Start/stop node - moved out actions

This commit is contained in:
ziajka
2017-11-30 08:59:52 +01:00
parent 935b0b93e6
commit 9d8e8ca42e
15 changed files with 108 additions and 89 deletions

View File

@ -23,7 +23,6 @@ import { ToastyModule } from 'ng2-toasty';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { VersionService } from './shared/services/version.service'; import { VersionService } from './shared/services/version.service';
import { ProjectService } from './shared/services/project.service'; import { ProjectService } from './shared/services/project.service';
import { SymbolService } from "./shared/services/symbol.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 { HttpServer } from "./shared/services/http-server.service";
import { SnapshotService } from "./shared/services/snapshot.service"; import { SnapshotService } from "./shared/services/snapshot.service";
import { ProgressDialogService } from "./shared/progress-dialog/progress-dialog.service"; import { ProgressDialogService } from "./shared/progress-dialog/progress-dialog.service";
import { NodeService } from "./shared/services/node.service";
import { ProjectsComponent } from './projects/projects.component'; import { ProjectsComponent } from './projects/projects.component';
import { DefaultLayoutComponent } from './default-layout/default-layout.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 { CreateSnapshotDialogComponent, ProjectMapComponent } from './project-map/project-map.component';
import { ServersComponent, AddServerDialogComponent } from './servers/servers.component'; import { ServersComponent, AddServerDialogComponent } from './servers/servers.component';
import { NodeContextMenuComponent } from './shared/node-context-menu/node-context-menu.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 { 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({ @NgModule({
@ -58,6 +58,7 @@ import { StartNodeActionComponent } from './shared/node-context-menu/actions/sta
ProgressDialogComponent, ProgressDialogComponent,
NodeContextMenuComponent, NodeContextMenuComponent,
StartNodeActionComponent, StartNodeActionComponent,
StopNodeActionComponent,
], ],
imports: [ imports: [
NgbModule.forRoot(), NgbModule.forRoot(),

View File

@ -1,3 +1 @@
<svg preserveAspectRatio="none"></svg> <svg preserveAspectRatio="none"></svg>
<app-node-context-menu></app-node-context-menu>

Before

Width:  |  Height:  |  Size: 88 B

After

Width:  |  Height:  |  Size: 39 B

View File

@ -1,6 +1,5 @@
import { import {
Component, ElementRef, Input, OnChanges, OnDestroy, OnInit, SimpleChange, Component, ElementRef, Input, OnChanges, OnDestroy, OnInit, SimpleChange
ViewChild
} from '@angular/core'; } from '@angular/core';
import { D3, D3Service } from 'd3-ng2-service'; import { D3, D3Service } from 'd3-ng2-service';
import { Selection } from 'd3-selection'; import { Selection } from 'd3-selection';
@ -12,8 +11,6 @@ import { Context } from "../../map/models/context";
import { Size } from "../shared/models/size.model"; import { Size } from "../shared/models/size.model";
import { Drawing } from "../shared/models/drawing.model"; import { Drawing } from "../shared/models/drawing.model";
import {NodeContextMenuComponent} from "../../shared/node-context-menu/node-context-menu.component";
@Component({ @Component({
selector: 'app-map', selector: 'app-map',
@ -28,13 +25,11 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
@Input() height = 600; @Input() height = 600;
@Input() windowFullSize = true; @Input() windowFullSize = true;
@ViewChild(NodeContextMenuComponent) nodeContextMenu: NodeContextMenuComponent;
private d3: D3; private d3: D3;
private parentNativeElement: any; private parentNativeElement: any;
private svg: Selection<SVGSVGElement, any, null, undefined>; private svg: Selection<SVGSVGElement, any, null, undefined>;
private graphLayout: GraphLayout; public graphLayout: GraphLayout;
private graphContext: Context; private graphContext: Context;
@ -94,12 +89,6 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
this.graphLayout = new GraphLayout(); this.graphLayout = new GraphLayout();
this.graphLayout.draw(this.svg, this.graphContext); this.graphLayout.draw(this.svg, this.graphContext);
this.graphLayout.getNodesWidget().setOnContextMenuCallback((event: any, node: Node) => {
this.nodeContextMenu.open(node, event.clientY, event.clientX);
});
} }
} }

View File

@ -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<MapComponent>;
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();
});
});

View File

@ -13,13 +13,10 @@
</button> </button>
</mat-toolbar-row> </mat-toolbar-row>
<!--<mat-toolbar-row>-->
<!--<button mat-icon-button>-->
<!--<mat-icon>delete</mat-icon>-->
<!--</button>-->
<!--</mat-toolbar-row>-->
</mat-toolbar> </mat-toolbar>
</div> </div>
<app-node-context-menu [server]="server"></app-node-context-menu>
</div> </div>

View File

@ -29,6 +29,7 @@ import {Drawing} from "../cartography/shared/models/drawing.model";
import {StartNodeAction} from "../shared/node-context-menu/actions/start-node-action"; import {StartNodeAction} from "../shared/node-context-menu/actions/start-node-action";
import {NodeService} from "../shared/services/node.service"; import {NodeService} from "../shared/services/node.service";
import {StopNodeAction} from "../shared/node-context-menu/actions/stop-node-action"; import {StopNodeAction} from "../shared/node-context-menu/actions/stop-node-action";
import {NodeContextMenuComponent} from "../shared/node-context-menu/node-context-menu.component";
@Component({ @Component({
@ -43,12 +44,14 @@ export class ProjectMapComponent implements OnInit {
public drawings: Drawing[] = []; public drawings: Drawing[] = [];
project: Project; project: Project;
server: Server; public server: Server;
private ws: Subject<any>; private ws: Subject<any>;
@ViewChild(MapComponent) mapChild: MapComponent; @ViewChild(MapComponent) mapChild: MapComponent;
@ViewChild(NodeContextMenuComponent) nodeContextMenu: NodeContextMenuComponent;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private serverService: ServerService, private serverService: ServerService,
@ -109,10 +112,9 @@ export class ProjectMapComponent implements OnInit {
n.icon = this.symbolService.get(n.symbol); n.icon = this.symbolService.get(n.symbol);
}); });
this.setUpNodeActions(); this.setUpMapCallbacks(project);
this.setUpWS(project); this.setUpWS(project);
}); });
} }
setUpWS(project: 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); setUpMapCallbacks(project: Project) {
this.mapChild.nodeContextMenu.registerAction(start_node_action); this.mapChild.graphLayout.getNodesWidget().setOnContextMenuCallback((event: any, node: Node) => {
this.nodeContextMenu.open(node, event.clientY, event.clientX);
const stop_node_action = new StopNodeAction(this.server, this.nodeService); });
this.mapChild.nodeContextMenu.registerAction(stop_node_action);
} }
// 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() { public createSnapshotModal() {
const dialogRef = this.dialog.open(CreateSnapshotDialogComponent, { const dialogRef = this.dialog.open(CreateSnapshotDialogComponent, {
width: '250px', width: '250px',

View File

@ -20,6 +20,6 @@ export class StartNodeAction implements NodeContextMenuAction {
} }
onClick(node: Node) { onClick(node: Node) {
this.nodeService.start() // this.nodeService.start()
} }
} }

View File

@ -1,3 +1,4 @@
<p> <button mat-menu-item *ngIf="node.status == 'stopped'" (click)="startNode()">
start-node-action works! <mat-icon>play_arrow</mat-icon>
</p> <span>Start</span>
</button>

View File

@ -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({ @Component({
selector: 'app-start-node-action', selector: 'app-start-node-action',
templateUrl: './start-node-action.component.html', templateUrl: './start-node-action.component.html',
styleUrls: ['./start-node-action.component.scss']
}) })
export class StartNodeActionComponent implements OnInit { 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) => {
});
} }
} }

View File

@ -0,0 +1,4 @@
<button mat-menu-item *ngIf="node.status == 'started'" (click)="stopNode()">
<mat-icon>stop</mat-icon>
<span>Stop</span>
</button>

View File

@ -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<StopNodeActionComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ StopNodeActionComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(StopNodeActionComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -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) => {
});
}
}

View File

@ -1,17 +1,7 @@
<div class="context-menu" [style.left]="leftPosition" [style.top]="topPosition" *ngIf="node"> <div class="context-menu" [style.left]="leftPosition" [style.top]="topPosition" *ngIf="node">
<span [matMenuTriggerFor]="contextMenu"></span> <span [matMenuTriggerFor]="contextMenu"></span>
<mat-menu #contextMenu="matMenu"> <mat-menu #contextMenu="matMenu">
<!--<button mat-menu-item *ngIf="node.status == 'stopped'">--> <app-start-node-action [server]="server" [node]="node"></app-start-node-action>
<!--<mat-icon>play_arrow</mat-icon>--> <app-stop-node-action [server]="server" [node]="node"></app-stop-node-action>
<!--<span>Start</span>-->
<!--</button>-->
<!--<ng-container *ngFor="let action of actions">-->
<!--<button mat-menu-item *ngIf="action.isVisible(node)" (click)="action.onClick(node)">-->
<!--<mat-icon>{{ action.icon(node) }}</mat-icon>-->
<!--<span>{{ action.label(node) }}</span>-->
<!--</button>-->
<!--</ng-container>-->
</mat-menu> </mat-menu>
</div> </div>

View File

@ -2,7 +2,7 @@ import {ChangeDetectorRef, Component, Input, OnInit, ViewChild} from '@angular/c
import {MatMenuTrigger} from "@angular/material"; import {MatMenuTrigger} from "@angular/material";
import {DomSanitizer} from "@angular/platform-browser"; import {DomSanitizer} from "@angular/platform-browser";
import {Node} from "../../cartography/shared/models/node.model"; import {Node} from "../../cartography/shared/models/node.model";
import {NodeContextMenuAction} from "./node-context-menu-action"; import {Server} from "../models/server";
@Component({ @Component({
@ -11,12 +11,13 @@ import {NodeContextMenuAction} from "./node-context-menu-action";
styleUrls: ['./node-context-menu.component.scss'] styleUrls: ['./node-context-menu.component.scss']
}) })
export class NodeContextMenuComponent implements OnInit { export class NodeContextMenuComponent implements OnInit {
@Input() server: Server;
@ViewChild(MatMenuTrigger) contextMenu: MatMenuTrigger; @ViewChild(MatMenuTrigger) contextMenu: MatMenuTrigger;
private topPosition; private topPosition;
private leftPosition; private leftPosition;
private node: Node; private node: Node;
private actions: NodeContextMenuAction[] = [];
constructor( constructor(
private sanitizer: DomSanitizer, private sanitizer: DomSanitizer,
@ -38,12 +39,4 @@ export class NodeContextMenuComponent implements OnInit {
this.contextMenu.openMenu(); this.contextMenu.openMenu();
} }
public registerAction(action: NodeContextMenuAction) {
this.actions.push(action);
}
public clearActions() {
this.actions = [];
}
} }