Use enums in IdeComponent state machines
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user