From 9d8e8ca42ea7b5120ae4a15faa04c769aafa9ef9 Mon Sep 17 00:00:00 2001 From: ziajka Date: Thu, 30 Nov 2017 08:59:52 +0100 Subject: [PATCH] Start/stop node - moved out actions --- src/app/app.module.ts | 5 ++-- src/app/cartography/map/map.component.html | 2 -- src/app/cartography/map/map.component.ts | 15 ++-------- src/app/map/map.component.spec.ts | 27 ----------------- .../project-map/project-map.component.html | 7 ++--- src/app/project-map/project-map.component.ts | 29 ++++++++++++------- .../actions/start-node-action.ts | 2 +- .../start-node-action.component.html | 7 +++-- .../start-node-action.component.scss | 0 .../start-node-action.component.ts | 20 ++++++++++--- .../stop-node-action.component.html | 4 +++ .../stop-node-action.component.spec.ts | 25 ++++++++++++++++ .../stop-node-action.component.ts | 27 +++++++++++++++++ .../node-context-menu.component.html | 14 ++------- .../node-context-menu.component.ts | 13 ++------- 15 files changed, 108 insertions(+), 89 deletions(-) delete mode 100644 src/app/map/map.component.spec.ts delete mode 100644 src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.scss create mode 100644 src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.html create mode 100644 src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.spec.ts create mode 100644 src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 48274cd0..5576e495 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,7 +23,6 @@ import { ToastyModule } from 'ng2-toasty'; import { AppRoutingModule } from './app-routing.module'; - import { VersionService } from './shared/services/version.service'; import { ProjectService } from './shared/services/project.service'; import { SymbolService } from "./shared/services/symbol.service"; @@ -32,6 +31,7 @@ import { IndexedDbService } from "./shared/services/indexed-db.service"; import { HttpServer } from "./shared/services/http-server.service"; import { SnapshotService } from "./shared/services/snapshot.service"; import { ProgressDialogService } from "./shared/progress-dialog/progress-dialog.service"; +import { NodeService } from "./shared/services/node.service"; import { ProjectsComponent } from './projects/projects.component'; import { DefaultLayoutComponent } from './default-layout/default-layout.component'; @@ -41,8 +41,8 @@ import { MapComponent } from './cartography/map/map.component'; import { CreateSnapshotDialogComponent, ProjectMapComponent } from './project-map/project-map.component'; import { ServersComponent, AddServerDialogComponent } from './servers/servers.component'; import { NodeContextMenuComponent } from './shared/node-context-menu/node-context-menu.component'; -import {NodeService} from "./shared/services/node.service"; import { StartNodeActionComponent } from './shared/node-context-menu/actions/start-node-action/start-node-action.component'; +import { StopNodeActionComponent } from './shared/node-context-menu/actions/stop-node-action/stop-node-action.component'; @NgModule({ @@ -58,6 +58,7 @@ import { StartNodeActionComponent } from './shared/node-context-menu/actions/sta ProgressDialogComponent, NodeContextMenuComponent, StartNodeActionComponent, + StopNodeActionComponent, ], imports: [ NgbModule.forRoot(), diff --git a/src/app/cartography/map/map.component.html b/src/app/cartography/map/map.component.html index 0985703a..c56fc706 100644 --- a/src/app/cartography/map/map.component.html +++ b/src/app/cartography/map/map.component.html @@ -1,3 +1 @@ - - diff --git a/src/app/cartography/map/map.component.ts b/src/app/cartography/map/map.component.ts index b82dad4b..2c1b9488 100644 --- a/src/app/cartography/map/map.component.ts +++ b/src/app/cartography/map/map.component.ts @@ -1,6 +1,5 @@ import { - Component, ElementRef, Input, OnChanges, OnDestroy, OnInit, SimpleChange, - ViewChild + Component, ElementRef, Input, OnChanges, OnDestroy, OnInit, SimpleChange } from '@angular/core'; import { D3, D3Service } from 'd3-ng2-service'; import { Selection } from 'd3-selection'; @@ -12,8 +11,6 @@ import { Context } from "../../map/models/context"; import { Size } from "../shared/models/size.model"; import { Drawing } from "../shared/models/drawing.model"; -import {NodeContextMenuComponent} from "../../shared/node-context-menu/node-context-menu.component"; - @Component({ selector: 'app-map', @@ -28,13 +25,11 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy { @Input() height = 600; @Input() windowFullSize = true; - @ViewChild(NodeContextMenuComponent) nodeContextMenu: NodeContextMenuComponent; - private d3: D3; private parentNativeElement: any; private svg: Selection; - private graphLayout: GraphLayout; + public graphLayout: GraphLayout; private graphContext: Context; @@ -94,12 +89,6 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy { this.graphLayout = new GraphLayout(); this.graphLayout.draw(this.svg, this.graphContext); - - this.graphLayout.getNodesWidget().setOnContextMenuCallback((event: any, node: Node) => { - this.nodeContextMenu.open(node, event.clientY, event.clientX); - }); - - } } diff --git a/src/app/map/map.component.spec.ts b/src/app/map/map.component.spec.ts deleted file mode 100644 index 7bc30b62..00000000 --- a/src/app/map/map.component.spec.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { MapComponent } from '../cartography/map/map.component'; -import {D3Service} from "d3-ng2-service"; - -describe('MapComponent', () => { - let component: MapComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ MapComponent ], - providers: [ D3Service ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(MapComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should be created', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/project-map/project-map.component.html b/src/app/project-map/project-map.component.html index ed0e5ce4..ee1d03e8 100644 --- a/src/app/project-map/project-map.component.html +++ b/src/app/project-map/project-map.component.html @@ -13,13 +13,10 @@ - - - - - + + diff --git a/src/app/project-map/project-map.component.ts b/src/app/project-map/project-map.component.ts index 41747acf..f00ef0a0 100644 --- a/src/app/project-map/project-map.component.ts +++ b/src/app/project-map/project-map.component.ts @@ -29,6 +29,7 @@ import {Drawing} from "../cartography/shared/models/drawing.model"; import {StartNodeAction} from "../shared/node-context-menu/actions/start-node-action"; import {NodeService} from "../shared/services/node.service"; import {StopNodeAction} from "../shared/node-context-menu/actions/stop-node-action"; +import {NodeContextMenuComponent} from "../shared/node-context-menu/node-context-menu.component"; @Component({ @@ -43,12 +44,14 @@ export class ProjectMapComponent implements OnInit { public drawings: Drawing[] = []; project: Project; - server: Server; + public server: Server; private ws: Subject; @ViewChild(MapComponent) mapChild: MapComponent; + @ViewChild(NodeContextMenuComponent) nodeContextMenu: NodeContextMenuComponent; + constructor( private route: ActivatedRoute, private serverService: ServerService, @@ -109,10 +112,9 @@ export class ProjectMapComponent implements OnInit { n.icon = this.symbolService.get(n.symbol); }); - this.setUpNodeActions(); + this.setUpMapCallbacks(project); this.setUpWS(project); }); - } setUpWS(project: Project) { @@ -171,16 +173,23 @@ export class ProjectMapComponent implements OnInit { }); } - setUpNodeActions() { - this.mapChild.nodeContextMenu.clearActions(); - const start_node_action = new StartNodeAction(this.server, this.nodeService); - this.mapChild.nodeContextMenu.registerAction(start_node_action); - - const stop_node_action = new StopNodeAction(this.server, this.nodeService); - this.mapChild.nodeContextMenu.registerAction(stop_node_action); + setUpMapCallbacks(project: Project) { + this.mapChild.graphLayout.getNodesWidget().setOnContextMenuCallback((event: any, node: Node) => { + this.nodeContextMenu.open(node, event.clientY, event.clientX); + }); } + // setUpNodeActions() { + // this.mapChild.nodeContextMenu.clearActions(); + // + // const start_node_action = new StartNodeAction(this.server, this.nodeService); + // this.mapChild.nodeContextMenu.registerAction(start_node_action); + // + // const stop_node_action = new StopNodeAction(this.server, this.nodeService); + // this.mapChild.nodeContextMenu.registerAction(stop_node_action); + // } + public createSnapshotModal() { const dialogRef = this.dialog.open(CreateSnapshotDialogComponent, { width: '250px', diff --git a/src/app/shared/node-context-menu/actions/start-node-action.ts b/src/app/shared/node-context-menu/actions/start-node-action.ts index 4274a826..7ea20ffa 100644 --- a/src/app/shared/node-context-menu/actions/start-node-action.ts +++ b/src/app/shared/node-context-menu/actions/start-node-action.ts @@ -20,6 +20,6 @@ export class StartNodeAction implements NodeContextMenuAction { } onClick(node: Node) { - this.nodeService.start() + // this.nodeService.start() } } diff --git a/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.html b/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.html index 81565936..f3acc224 100644 --- a/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.html +++ b/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.html @@ -1,3 +1,4 @@ -

- start-node-action works! -

+ diff --git a/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.scss b/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.scss deleted file mode 100644 index e69de29b..00000000 diff --git a/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.ts b/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.ts index 16b2c37c..a2c6f65f 100644 --- a/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.ts +++ b/src/app/shared/node-context-menu/actions/start-node-action/start-node-action.component.ts @@ -1,15 +1,27 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, Input, OnInit} from '@angular/core'; +import {Server} from "../../../models/server"; +import {NodeService} from "../../../services/node.service"; +import {Node} from "../../../../cartography/shared/models/node.model"; + @Component({ selector: 'app-start-node-action', templateUrl: './start-node-action.component.html', - styleUrls: ['./start-node-action.component.scss'] }) export class StartNodeActionComponent implements OnInit { + @Input() server: Server; + @Input() node: Node; - constructor() { } + constructor(private nodeService: NodeService) { } - ngOnInit() { + ngOnInit() {} + + startNode() { + this.nodeService + .start(this.server, this.node) + .subscribe((n: Node) => { + + }); } } diff --git a/src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.html b/src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.html new file mode 100644 index 00000000..47f4016e --- /dev/null +++ b/src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.html @@ -0,0 +1,4 @@ + diff --git a/src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.spec.ts b/src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.spec.ts new file mode 100644 index 00000000..30228d8f --- /dev/null +++ b/src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { StopNodeActionComponent } from './stop-node-action.component'; + +describe('StopNodeActionComponent', () => { + let component: StopNodeActionComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ StopNodeActionComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(StopNodeActionComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.ts b/src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.ts new file mode 100644 index 00000000..5cb8fc47 --- /dev/null +++ b/src/app/shared/node-context-menu/actions/stop-node-action/stop-node-action.component.ts @@ -0,0 +1,27 @@ +import {Component, Input, OnInit} from '@angular/core'; +import {Server} from "../../../models/server"; +import {NodeService} from "../../../services/node.service"; +import {Node} from "../../../../cartography/shared/models/node.model"; + + +@Component({ + selector: 'app-stop-node-action', + templateUrl: './stop-node-action.component.html' +}) +export class StopNodeActionComponent implements OnInit { + @Input() server: Server; + @Input() node: Node; + + constructor(private nodeService: NodeService) { } + + ngOnInit() { + } + + stopNode() { + this.nodeService + .stop(this.server, this.node) + .subscribe((n: Node) => { + + }); + } +} diff --git a/src/app/shared/node-context-menu/node-context-menu.component.html b/src/app/shared/node-context-menu/node-context-menu.component.html index 8c0ec14e..9d669f5b 100644 --- a/src/app/shared/node-context-menu/node-context-menu.component.html +++ b/src/app/shared/node-context-menu/node-context-menu.component.html @@ -1,17 +1,7 @@
- - - - - - - - - - - - + +
diff --git a/src/app/shared/node-context-menu/node-context-menu.component.ts b/src/app/shared/node-context-menu/node-context-menu.component.ts index 1613e8bd..944bd9c2 100644 --- a/src/app/shared/node-context-menu/node-context-menu.component.ts +++ b/src/app/shared/node-context-menu/node-context-menu.component.ts @@ -2,7 +2,7 @@ import {ChangeDetectorRef, Component, Input, OnInit, ViewChild} from '@angular/c import {MatMenuTrigger} from "@angular/material"; import {DomSanitizer} from "@angular/platform-browser"; import {Node} from "../../cartography/shared/models/node.model"; -import {NodeContextMenuAction} from "./node-context-menu-action"; +import {Server} from "../models/server"; @Component({ @@ -11,12 +11,13 @@ import {NodeContextMenuAction} from "./node-context-menu-action"; styleUrls: ['./node-context-menu.component.scss'] }) export class NodeContextMenuComponent implements OnInit { + @Input() server: Server; + @ViewChild(MatMenuTrigger) contextMenu: MatMenuTrigger; private topPosition; private leftPosition; private node: Node; - private actions: NodeContextMenuAction[] = []; constructor( private sanitizer: DomSanitizer, @@ -38,12 +39,4 @@ export class NodeContextMenuComponent implements OnInit { this.contextMenu.openMenu(); } - public registerAction(action: NodeContextMenuAction) { - this.actions.push(action); - } - - public clearActions() { - this.actions = []; - } - }