mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2024-12-05 02:01:32 +00:00
Use enums in IdeComponent state machines
This commit is contained in:
parent
8bf82365f4
commit
b2862b755b
@ -9,10 +9,10 @@
|
||||
[class.active]="filename === file"
|
||||
[class.disabled]="filename === file"
|
||||
[disabled]="filename === file"
|
||||
[class.tao-tab-btn-saved]="filename === file && codeState === 'SAVED'">
|
||||
[class.tao-tab-btn-saved]="filename === file && codeState === CodeState.SAVED">
|
||||
<span *ngIf="filename !== file">{{file}}</span>
|
||||
<span *ngIf="filename === file"
|
||||
[class.underline]="codeState === 'DIRTY'">{{file}}</span>
|
||||
[class.underline]="codeState === CodeState.DIRTY">{{file}}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@ -21,28 +21,27 @@
|
||||
type="submit"
|
||||
class="btn tfw-deploy-btn tao-grid-top-center"
|
||||
(click)="sendCodeIfDirty(); deployCode()"
|
||||
[disabled]="deployButtonState === 'DEPLOYING' || deployButtonState === 'DEPLOYED'"
|
||||
[class.deployed]="deployButtonState === 'DEPLOYED'"
|
||||
[class.deploy]="deployButtonState === 'DEPLOYING'"
|
||||
[class.disabled]="deployButtonState === 'DEPLOYING' || deployButtonState === 'DEPLOYED'"
|
||||
[class.failed]="deployButtonState === 'FAILED'"
|
||||
>
|
||||
<span *ngIf="deployButtonState === 'TODEPLOY'">Deploy</span>
|
||||
<span *ngIf="deployButtonState === 'DEPLOYED'">
|
||||
[disabled]="deployButtonState === DeployButtonState.DEPLOYING || deployButtonState === DeployButtonState.DEPLOYED"
|
||||
[class.deployed]="deployButtonState === DeployButtonState.DEPLOYED"
|
||||
[class.deploy]="deployButtonState === DeployButtonState.DEPLOYING"
|
||||
[class.disabled]="deployButtonState === DeployButtonState.DEPLOYING || deployButtonState === DeployButtonState.DEPLOYED"
|
||||
[class.failed]="deployButtonState === DeployButtonState.FAILED">
|
||||
<span *ngIf="deployButtonState === DeployButtonState.TODEPLOY">Deploy</span>
|
||||
<span *ngIf="deployButtonState === DeployButtonState.DEPLOYED">
|
||||
<img src="images/greentick_icon.svg"/>
|
||||
<span>Deployed</span>
|
||||
</span>
|
||||
<span *ngIf="deployButtonState === 'DEPLOYING'"><div class="loader"></div>Reloading app...</span>
|
||||
<span *ngIf="deployButtonState === 'FAILED'">Deployment failed. Retry</span></button>
|
||||
<span *ngIf="deployButtonState === DeployButtonState.DEPLOYING"><div class="loader"></div>Reloading app...</span>
|
||||
<span *ngIf="deployButtonState === DeployButtonState.FAILED">Deployment failed. Retry</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div (keyup)="setCodeState('DIRTY'); setDeployButtonState('TODEPLOY'); resetAutoSaveCountdown()"
|
||||
<div (keyup)="setCodeState(CodeState.DIRTY); setDeployButtonState(DeployButtonState.TODEPLOY); resetAutoSaveCountdown()"
|
||||
ace-editor
|
||||
[(text)]="code"
|
||||
[mode]="language"
|
||||
[theme]="theme"
|
||||
[options]="options"
|
||||
class="tfw-ace-editor"
|
||||
>
|
||||
class="tfw-ace-editor">
|
||||
</div>
|
||||
|
@ -26,26 +26,46 @@ const modelist = brace.acequire('ace/ext/modelist');
|
||||
const langTools = brace.acequire('ace/ext/language_tools');
|
||||
|
||||
|
||||
enum DeployButtonState {
|
||||
DEPLOYED,
|
||||
DEPLOYING,
|
||||
FAILED,
|
||||
TODEPLOY
|
||||
}
|
||||
|
||||
|
||||
enum CodeState {
|
||||
SAVED,
|
||||
DIRTY
|
||||
}
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-ide',
|
||||
templateUrl: './ide.component.html',
|
||||
styleUrls: ['./ide.component.scss']
|
||||
})
|
||||
export class IdeComponent implements OnInit {
|
||||
CodeState = CodeState;
|
||||
DeployButtonState = DeployButtonState;
|
||||
|
||||
key_id = 'ide';
|
||||
files: string[];
|
||||
filename = '';
|
||||
directory = '';
|
||||
code: string = config.ide.defaultCode;
|
||||
|
||||
codeState = CodeState.SAVED;
|
||||
deployButtonState = DeployButtonState.DEPLOYED;
|
||||
showDeployButton: boolean = config.ide.showDeployButton;
|
||||
autosave = null;
|
||||
|
||||
language: string = config.ide.defaultLanguage;
|
||||
theme = 'cobalt';
|
||||
options: any = {enableBasicAutocompletion: true,
|
||||
enableSnippets: true,
|
||||
enableLiveAutocompletion: true};
|
||||
directory = '';
|
||||
files: string[];
|
||||
codeState = 'SAVED';
|
||||
deployButtonState = 'DEPLOYED';
|
||||
showDeployButton: boolean = config.ide.showDeployButton;
|
||||
autosave = null;
|
||||
|
||||
command_handlers = {'reload': this.reloadHandler.bind(this),
|
||||
'read': this.readHandler.bind(this),
|
||||
'select': this.selectHandler.bind(this),
|
||||
@ -74,9 +94,20 @@ export class IdeComponent implements OnInit {
|
||||
|
||||
initProcessManagerService() {
|
||||
this.processManagerService.init();
|
||||
this.processManagerService.subscribeCallback(config.ide.deployProcessName, (event) => this.deploymentNotificationService.deploying.next(false));
|
||||
this.processManagerService.subscribeSuccessCallback(config.ide.deployProcessName, (event) => this.setDeployButtonState('DEPLOYED'));
|
||||
this.processManagerService.subscribeErrorCallback(config.ide.deployProcessName, (event) => this.setDeployButtonState('FAILED'));
|
||||
this.processManagerService.subscribeCallback(
|
||||
config.ide.deployProcessName,
|
||||
(event) => this.deploymentNotificationService.deploying.next(false)
|
||||
);
|
||||
|
||||
this.processManagerService.subscribeSuccessCallback(
|
||||
config.ide.deployProcessName,
|
||||
(event) => this.setDeployButtonState(DeployButtonState.DEPLOYED)
|
||||
);
|
||||
|
||||
this.processManagerService.subscribeErrorCallback(
|
||||
config.ide.deployProcessName,
|
||||
(event) => this.setDeployButtonState(DeployButtonState.FAILED)
|
||||
);
|
||||
}
|
||||
|
||||
updateFileData(data: SourceCode) {
|
||||
@ -96,13 +127,13 @@ export class IdeComponent implements OnInit {
|
||||
}
|
||||
|
||||
readHandler(data: SourceCode) {
|
||||
if (this.codeState === 'SAVED') {
|
||||
if (this.codeState === CodeState.SAVED) {
|
||||
this.updateFileData(data);
|
||||
}
|
||||
}
|
||||
|
||||
writeHandler() {
|
||||
this.setCodeState('SAVED');
|
||||
this.setCodeState(CodeState.SAVED);
|
||||
}
|
||||
|
||||
selectdirHandler(data: SourceCode) {
|
||||
@ -113,37 +144,36 @@ export class IdeComponent implements OnInit {
|
||||
if (this.autosave) {
|
||||
clearInterval(this.autosave);
|
||||
}
|
||||
this.autosave = setInterval(() => { this.sendCodeIfDirty(); }, config.ide.autoSaveInterval);
|
||||
this.autosave = setInterval(
|
||||
() => { this.sendCodeIfDirty(); },
|
||||
config.ide.autoSaveInterval
|
||||
);
|
||||
}
|
||||
|
||||
tabSwitchButtonHandler(file) {
|
||||
if (this.codeState === 'DIRTY') {
|
||||
tabSwitchButtonHandler(file: string) {
|
||||
if (this.codeState === CodeState.DIRTY) {
|
||||
this.sendCodeContents();
|
||||
}
|
||||
this.selectCode(file);
|
||||
this.requestCode();
|
||||
}
|
||||
|
||||
setCodeState(state: string) {
|
||||
if (state.match('SAVED|DIRTY')) {
|
||||
this.codeState = state;
|
||||
}
|
||||
setCodeState(state: CodeState) {
|
||||
this.codeState = state;
|
||||
}
|
||||
|
||||
setDeployButtonState(state: string) {
|
||||
if (state.match('DEPLOYED|DEPLOYING|FAILED|TODEPLOY')) {
|
||||
this.deployButtonState = state;
|
||||
}
|
||||
setDeployButtonState(state: DeployButtonState) {
|
||||
this.deployButtonState = state;
|
||||
}
|
||||
|
||||
deployCode() {
|
||||
this.processManagerService.restartProcess(config.ide.deployProcessName);
|
||||
this.setDeployButtonState('DEPLOYING');
|
||||
this.setDeployButtonState(DeployButtonState.DEPLOYING);
|
||||
this.deploymentNotificationService.deploying.next(true);
|
||||
}
|
||||
|
||||
sendCodeIfDirty() {
|
||||
if (this.codeState === 'DIRTY') {
|
||||
if (this.codeState === CodeState.DIRTY) {
|
||||
this.sendCodeContents();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user