Make whole frontend dynamically configurable to avoid rebuilds

This commit is contained in:
Kristóf Tóth
2019-08-28 10:19:14 +02:00
parent 41eebc60f6
commit a88415bad1
17 changed files with 187 additions and 207 deletions
+13 -14
View File
@@ -4,7 +4,7 @@ import { WebSocketMessage } from '../message-types/websocket-message';
import { IDEMessage } from '../message-types/ide-message';
import { DeployMessage } from '../message-types/deploy-message';
import { DeploymentNotificationService } from '../services/deployment-notification.service';
import { config } from '../config';
import { IdeConfigService } from '../services/config.service';
import { LanguageMap } from './language-map';
import { first } from 'rxjs/operators';
@@ -31,19 +31,19 @@ export class IdeComponent implements OnInit {
files: string[];
filename = '';
code: string = config.ide.defaultCode;
code = 'Loading your file...';
codeState = CodeState.SAVED;
deployButtonState = DeployButtonState.DEPLOYED;
deployButtonText = config.ide.deployButtonText;
showDeployButton: boolean = config.ide.showDeployButton;
deployButtonText = this.configService.deployButtonText;
showDeployButton = this.configService.showDeployButton;
autosave = null;
editorOptions = {
theme: 'vs-dark',
language: config.ide.defaultLanguage,
language: 'text',
glyphMargin: false,
minimap: {enabled: config.ide.showMiniMap}
minimap: {enabled: false}
};
command_handlers = {
@@ -54,10 +54,12 @@ export class IdeComponent implements OnInit {
constructor(private webSocketService: WebSocketService,
private changeDetectorRef: ChangeDetectorRef,
private deploymentNotificationService: DeploymentNotificationService) { }
private deploymentNotificationService: DeploymentNotificationService,
private configService: IdeConfigService) {}
ngOnInit() {
this.webSocketService.connect();
this.configService.init();
this.subscribeWS();
this.subscribeFirstLanguageDetection();
this.requestCode();
@@ -77,7 +79,7 @@ export class IdeComponent implements OnInit {
subscribeFirstLanguageDetection() {
this.webSocketService.observeKey<IDEMessage>('ide.read').pipe(first()).subscribe(
() => this.autoDetectEditorLanguageIfEnabled(this.filename)
() => this.autoDetectEditorLanguage(this.filename)
);
}
@@ -108,10 +110,7 @@ export class IdeComponent implements OnInit {
this.deploymentNotificationService.deploying.next(false);
}
autoDetectEditorLanguageIfEnabled(filename: string) {
if (!config.ide.autoDetectFileLanguage) {
return;
}
autoDetectEditorLanguage(filename: string) {
const extension = filename.substr(filename.lastIndexOf('.') + 1);
let language = LanguageMap[extension];
language = (language === undefined) ? 'text' : language;
@@ -132,7 +131,7 @@ export class IdeComponent implements OnInit {
}
this.autosave = setInterval(
() => { this.sendCodeIfDirty(); },
config.ide.autoSaveInterval
this.configService.autoSaveInterval.value
);
}
@@ -142,7 +141,7 @@ export class IdeComponent implements OnInit {
}
this.filename = file;
this.requestCode();
this.autoDetectEditorLanguageIfEnabled(this.filename);
this.autoDetectEditorLanguage(this.filename);
}
editorWriteHandler() {