Introduce separate event handler for deploying

This commit is contained in:
R. Richard 2019-08-26 10:40:25 +02:00 committed by therealkrispet
parent 24c994c41e
commit 1b53ac40f2

View File

@ -2,7 +2,7 @@ import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { WebSocketService } from '../services/websocket.service';
import { WebSocketMessage } from '../message-types/websocket-message';
import { IDEMessage } from '../message-types/ide-message';
import { ProcessManagerService } from '../services/processmanager.service';
import { DeployMessage } from '../message-types/deploy-message';
import { DeploymentNotificationService } from '../services/deployment-notification.service';
import { config } from '../config';
import { LanguageMap } from './language-map';
@ -54,7 +54,6 @@ export class IdeComponent implements OnInit {
constructor(private webSocketService: WebSocketService,
private changeDetectorRef: ChangeDetectorRef,
private processManagerService: ProcessManagerService,
private deploymentNotificationService: DeploymentNotificationService) { }
ngOnInit() {
@ -62,7 +61,6 @@ export class IdeComponent implements OnInit {
this.subscribeWS();
this.subscribeFirstLanguageDetection();
this.requestCode();
this.initProcessManagerService();
this.resetAutoSaveCountdown();
}
@ -71,6 +69,10 @@ export class IdeComponent implements OnInit {
this.command_handlers[message.key](message);
this.changeDetectorRef.detectChanges();
});
this.webSocketService.observeKey<DeployMessage>('deploy.finish').subscribe(
message => this.deployHandler(message)
);
}
subscribeFirstLanguageDetection() {
@ -79,24 +81,6 @@ export class IdeComponent implements OnInit {
);
}
initProcessManagerService() {
this.processManagerService.init();
this.processManagerService.subscribeCallback(
config.ide.deployProcessName,
() => this.deploymentNotificationService.deploying.next(false)
);
this.processManagerService.subscribeSuccessCallback(
config.ide.deployProcessName,
message => this.setDeployButtonState(DeployButtonState.DEPLOYED)
);
this.processManagerService.subscribeErrorCallback(
config.ide.deployProcessName,
() => this.setDeployButtonState(DeployButtonState.FAILED)
);
}
reloadHandler(message: WebSocketMessage) {
this.requestCode();
}
@ -115,6 +99,15 @@ export class IdeComponent implements OnInit {
this.setCodeState(CodeState.SAVED);
}
deployHandler(message: WebSocketMessage) {
if (message['status'] === 'success') {
this.setDeployButtonState(DeployButtonState.DEPLOYED);
} else if (message['status'] === 'error') {
this.setDeployButtonState(DeployButtonState.FAILED);
}
this.deploymentNotificationService.deploying.next(false);
}
autoDetectEditorLanguageIfEnabled(filename: string) {
if (!config.ide.autoDetectFileLanguage) {
return;
@ -167,7 +160,7 @@ export class IdeComponent implements OnInit {
}
deployCode() {
this.processManagerService.restartProcess(config.ide.deployProcessName);
this.webSocketService.send({'key': 'deploy.start'});
this.setDeployButtonState(DeployButtonState.DEPLOYING);
this.deploymentNotificationService.deploying.next(true);
}