frontend-tutorial-framework/src/app/services/config.service.ts

84 lines
2.4 KiB
TypeScript

import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { Subject, BehaviorSubject, forkJoin } from 'rxjs';
import { ConfigServiceBase } from './config.service.base';
@Injectable()
export class DashboardConfigService extends ConfigServiceBase {
keys = ['frontend.dashboard'];
layout = new BehaviorSubject<string>('terminal-ide-web');
hideMessages = new BehaviorSubject<boolean>(false);
iframeUrl = new BehaviorSubject<string>('/webservice');
showUrlBar = new BehaviorSubject<boolean>(false);
terminalMenuItem = new BehaviorSubject<string>('terminal');
reloadIframeOnDeploy = new BehaviorSubject<boolean>(false);
enabledLayouts = new BehaviorSubject<Array<string>>([
'terminal-ide-web',
'terminal-ide-vertical',
'terminal-web',
'ide-web-vertical',
'terminal-ide-horizontal',
'terminal-only',
'ide-only',
'web-only'
]);
}
@Injectable()
export class IdeConfigService extends ConfigServiceBase {
keys = ['frontend.ide'];
autoSaveInterval = new BehaviorSubject<number>(444);
showDeployButton = new BehaviorSubject<boolean>(true);
deployButtonText = new BehaviorSubject<any>({
'TODEPLOY': 'Deploy',
'DEPLOYED': 'Deployed',
'DEPLOYING': 'Reloading app...',
'FAILED': 'Deployment failed'
});
}
@Injectable()
export class SiteConfigService extends ConfigServiceBase {
keys = ['frontend.site'];
askReloadSite = new BehaviorSubject<boolean>(false);
documentTitle = new BehaviorSubject<string>('Avatao Tutorials');
}
@Injectable()
export class ConfigReadyService {
configDone = new Subject<void>();
readyNotifiers: Array<any>;
constructor(
private webSocketService: WebSocketService,
private ide: IdeConfigService,
private dashboard: DashboardConfigService,
private site: SiteConfigService
) {
this.readyNotifiers = [
this.ide.configDone,
this.dashboard.configDone,
this.site.configDone
];
}
init() {
this.webSocketService.connect();
const recvdConfigDone = new Subject<void>();
this.readyNotifiers.push(recvdConfigDone);
this.webSocketService.observeKey<any>('frontend.config.done').subscribe(() => {
recvdConfigDone.next();
recvdConfigDone.complete();
});
forkJoin(this.readyNotifiers).subscribe(undefined, undefined, () => {
this.configDone.next();
this.configDone.complete();
});
}
}