mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2024-12-05 02:01:32 +00:00
Implement poc ConfigService
This commit is contained in:
parent
45767b6711
commit
448a2bc862
@ -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
|
||||
|
38
src/app/services/config.service.ts
Normal file
38
src/app/services/config.service.ts
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user