mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 12:42:55 +00:00 
			
		
		
		
	Refactor project to use config file
This commit is contained in:
		@@ -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({
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								src/app/config.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/app/config.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
export const config = {
 | 
			
		||||
  dashboard: {
 | 
			
		||||
    'route': 'dashboard',
 | 
			
		||||
    'defaultLayout': 'vraw-open'
 | 
			
		||||
  },
 | 
			
		||||
  webide: {
 | 
			
		||||
    'route': 'webide',
 | 
			
		||||
    'autoSaveInterval': 1000,
 | 
			
		||||
    'defaultCode': 'Loading your file...',
 | 
			
		||||
    'defaultLanguage': 'text',
 | 
			
		||||
    'deployProcessName': 'login'
 | 
			
		||||
  },
 | 
			
		||||
  terminal: {
 | 
			
		||||
    'route': 'shell'
 | 
			
		||||
  },
 | 
			
		||||
  messages: {
 | 
			
		||||
    'route': 'messages',
 | 
			
		||||
    'showNextButton': false
 | 
			
		||||
  },
 | 
			
		||||
  testmessenger: {
 | 
			
		||||
    'route': 'testmessenger'
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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(
 | 
			
		||||
 
 | 
			
		||||
@@ -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,9 +27,9 @@ 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[];
 | 
			
		||||
@@ -54,8 +52,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 +97,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) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user