mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-16 05:21:55 +00:00
Merge pull request #12 from avatao-content/pmgeh
Implement manipulation of supervisor processes from frontend
This commit is contained in:
commit
ddc4430bde
@ -17,6 +17,7 @@ import { MessagesComponent } from './messages/messages.component';
|
|||||||
import { WebSocketService } from './services/websocket.service';
|
import { WebSocketService } from './services/websocket.service';
|
||||||
import { TerminalComponent } from './terminal/terminal.component';
|
import { TerminalComponent } from './terminal/terminal.component';
|
||||||
import { FSMUpdateService } from './services/fsmupdate.service';
|
import { FSMUpdateService } from './services/fsmupdate.service';
|
||||||
|
import { ProcessManagerService } from './services/processmanager.service';
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +43,8 @@ import { AppRoutingModule } from './app-routing.module';
|
|||||||
MarkdownService,
|
MarkdownService,
|
||||||
WebSocketService,
|
WebSocketService,
|
||||||
TerminadoService,
|
TerminadoService,
|
||||||
FSMUpdateService
|
FSMUpdateService,
|
||||||
|
ProcessManagerService
|
||||||
],
|
],
|
||||||
bootstrap: [
|
bootstrap: [
|
||||||
AppComponent
|
AppComponent
|
||||||
|
4
src/app/services/processcommand.ts
Normal file
4
src/app/services/processcommand.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export class ProcessCommand {
|
||||||
|
command: string;
|
||||||
|
process_name: string;
|
||||||
|
}
|
39
src/app/services/processmanager.service.ts
Normal file
39
src/app/services/processmanager.service.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
import { WebSocketService } from './websocket.service';
|
||||||
|
import { ProcessCommand } from './processcommand';
|
||||||
|
import { filter } from 'rxjs/operators';
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ProcessManagerService {
|
||||||
|
key = 'processmanager';
|
||||||
|
process_name: string;
|
||||||
|
|
||||||
|
constructor(private webSocketService: WebSocketService) {}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this.webSocketService.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribeCallback(process_name: string, callback: (event: any) => void) {
|
||||||
|
this.webSocketService.observeKey<ProcessCommand>(this.key)
|
||||||
|
.pipe(filter(message => message.data.process_name === process_name)).subscribe(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendCommand(command: string, process_name: string) {
|
||||||
|
this.webSocketService.send(this.key, {'command': command, 'process_name': process_name});
|
||||||
|
}
|
||||||
|
|
||||||
|
startProcess(process_name: string) {
|
||||||
|
this.sendCommand('start', process_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
stopProcess(process_name: string) {
|
||||||
|
this.sendCommand('stop', process_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
restartProcess(process_name: string) {
|
||||||
|
this.sendCommand('restart', process_name);
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
class="btn btn-secondary"
|
class="btn btn-secondary"
|
||||||
[class.active]="filename === file"
|
[class.active]="filename === file"
|
||||||
[class.disabled]="filename === file"
|
[class.disabled]="filename === file"
|
||||||
(click)="selectCode(file); requestCode()"
|
(click)="sendCodeContents(); selectCode(file); requestCode()"
|
||||||
[disabled]="filename === file">
|
[disabled]="filename === file">
|
||||||
{{file}}
|
{{file}}
|
||||||
</button>
|
</button>
|
||||||
@ -23,8 +23,8 @@
|
|||||||
type="submit"
|
type="submit"
|
||||||
class="btn btn-secondary"
|
class="btn btn-secondary"
|
||||||
[class.btn-success]="saveButtonState === 'SAVED'"
|
[class.btn-success]="saveButtonState === 'SAVED'"
|
||||||
[class.btn-warning]="saveButtonState === 'SAVING'"
|
[class.btn-info]="saveButtonState === 'SAVING'"
|
||||||
[class.disabled]="saveButtonState === 'SAVING'"
|
[class.disabled]="saveButtonState === 'SAVING'"
|
||||||
><span *ngIf="saveButtonState === 'DIRTY'">Save!</span>
|
><span *ngIf="saveButtonState === 'DIRTY'">Save!</span>
|
||||||
<span *ngIf="saveButtonState === 'SAVED'">Saved!</span>
|
<span *ngIf="saveButtonState === 'SAVED'">Done!</span>
|
||||||
<span *ngIf="saveButtonState === 'SAVING'">Saving...</span></button>
|
<span *ngIf="saveButtonState === 'SAVING'"><div class="loader"></div>Reloading...</span></button>
|
||||||
|
@ -7,3 +7,21 @@
|
|||||||
.btn-secondary {
|
.btn-secondary {
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loader {
|
||||||
|
border: 2px solid #ffffff;
|
||||||
|
border-radius: 50%;
|
||||||
|
border-top: 2px solid #212529;
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
animation: spin 2s linear infinite;
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 5px;
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% { transform: rotate(0deg); }
|
||||||
|
100% { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@ import 'brace/mode/sql';
|
|||||||
import 'brace/theme/monokai';
|
import 'brace/theme/monokai';
|
||||||
import { SourceCode } from './source-code';
|
import { SourceCode } from './source-code';
|
||||||
import { WebSocketService } from '../services/websocket.service';
|
import { WebSocketService } from '../services/websocket.service';
|
||||||
|
import { ProcessManagerService } from '../services/processmanager.service';
|
||||||
|
|
||||||
const modelist = brace.acequire('ace/ext/modelist');
|
const modelist = brace.acequire('ace/ext/modelist');
|
||||||
|
|
||||||
@ -35,15 +36,18 @@ export class WebideComponent implements OnInit {
|
|||||||
command_handlers = { 'reload': this.reloadHandler.bind(this),
|
command_handlers = { 'reload': this.reloadHandler.bind(this),
|
||||||
'read': this.readHandler.bind(this),
|
'read': this.readHandler.bind(this),
|
||||||
'select': this.selectHandler.bind(this),
|
'select': this.selectHandler.bind(this),
|
||||||
'write': this.writeHandler.bind(this)};
|
'write': () => {}};
|
||||||
|
|
||||||
constructor(private webSocketService: WebSocketService,
|
constructor(private webSocketService: WebSocketService,
|
||||||
private changeDetectorRef: ChangeDetectorRef) { }
|
private changeDetectorRef: ChangeDetectorRef,
|
||||||
|
private processManagerService: ProcessManagerService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.webSocketService.connect();
|
this.webSocketService.connect();
|
||||||
this.subscribeWS();
|
this.subscribeWS();
|
||||||
this.requestCode();
|
this.requestCode();
|
||||||
|
this.processManagerService.init();
|
||||||
|
this.processManagerService.subscribeCallback('login', (event) => { this.setButtonStateSaved(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeWS() {
|
subscribeWS() {
|
||||||
@ -72,7 +76,7 @@ export class WebideComponent implements OnInit {
|
|||||||
this.updateFileData(data);
|
this.updateFileData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeHandler(data: SourceCode) {
|
setButtonStateSaved() {
|
||||||
this.saveButtonState = 'SAVED';
|
this.saveButtonState = 'SAVED';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +85,16 @@ export class WebideComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendCode() {
|
sendCode() {
|
||||||
|
this.sendCodeContents();
|
||||||
|
this.saveButtonState = 'SAVING';
|
||||||
|
this.processManagerService.restartProcess('login');
|
||||||
|
}
|
||||||
|
|
||||||
|
sendCodeContents() {
|
||||||
this.webSocketService.send(this.key_id, {
|
this.webSocketService.send(this.key_id, {
|
||||||
'command': 'write',
|
'command': 'write',
|
||||||
'content': this.code
|
'content': this.code
|
||||||
});
|
});
|
||||||
this.saveButtonState = 'SAVING';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
requestCode() {
|
requestCode() {
|
||||||
|
Loading…
Reference in New Issue
Block a user