Skip to content

Commit

Permalink
feat(octra): additional params audio_url, audio_name and readonly for…
Browse files Browse the repository at this point in the history
… URL mode
  • Loading branch information
julianpoemp committed Nov 6, 2023
1 parent 8c0f02e commit 6cf1264
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 33 deletions.
2 changes: 1 addition & 1 deletion apps/octra/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ export class AppComponent

queryParamsSet(): boolean {
const params = this.route.snapshot.queryParams;
return params['audio'] && params['embedded'];
return params['audio_url'] && params['embedded'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
</button>
<button
(click)="onSaveTranscriptionButtonClicked()"
*ngIf="useMode === 'url'"
*ngIf="useMode === 'url' && !routingService.staticQueryParams.readonly"
class="btn btn-primary"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ChangeDetectorRef,
Component,
ComponentFactoryResolver,
ComponentRef,
OnDestroy,
OnInit,
Expand Down Expand Up @@ -332,7 +331,6 @@ export class TranscriptionComponent

constructor(
public router: Router,
private _componentFactoryResolver: ComponentFactoryResolver,
public audio: AudioService,
public uiService: UserInteractionsService,
public appStorage: AppStorageService,
Expand All @@ -342,7 +340,7 @@ export class TranscriptionComponent
public modService: OctraModalService,
private appStoreService: ApplicationStoreService,
public langService: TranslocoService,
private routingService: RoutingService,
public routingService: RoutingService,
private cd: ChangeDetectorRef,
private alertService: AlertService,
public annotationStoreService: AnnotationStoreService,
Expand Down
5 changes: 1 addition & 4 deletions apps/octra/src/app/core/shared/service/routing.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@angular/core';
import { NavigationExtras, QueryParamsHandling, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { removeEmptyProperties, SubscriptionManager } from '@octra/utilities';
import { removeEmptyProperties } from '@octra/utilities';
import { SessionStorageService } from 'ngx-webstorage';
import { environment } from '../../../../environments/environment';

Expand All @@ -15,8 +14,6 @@ export class RoutingService {

private _staticQueryParams: any = {};

private readonly subscrManager = new SubscriptionManager<Subscription>();

// Observable exposing the breadcrumb hierarchy
constructor(
private router: Router,
Expand Down
14 changes: 4 additions & 10 deletions apps/octra/src/app/core/store/application/application.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { SettingsService } from '../../shared/service';
import { getModeState, LoginMode, RootState } from '../index';
import { AuthenticationActions } from '../authentication';
import { RoutingService } from '../../shared/service/routing.service';
import { Params } from '@angular/router';
import { AnnotationActions } from '../login-mode/annotation/annotation.actions';
import { OctraModalService } from '../../modals/octra-modal.service';
import { ErrorModalComponent } from '../../modals/error-modal/error-modal.component';
Expand All @@ -52,9 +51,11 @@ export class ApplicationEffects {
ofType(ApplicationActions.initApplication.do),
exhaustMap(() => {
const queryParams = {
audio: this.getParameterByName('audio'),
audio_url: this.getParameterByName('audio_url'),
audio_name: this.getParameterByName('audio_name'),
host: this.getParameterByName('host'),
transcript: this.getParameterByName('transcript'),
readonly: this.getParameterByName('readonly'),
embedded: this.getParameterByName('embedded'),
};

Expand Down Expand Up @@ -667,7 +668,7 @@ export class ApplicationEffects {
}
}

if (this.routerService.staticQueryParams?.audio) {
if (this.routerService.staticQueryParams?.audio_url) {
this.store.dispatch(
AuthenticationActions.loginURL.do({
mode: LoginMode.URL,
Expand Down Expand Up @@ -963,11 +964,4 @@ export class ApplicationEffects {
}
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

private queryParamsSet(queryParams: Params): boolean {
return (
queryParams['audio'] !== undefined &&
queryParams['embedded'] !== undefined
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ export class AnnotationEffects {
) {
// online, url or demo
if (a.audioFile) {
const src = this.apiService.prepareFileURL(a.audioFile!.url!);
const src =
state.application.mode === LoginMode.ONLINE
? this.apiService.prepareFileURL(a.audioFile!.url!)
: a.audioFile!.url!;
// extract filename

filename = filename.substring(0, filename.lastIndexOf('.'));
Expand Down Expand Up @@ -724,17 +727,20 @@ export class AnnotationEffects {
// URL mode
if (
Object.keys(this.routingService.staticQueryParams).includes(
'audio'
'audio_url'
)
) {

const fileInfoAudio = FileInfo.fromURL(
this.routingService.staticQueryParams['audio_url']
);

inputs = [
{
filename: FileInfo.fromURL(
this.routingService.staticQueryParams['audio']
).fullname,
filename: this.routingService.staticQueryParams['audio_name'] ?? fileInfoAudio.fullname,
fileType: 'audio/wave',
type: 'input',
url: this.routingService.staticQueryParams['audio'],
url: this.routingService.staticQueryParams['audio_url'],
creator_type: TaskInputOutputCreatorType.user,
content: '',
content_type: '',
Expand Down Expand Up @@ -778,14 +784,23 @@ export class AnnotationEffects {
})
.pipe(
exhaustMap((content) => {
let filename =
this.routingService.staticQueryParams.transcript;
filename = filename.substring(
filename.lastIndexOf('/') + 1
const fileInfoTranscript = FileInfo.fromURL(
this.routingService.staticQueryParams['transcript']
);
const fileInfoAudio = FileInfo.fromURL(
this.routingService.staticQueryParams['audio_url']
);
let audioName =
this.routingService.staticQueryParams.audio_name ??
fileInfoAudio.fullname;

audioName = audioName.substring(
0,
audioName.lastIndexOf('.')
);

task.inputs.push({
filename,
filename: audioName + fileInfoTranscript.extension,
fileType: 'text/plain',
type: 'input',
creator_type: TaskInputOutputCreatorType.user,
Expand Down
2 changes: 1 addition & 1 deletion libs/web-media/src/lib/audio/audio-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class AudioManager {
);
}
} else {
subj.error(`audio format not supported`);
subj.error(`audio format not supported: ${filename.substring(filename.lastIndexOf('.'))} from ${filename}`);
}

return subj;
Expand Down
12 changes: 10 additions & 2 deletions libs/web-media/src/lib/data-info/file-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@ export class FileInfo extends DataInfo {
createdAt = 0
) {
let fullname = '';
const extension = url.substr(url.lastIndexOf('.') + 1);
let extension = url.substring(url.lastIndexOf('.') + 1);

if (extension.indexOf('?') > 0) {
extension = extension.substring(0, extension.indexOf('?'));
}

if (name != undefined) {
fullname = name + '.' + extension;
} else {
fullname = url.substr(url.lastIndexOf('/') + 1);
fullname = url.substring(url.lastIndexOf('/') + 1);

if (fullname.indexOf('?') > 0) {
fullname = fullname.substring(0, fullname.indexOf('?'));
}
}
const result = new FileInfo(
fullname,
Expand Down

0 comments on commit 6cf1264

Please sign in to comment.