Implement poc ConfigService

This commit is contained in:
Kristóf Tóth 2019-08-16 00:05:29 +02:00
parent 45767b6711
commit 448a2bc862
2 changed files with 40 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import { DeploymentNotificationService } from './services/deployment-notificatio
import { SafePipe } from './pipes/safe.pipe';
import { ConsoleComponent } from './console/console.component';
import { MonacoEditorModule } from 'ngx-monaco-editor';
import { IdeConfigService } from './services/config.service';
@NgModule({
@ -50,6 +51,7 @@ import { MonacoEditorModule } from 'ngx-monaco-editor';
WebSocketService,
TerminadoService,
DeploymentNotificationService,
IdeConfigService
],
bootstrap: [
AppComponent

View File

@ -0,0 +1,38 @@
import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { BehaviorSubject } from 'rxjs';
@Injectable()
abstract class ConfigService {
keys: Array<string> = new Array<string>();
protected mau = 'cica';
constructor(private webSocketService: WebSocketService) {}
init() {
this.webSocketService.connect();
this.keys.forEach(key => {
key = 'frontend.config.' + key;
this.webSocketService.observeKey<any>(key).subscribe(this.handleConfig.bind(this));
});
}
handleConfig(message: any) {
Object.keys(message).filter(key => key !== 'key').forEach(key => {
if (this[key] === undefined) {
console.log(`Invalid ${this.keys} config key "${key}"!`);
} else {
this[key].next(message[key]);
}
});
}
}
@Injectable()
export class IdeConfigService extends ConfigService {
keys = ['ide'];
showDeployButton = new BehaviorSubject<boolean>(true);
}