diff --git a/src/app/components/project-map/log-console/log-console.component.ts b/src/app/components/project-map/log-console/log-console.component.ts
index 330bdffa..ccab35ca 100644
--- a/src/app/components/project-map/log-console/log-console.component.ts
+++ b/src/app/components/project-map/log-console/log-console.component.ts
@@ -5,6 +5,9 @@ import { NodeService } from '../../../services/node.service';
import { NodesDataSource } from '../../../cartography/datasources/nodes-datasource';
import { Project } from '../../../models/project';
import { Server } from '../../../models/server';
+import { Drawing } from '../../../cartography/models/drawing';
+import { Link } from '../../../models/link';
+import { Node } from '../../../cartography/models/node';
@Component({
@@ -16,13 +19,16 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
@Input() project: Project;
@Input() server: Server;
@ViewChild('console', {static: false}) console: ElementRef;
- private subscription: Subscription;
+ private nodeSubscription: Subscription;
+ private linkSubscription: Subscription;
+ private drawingSubscription: Subscription;
command: string = '';
private regexStart: RegExp = /^start (.*?)$/;
private regexStop: RegExp = /^stop (.*?)$/;
private regexSuspend: RegExp = /^suspend (.*?)$/;
private regexReload: RegExp = /^reload (.*?)$/;
+ private regexShow: RegExp = /^show (.*?)$/;
constructor(
private projectWebServiceHandler: ProjectWebServiceHandler,
@@ -31,10 +37,21 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
) {}
ngOnInit() {
- this.subscription = this.projectWebServiceHandler.logEmitter.subscribe((event) => {
- let message = `Event received: ${event.action}.`
+ this.nodeSubscription = this.projectWebServiceHandler.nodeNotificationEmitter.subscribe((event) => {
+ let node: Node = event.event as Node;
+ let message = `Event received: ${event.action} - ${this.printNode(node)}.`
this.showMessage(message);
- })
+ });
+ this.linkSubscription = this.projectWebServiceHandler.linkNotificationEmitter.subscribe((event) => {
+ let link: Link = event.event as Link;
+ let message = `Event received: ${event.action} - ${this.printLink(link)}.`
+ this.showMessage(message);
+ });
+ this.drawingSubscription = this.projectWebServiceHandler.drawingNotificationEmitter.subscribe((event) => {
+ let drawing: Drawing = event.event as Drawing;
+ let message = `Event received: ${event.action} - ${this.printDrawing(drawing)}.`
+ this.showMessage(message);
+ });
}
ngAfterViewInit() {
@@ -42,7 +59,9 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
}
ngOnDestroy() {
- this.subscription.unsubscribe();
+ this.nodeSubscription.unsubscribe();
+ this.linkSubscription.unsubscribe();
+ this.drawingSubscription.unsubscribe();
}
onKeyDown(event) {
@@ -52,7 +71,11 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
}
handleCommand() {
- if (this.command === 'start all') {
+ if (this.command === 'help') {
+ this.showMessage("Available commands: help, version, start all, start {node name}, stop all, stop {node name}, suspend all, suspend {node name}, reload all, reload {node name}, show {node name}.")
+ } else if (this.command === 'version') {
+ this.showMessage("Current version: 2019.2.0");
+ } else if (this.command === 'start all') {
this.showMessage("Starting all nodes...");
this.nodeService.startAll(this.server, this.project).subscribe(() => {
this.showMessage("All nodes started.")
@@ -72,51 +95,31 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
this.nodeService.reloadAll(this.server, this.project).subscribe(() => {
this.showMessage("All nodes reloaded.")
});
- } else if (this.regexStart.test(this.command)) {
+ } else if (
+ this.regexStart.test(this.command) || this.regexStop.test(this.command) || this.regexSuspend.test(this.command) || this.regexReload.test(this.command)) {
let splittedCommand = this.command.split(/[ ,]+/);
- let node = this.nodesDataSource.getItems().find(n => {
- n.name.valueOf() === splittedCommand[1].valueOf();
- return n;
- });
+ let node = this.nodesDataSource.getItems().find(n => n.name.valueOf() === splittedCommand[1].valueOf());
if (node) {
- this.showMessage(`Starting node ${splittedCommand[1]}...`);
- this.nodeService.start(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} started.`));
- } else {
- this.showMessage(`Node with ${splittedCommand[1]} name was not found.`);
- }
- } else if (this.regexStop.test(this.command)) {
- let splittedCommand = this.command.split(/[ ,]+/);
- let node = this.nodesDataSource.getItems().find(n => {
- n.name.valueOf() === splittedCommand[1].valueOf();
- return n;
- });
- if (node) {
- this.showMessage(`Stopping node ${splittedCommand[1]}...`);
- this.nodeService.stop(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} stopped.`));
- } else {
- this.showMessage(`Node with ${splittedCommand[1]} name was not found.`);
- }
- } else if (this.regexSuspend.test(this.command)) {
- let splittedCommand = this.command.split(/[ ,]+/);
- let node = this.nodesDataSource.getItems().find(n => {
- n.name.valueOf() === splittedCommand[1].valueOf();
- return n;
- });
- if (node) {
- this.showMessage(`Suspending node ${splittedCommand[1]}...`);
- this.nodeService.suspend(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} stopped.`));
- } else {
- this.showMessage(`Node with ${splittedCommand[1]} name was not found.`);
- }
- } else if (this.regexReload.test(this.command)) {
- let splittedCommand = this.command.split(/[ ,]+/);
- let node = this.nodesDataSource.getItems().find(n => {
- n.name.valueOf() === splittedCommand[1].valueOf();
- return n;
- });
- if (node) {
- this.showMessage(`Reloading node ${splittedCommand[1]}...`);
- this.nodeService.reload(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} reloaded.`));
+ if (this.regexStart.test(this.command)) {
+ this.showMessage(`Starting node ${splittedCommand[1]}...`);
+ this.nodeService.start(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} started.`));
+ }
+ else if (this.regexStop.test(this.command)) {
+ this.showMessage(`Stopping node ${splittedCommand[1]}...`);
+ this.nodeService.stop(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} stopped.`));
+ }
+ else if (this.regexSuspend.test(this.command)) {
+ this.showMessage(`Suspending node ${splittedCommand[1]}...`);
+ this.nodeService.suspend(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} suspended.`));
+ }
+ else if (this.regexReload.test(this.command)) {
+ this.showMessage(`Reloading node ${splittedCommand[1]}...`);
+ this.nodeService.reload(this.server, node).subscribe(() => this.showMessage(`Node ${node.name} reloaded.`));
+ }
+ else if (this.regexShow.test(this.command)) {
+ this.showMessage(`Information about node ${node.name}:`);
+ this.showMessage(this.printNode(node));
+ }
} else {
this.showMessage(`Node with ${splittedCommand[1]} name was not found.`);
}
@@ -130,4 +133,17 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
this.console.nativeElement.innerHTML += message += "
";
this.console.nativeElement.scrollTop = this.console.nativeElement.scrollHeight;
}
+
+ printNode(node: Node): string {
+ return 'command line: ' + node.command_line + ', '
+ + 'name: ' + node.name
+ }
+
+ printLink(link: Link): string {
+ return '';
+ }
+
+ printDrawing(drawing: Drawing): string {
+ return '';
+ }
}
diff --git a/src/app/handlers/project-web-service-handler.ts b/src/app/handlers/project-web-service-handler.ts
index d4f93c5c..c42379a9 100644
--- a/src/app/handlers/project-web-service-handler.ts
+++ b/src/app/handlers/project-web-service-handler.ts
@@ -15,7 +15,9 @@ export class WebServiceMessage {
@Injectable()
export class ProjectWebServiceHandler {
- public logEmitter = new EventEmitter();
+ public nodeNotificationEmitter = new EventEmitter();
+ public linkNotificationEmitter = new EventEmitter();
+ public drawingNotificationEmitter = new EventEmitter();
constructor(
private nodesDataSource: NodesDataSource,
@@ -24,35 +26,41 @@ export class ProjectWebServiceHandler {
) {}
public handleMessage(message: WebServiceMessage) {
- if( message.action !== 'ping' && message.action !== 'compute.updated') {
- this.logEmitter.emit(message);
- }
if (message.action === 'node.updated') {
this.nodesDataSource.update(message.event as Node);
+ this.nodeNotificationEmitter.emit(message);
}
if (message.action === 'node.created') {
this.nodesDataSource.add(message.event as Node);
+ this.nodeNotificationEmitter.emit(message);
}
if (message.action === 'node.deleted') {
this.nodesDataSource.remove(message.event as Node);
+ this.nodeNotificationEmitter.emit(message);
}
if (message.action === 'link.created') {
this.linksDataSource.add(message.event as Link);
+ this.linkNotificationEmitter.emit(message);
}
if (message.action === 'link.updated') {
this.linksDataSource.update(message.event as Link);
+ this.linkNotificationEmitter.emit(message);
}
if (message.action === 'link.deleted') {
this.linksDataSource.remove(message.event as Link);
+ this.linkNotificationEmitter.emit(message);
}
if (message.action === 'drawing.created') {
this.drawingsDataSource.add(message.event as Drawing);
+ this.drawingNotificationEmitter.emit(message);
}
if (message.action === 'drawing.updated') {
this.drawingsDataSource.update(message.event as Drawing);
+ this.drawingNotificationEmitter.emit(message);
}
if (message.action === 'drawing.deleted') {
this.drawingsDataSource.remove(message.event as Drawing);
+ this.drawingNotificationEmitter.emit(message);
}
}
}