Skip to content

Commit

Permalink
feat(octra): URL mode from v1.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp committed Oct 23, 2023
1 parent 96263ea commit 8881769
Show file tree
Hide file tree
Showing 21 changed files with 477 additions and 529 deletions.
4 changes: 4 additions & 0 deletions apps/octra/src/app/core/pages/intern/intern.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export const EDITORS: any[] = [
'localMode',
new LoginModeReducers(LoginMode.LOCAL).create()
),
StoreModule.forFeature(
'urlMode',
new LoginModeReducers(LoginMode.URL).create()
),
EffectsModule.forFeature([AnnotationEffects]),
OctraUtilitiesModule,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { NavbarService } from '../../../component/navbar/navbar.service';
import { LoginMode } from '../../../store';
import { ShortcutsModalComponent } from '../../../modals/shortcuts-modal/shortcuts-modal.component';
import { PromptModalComponent } from '../../../modals/prompt-modal/prompt-modal.component';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { DefaultComponent } from '../../../component/default.component';
import { AnnotationStoreService } from '../../../store/login-mode/annotation/annotation.store.service';
import { AuthenticationStoreService } from '../../../store/authentication';
Expand All @@ -60,6 +60,7 @@ import X2JS from 'x2js';
import { ApplicationStoreService } from '../../../store/application/application-store.service';
import { ShortcutService } from '../../../shared/service/shortcut.service';
import { HotkeysEvent } from 'hotkeys-js';
import { RoutingService } from '../../../shared/service/routing.service';

@Component({
selector: 'octra-transcription',
Expand Down Expand Up @@ -341,7 +342,7 @@ export class TranscriptionComponent
public modService: OctraModalService,
private appStoreService: ApplicationStoreService,
public langService: TranslocoService,
private ngbModalService: NgbModal,
private routingService: RoutingService,
private cd: ChangeDetectorRef,
private alertService: AlertService,
public annotationStoreService: AnnotationStoreService,
Expand Down Expand Up @@ -862,19 +863,6 @@ export class TranscriptionComponent
closeTranscriptionAndGetNew() {
// close current session
if (this._useMode === LoginMode.ONLINE) {
/* TODO
this.api.freeAnnotation(this.appStorage.onlineSession.currentProject.id, this.appStorage.onlineSession.sessionData.transcriptID).then(() => {
this.api.startAnnotation(this.appStorage.onlineSession.currentProject.id).then((result) => {
this.transcrService.endTranscription(false);
navigateTo(this.router, ['/load'], AppInfo.queryParamsHandling).catch((error) => {
console.error(error);
});
}).catch((error) => {
console.error(error);
});
}).catch((error) => {
console.error(error);
}); */
} else if (this._useMode === LoginMode.DEMO) {
this.reloadDemo();
}
Expand Down Expand Up @@ -913,8 +901,8 @@ export class TranscriptionComponent
let host =
'https://clarin.phonetik.uni-muenchen.de/BASWebServices/services/';

if (!(this.appStorage.urlParams.host === undefined)) {
host = this.appStorage.urlParams.host;
if (this.routingService.staticQueryParams?.host) {
host = this.routingService.staticQueryParams.host;
}

const url = `${host}uploadFileMulti`;
Expand Down
43 changes: 33 additions & 10 deletions apps/octra/src/app/core/shared/octra-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { ASRStateSettings } from '../store/asr';
export class OctraDatabase extends Dexie {
public demoData: Dexie.Table<IIDBEntry, string>;
public onlineData: Dexie.Table<IIDBEntry, string>;
public urlData: Dexie.Table<IIDBEntry, string>;
public localData: Dexie.Table<IIDBEntry, string>;
public options: Dexie.Table<IIDBEntry, string>;
public app_options: Dexie.Table<IIDBEntry, string>;
public onReady: Subject<void>;

private defaultOptions: IIDBEntry[] = [
Expand Down Expand Up @@ -131,19 +132,22 @@ export class OctraDatabase extends Dexie {
.stores({
annotation_levels: null,
annotation_links: null,
logs: 'timestamp',
logs: null,
options: null,
demo_data: 'name',
online_data: 'name',
local_data: 'name',
options: 'name',
url_data: 'name',
app_options: 'name',
})
.upgrade(this.upgradeToDatabaseV4);

this.demoData = this.table('demo_data');
this.onlineData = this.table('online_data');
this.localData = this.table('local_data');
this.urlData = this.table('url_data');

this.options = this.table('options');
this.app_options = this.table('app_options');

this.on('ready', () => {
this.checkAndFillPopulation()
Expand All @@ -161,12 +165,12 @@ export class OctraDatabase extends Dexie {
}

private upgradeToDatabaseV2(transaction: Transaction) {
return transaction.table('options').bulkPut(this.defaultOptions);
return transaction.table('app_options').bulkPut(this.defaultOptions);
}

private upgradeToDatabaseV3(transaction: Transaction) {
return transaction
.table('options')
.table('app_options')
.toCollection()
.modify((option: IIDBEntry) => {
if (option.name === 'uselocalmode') {
Expand All @@ -181,7 +185,7 @@ export class OctraDatabase extends Dexie {
}

private async upgradeToDatabaseV4(transaction: Transaction) {
await transaction.table('options').get('usemode');
await transaction.table('app_options').get('usemode');
}

private getTableFromString(mode: LoginMode): Dexie.Table<IIDBEntry, string> {
Expand All @@ -197,6 +201,9 @@ export class OctraDatabase extends Dexie {
case LoginMode.ONLINE:
table = this.onlineData;
break;
case LoginMode.URL:
table = this.urlData;
break;
}

return table;
Expand All @@ -205,7 +212,7 @@ export class OctraDatabase extends Dexie {
private checkAndFillPopulation(): Observable<void> {
const subj = new Subject<void>();

this.countEntries(this.options)
this.countEntries(this.app_options)
.pipe(take(1))
.subscribe({
next: (count) => {
Expand All @@ -215,6 +222,7 @@ export class OctraDatabase extends Dexie {
this.populateModeOptions(LoginMode.DEMO),
this.populateModeOptions(LoginMode.ONLINE),
this.populateModeOptions(LoginMode.LOCAL),
this.populateModeOptions(LoginMode.URL),
]).subscribe(() => {
subj.next();
subj.complete();
Expand Down Expand Up @@ -347,7 +355,7 @@ export class OctraDatabase extends Dexie {

private populateOptions() {
return from(
this.options.bulkPut([
this.app_options.bulkPut([
{
name: 'version',
value: 3,
Expand Down Expand Up @@ -454,7 +462,22 @@ export interface IIDBApplicationOptions {
showFeedbackNotice?: boolean | null;
}

export type IDBApplicationOptionName = "asr" | "audioSettings" | "console" | "easyMode" | "highlightingEnabled" | "interface" | "language" | "secondsPerLine" | "showLoupe" | "useMode" | "version" | "editorFont" | "playOnHover" | "followPlayCursor" | "showFeedbackNotice";
export type IDBApplicationOptionName =
| 'asr'
| 'audioSettings'
| 'console'
| 'easyMode'
| 'highlightingEnabled'
| 'interface'
| 'language'
| 'secondsPerLine'
| 'showLoupe'
| 'useMode'
| 'version'
| 'editorFont'
| 'playOnHover'
| 'followPlayCursor'
| 'showFeedbackNotice';

export const DefaultModeOptions: IIDBModeOptions = {
logging: true,
Expand Down
32 changes: 1 addition & 31 deletions apps/octra/src/app/core/shared/service/appstorage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ export class AppStorageService {
);
}

get urlParams(): any {
return this._snapshot.application.queryParams;
}

get easyMode(): boolean | undefined | null {
return this._snapshot.application.options.easyMode;
}
Expand Down Expand Up @@ -325,32 +321,6 @@ export class AppStorageService {
);
}

setURLSession(
audio: string,
transcript: string,
embedded: boolean,
host: string
) {
if (this.easyMode === undefined) {
this.easyMode = false;
}

if (this.interface === undefined) {
this.interface = '2D-Editor';
}

this.store.dispatch(
LoginModeActions.loginURLParameters({
urlParams: {
audio,
transcript,
embedded,
host,
},
})
);
}

public save(key: string, value: any): boolean {
// TODO why not url?
if (this.useMode !== LoginMode.URL) {
Expand Down Expand Up @@ -492,7 +462,7 @@ export class AppStorageService {

public startOnlineAnnotation(project: ProjectDto) {
this.store.dispatch(
AnnotationActions.startOnlineAnnotation.do({
AnnotationActions.startNewAnnotation.do({
project,
mode: LoginMode.ONLINE,
})
Expand Down
16 changes: 8 additions & 8 deletions apps/octra/src/app/core/shared/service/idb.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ export class IDBService {
* clears all options
*/
public clearModeOptions(mode: LoginMode) {
return this.database.clearDataOfMode(mode, 'options');
return this.database.clearDataOfMode(mode, 'app_options');
}

/**
* clears all options
*/
public clearOptions(mode: LoginMode): Promise<any> {
return this.database.options.clear();
return this.database.app_options.clear();
}

/**
* loads console entries.
*/
public loadConsoleEntries(): Promise<ConsoleEntry[]> {
return new Promise<ConsoleEntry[]>((resolve, reject) => {
this.database.options
this.database.app_options
.get('console')
.then((entry) => {
if (entry !== undefined) {
Expand All @@ -84,7 +84,7 @@ export class IDBService {
* @param entries
*/
public saveConsoleEntries(entries: ConsoleEntry[]) {
return this.database.options.put({
return this.database.app_options.put({
name: 'console',
value: entries,
});
Expand All @@ -96,7 +96,7 @@ export class IDBService {
public loadOptions(
keys: IDBApplicationOptionName[]
): Observable<IIDBApplicationOptions> {
return from(this.database.options.bulkGet(keys)).pipe(
return from(this.database.app_options.bulkGet(keys)).pipe(
map((values) => {
const entries = values.filter((a) => a !== undefined);
const result: any = {};
Expand Down Expand Up @@ -134,9 +134,9 @@ export class IDBService {
*/
public saveOption<T>(key: string, value: T) {
if (this.isReady) {
return from(this.database.options.put({ name: key, value }, key)).pipe(
map((result: string) => result)
);
return from(
this.database.app_options.put({ name: key, value }, key)
).pipe(map((result: string) => result));
} else {
return throwError(() => {
return new Error(`can't save option ${key}, because idb is not ready.`);
Expand Down
8 changes: 5 additions & 3 deletions apps/octra/src/app/core/shared/service/routing.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { NavigationExtras, QueryParamsHandling, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { SubscriptionManager } from '@octra/utilities';
import { removeEmptyProperties, SubscriptionManager } from '@octra/utilities';
import { SessionStorageService } from 'ngx-webstorage';
import { environment } from '../../../../environments/environment';

Expand Down Expand Up @@ -29,9 +29,11 @@ export class RoutingService {
}
}

public addStaticParams(params: Record<string, string>) {
public addStaticParams(params: Record<string, string | undefined | null>) {
this._staticQueryParams = {
...this._staticQueryParams,
...removeEmptyProperties<Record<string, string | undefined | null>>(
params
),
...params,
};
}
Expand Down
17 changes: 1 addition & 16 deletions apps/octra/src/app/core/store/application/application.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
props,
} from '@ngrx/store';
import { ConsoleEntry } from '../../shared/service/bug-report.service';
import { LoginMode } from '../index';
import { AppSettings, ASRSettings } from '../../obj';
import { HttpErrorResponse } from '@angular/common/http';
import { IDBApplicationOptionName } from '../../shared/octra-database';
Expand Down Expand Up @@ -80,7 +79,7 @@ export class ApplicationActions {
},
});

static setRedirectionTo = createActionGroup({
static redirectTo = createActionGroup({
source: 'app/set redirection',
events: {
success: props<{
Expand Down Expand Up @@ -133,20 +132,6 @@ export class ApplicationActions {

public static finishLoading = createAction(`[${context}] Finish Loading`);

public static setLoggedIn = createAction(
`[${context}] Set loggedIn`,
props<{
loggedIn: boolean;
}>()
);

public static setMode = createAction(
`[${context}] Set Mode`,
props<{
mode: LoginMode;
}>()
);

public static addError = createAction(
`[${context}] Add Error`,
props<{
Expand Down
Loading

0 comments on commit 8881769

Please sign in to comment.