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 { TerminalComponent } from './terminal/terminal.component';
import { MessagesComponent } from './messages/messages.component'; import { MessagesComponent } from './messages/messages.component';
import { TestmessengerComponent } from './testmessenger/testmessenger.component'; import { TestmessengerComponent } from './testmessenger/testmessenger.component';
import { config } from './config';
const routes: Routes = [ const routes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full'}, { path: '', redirectTo: '/dashboard', pathMatch: 'full'},
{ path: 'dashboard', component: DashboardComponent}, { path: config.dashboard.route, component: DashboardComponent},
{ path: 'webide', component: WebideComponent }, { path: config.webide.route, component: WebideComponent },
{ path: 'shell', component: TerminalComponent }, { path: config.terminal.route, component: TerminalComponent },
{ path: 'messages', component: MessagesComponent }, { path: config.messages.route, component: MessagesComponent },
{ path: 'testmessenger', component: TestmessengerComponent } { path: config.testmessenger.route, component: TestmessengerComponent }
]; ];
@NgModule({ @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 { Subscription } from 'rxjs/Subscription';
import { WebSocketService } from '../services/websocket.service'; import { WebSocketService } from '../services/websocket.service';
import { LayoutCommand } from './layout-command'; import { LayoutCommand } from './layout-command';
import { config } from '../config';
@Component({ @Component({
selector: 'app-dashboard', selector: 'app-dashboard',
@ -12,7 +13,7 @@ import { LayoutCommand } from './layout-command';
export class DashboardComponent implements OnInit, OnDestroy { export class DashboardComponent implements OnInit, OnDestroy {
deploying = false; deploying = false;
deploymentNotificationSubscription: Subscription; deploymentNotificationSubscription: Subscription;
layout = 'vraw-open'; layout: string = config.dashboard.defaultLayout;
command_handlers = {'layout': this.layoutHandler.bind(this)}; command_handlers = {'layout': this.layoutHandler.bind(this)};
constructor(private deploymentNotificationService: DeploymentNotificationService, constructor(private deploymentNotificationService: DeploymentNotificationService,
@ -33,8 +34,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
layoutHandler(data: LayoutCommand) { layoutHandler(data: LayoutCommand) {
if (data.layout.match('vraw-open|vraw-closed|hraw|default-open|default-closed')) { if (data.layout.match('vraw-open|vraw-closed|hraw|default-open|default-closed')) {
this.layout = data.layout; this.layout = data.layout;
} } else {
else {
console.log('Invalid webide layout "' + data.layout + '" received!'); console.log('Invalid webide layout "' + data.layout + '" received!');
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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