Merge pull request #19 from avatao-content/config_refactor

Config refactor
This commit is contained in:
Bokros Bálint 2018-03-21 16:52:09 +01:00 committed by GitHub
commit 2d82b83b06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 50 additions and 29 deletions

View File

@ -6,14 +6,15 @@ import { WebideComponent } from './webide/webide.component';
import { TerminalComponent } from './terminal/terminal.component';
import { MessagesComponent } from './messages/messages.component';
import { TestmessengerComponent } from './testmessenger/testmessenger.component';
import { config } from './config';
const routes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full'},
{ path: 'dashboard', component: DashboardComponent},
{ path: 'webide', component: WebideComponent },
{ path: 'shell', component: TerminalComponent },
{ path: 'messages', component: MessagesComponent },
{ path: 'testmessenger', component: TestmessengerComponent }
{ path: config.dashboard.route, component: DashboardComponent},
{ path: config.webide.route, component: WebideComponent },
{ path: config.terminal.route, component: TerminalComponent },
{ path: config.messages.route, component: MessagesComponent },
{ path: config.testmessenger.route, component: TestmessengerComponent }
];
@NgModule({

24
src/app/config.ts Normal file
View File

@ -0,0 +1,24 @@
export const config = {
dashboard: {
'route': 'dashboard',
'defaultLayout': 'vraw-open'
},
webide: {
'route': 'webide',
'autoSaveInterval': 1000,
'defaultCode': 'Loading your file...',
'defaultLanguage': 'text',
'deployProcessName': 'login',
'showDeployButton': true
},
terminal: {
'route': 'shell'
},
messages: {
'route': 'messages',
'showNextButton': false
},
testmessenger: {
'route': 'testmessenger'
}
};

View File

@ -3,6 +3,7 @@ import { DeploymentNotificationService } from '../services/deployment-notificati
import { Subscription } from 'rxjs/Subscription';
import { WebSocketService } from '../services/websocket.service';
import { LayoutCommand } from './layout-command';
import { config } from '../config';
@Component({
selector: 'app-dashboard',
@ -12,7 +13,7 @@ import { LayoutCommand } from './layout-command';
export class DashboardComponent implements OnInit, OnDestroy {
deploying = false;
deploymentNotificationSubscription: Subscription;
layout = 'vraw-open';
layout: string = config.dashboard.defaultLayout;
command_handlers = {'layout': this.layoutHandler.bind(this)};
constructor(private deploymentNotificationService: DeploymentNotificationService,
@ -33,8 +34,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
layoutHandler(data: LayoutCommand) {
if (data.layout.match('vraw-open|vraw-closed|hraw|default-open|default-closed')) {
this.layout = data.layout;
}
else {
} else {
console.log('Invalid webide layout "' + data.layout + '" received!');
}
}

View File

@ -1,4 +1,4 @@
export class LayoutCommand {
command: string;
layout: string;
}
}

View File

@ -1,15 +1,10 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
constructor() { }
ngOnInit() {
}
export class HeaderComponent {
constructor() {}
}

View File

@ -4,6 +4,7 @@ import { WebSocketService } from '../services/websocket.service';
import { Message } from './message';
import { MessageControl } from './messagecontrol';
import { config } from '../config';
@Component({
selector: 'app-messages',
@ -12,7 +13,7 @@ import { MessageControl } from './messagecontrol';
})
export class MessagesComponent implements OnInit {
messages: Message[] = [];
showNextButton = false;
showNextButton: boolean = config.messages.showNextButton;
command_handlers = {'showbutton': this.showButton.bind(this)};
constructor(

View File

@ -1,5 +1,5 @@
export class WSMessage<T> {
key: string;
trigger?: string;
data: T; // TODO: sane annotation
data: T;
}

View File

@ -14,7 +14,8 @@
</div>
<div class="btn-group-sm tfw-deploy-btn-group">
<button type="submit"
<button *ngIf="showDeployButton"
type="submit"
class="btn tfw-deploy-btn tao-grid-top-center"
(click)="sendCodeIfDirty(); deployCode()"
[disabled]="deployButtonState === 'DEPLOYING' || deployButtonState === 'DEPLOYED'"

View File

@ -16,12 +16,10 @@ import { SourceCode } from './source-code';
import { WebSocketService } from '../services/websocket.service';
import { ProcessManagerService } from '../services/processmanager.service';
import { DeploymentNotificationService } from '../services/deployment-notification.service';
import { config } from '../config';
const modelist = brace.acequire('ace/ext/modelist');
const defaultSourceCode = 'Loading your file...';
const autosave_interval = 1000;
@Component({
selector: 'app-webide',
templateUrl: './webide.component.html',
@ -29,14 +27,15 @@ const autosave_interval = 1000;
})
export class WebideComponent implements OnInit {
key_id = 'webide';
filename = 'demo.js';
code: string = defaultSourceCode;
language = 'javascript';
filename = '';
code: string = config.webide.defaultCode;
language: string = config.webide.defaultLanguage;
theme = 'cobalt';
directory = '';
files: string[];
codeState = 'SAVED';
deployButtonState = 'DEPLOYED';
showDeployButton: boolean = config.webide.showDeployButton;
autosave = null;
command_handlers = {'reload': this.reloadHandler.bind(this),
'read': this.readHandler.bind(this),
@ -54,8 +53,8 @@ export class WebideComponent implements OnInit {
this.subscribeWS();
this.requestCode();
this.processManagerService.init();
this.processManagerService.subscribeCallback('login', (event) => { this.setDeployButtonState('DEPLOYED'); });
this.processManagerService.subscribeErrorCallback('login', (event) => { this.setDeployButtonState('FAILED'); });
this.processManagerService.subscribeCallback(config.webide.deployProcessName, (event) => { this.setDeployButtonState('DEPLOYED'); });
this.processManagerService.subscribeErrorCallback(config.webide.deployProcessName, (event) => { this.setDeployButtonState('FAILED'); });
this.resetAutoSaveCountdown();
}
@ -99,7 +98,7 @@ export class WebideComponent implements OnInit {
if (this.autosave) {
clearInterval(this.autosave);
}
this.autosave = setInterval(() => { this.sendCodeIfDirty(); }, autosave_interval);
this.autosave = setInterval(() => { this.sendCodeIfDirty(); }, config.webide.autoSaveInterval);
}
tabSwitchButtonHandler(file) {