From abcf6f72de997389785f37f12e3298d8f13985cc Mon Sep 17 00:00:00 2001 From: ziajka Date: Thu, 30 Nov 2017 14:49:44 +0100 Subject: [PATCH] Add node to 0,0 position --- .../appliance-list-dialog.component.html | 2 +- .../appliance-list-dialog.component.ts | 9 +++---- src/app/appliance/appliance.component.ts | 10 ++++---- .../project-map/project-map.component.html | 2 +- src/app/project-map/project-map.component.ts | 24 ++++++++++++------- src/app/shared/services/node.service.ts | 11 ++++++--- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/app/appliance/appliance-list-dialog/appliance-list-dialog.component.html b/src/app/appliance/appliance-list-dialog/appliance-list-dialog.component.html index 2fe82d0a..2be8b639 100644 --- a/src/app/appliance/appliance-list-dialog/appliance-list-dialog.component.html +++ b/src/app/appliance/appliance-list-dialog/appliance-list-dialog.component.html @@ -9,7 +9,7 @@ Name - {{row.name}} + {{row.name}} diff --git a/src/app/appliance/appliance-list-dialog/appliance-list-dialog.component.ts b/src/app/appliance/appliance-list-dialog/appliance-list-dialog.component.ts index 6a43e96b..12bbd2eb 100644 --- a/src/app/appliance/appliance-list-dialog/appliance-list-dialog.component.ts +++ b/src/app/appliance/appliance-list-dialog/appliance-list-dialog.component.ts @@ -53,12 +53,9 @@ export class ApplianceListDialogComponent implements OnInit { this.dialogRef.close(); } - // - // applyFilter(filterValue: string) { - // filterValue = filterValue.trim(); // Remove whitespace - // filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches - // this.dataSource.filter = filterValue; - // } + addNode(appliance: Appliance): void { + this.dialogRef.close(appliance); + } } diff --git a/src/app/appliance/appliance.component.ts b/src/app/appliance/appliance.component.ts index 7c025951..cf83ee77 100644 --- a/src/app/appliance/appliance.component.ts +++ b/src/app/appliance/appliance.component.ts @@ -1,4 +1,4 @@ -import {Component, Input, OnInit} from '@angular/core'; +import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {MatDialog} from "@angular/material"; import {ApplianceListDialogComponent} from "./appliance-list-dialog/appliance-list-dialog.component"; @@ -11,7 +11,7 @@ import {Server} from "../shared/models/server"; }) export class ApplianceComponent implements OnInit { @Input() server: Server; - + @Output() onNodeCreation = new EventEmitter(); constructor(private dialog: MatDialog) { } @@ -26,8 +26,10 @@ export class ApplianceComponent implements OnInit { } }); - dialogRef.afterClosed().subscribe(() => { - + dialogRef.afterClosed().subscribe((appliance: AppendMode) => { + if (appliance !== null) { + this.onNodeCreation.emit(appliance); + } }); } } diff --git a/src/app/project-map/project-map.component.html b/src/app/project-map/project-map.component.html index 77238841..265ad840 100644 --- a/src/app/project-map/project-map.component.html +++ b/src/app/project-map/project-map.component.html @@ -26,7 +26,7 @@ - + diff --git a/src/app/project-map/project-map.component.ts b/src/app/project-map/project-map.component.ts index 76580a2e..4b16b5fd 100644 --- a/src/app/project-map/project-map.component.ts +++ b/src/app/project-map/project-map.component.ts @@ -27,6 +27,8 @@ import { ProgressDialogComponent } from "../shared/progress-dialog/progress-dial import { ToastyService } from "ng2-toasty"; import { Drawing } from "../cartography/shared/models/drawing.model"; import { NodeContextMenuComponent } from "../shared/node-context-menu/node-context-menu.component"; +import {Appliance} from "../shared/models/appliance"; +import {NodeService} from "../shared/services/node.service"; @Component({ @@ -55,6 +57,7 @@ export class ProjectMapComponent implements OnInit { private projectService: ProjectService, private symbolService: SymbolService, private snapshotService: SnapshotService, + private nodeService: NodeService, private dialog: MatDialog, private progressDialogService: ProgressDialogService, private toastyService: ToastyService) { @@ -176,15 +179,18 @@ 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); - // } + onNodeCreation(appliance: Appliance) { + this.nodeService + .createFromAppliance(this.server, this.project, appliance, 0, 0, 'local') + .subscribe(() => { + this.projectService + .nodes(this.server, this.project.project_id) + .subscribe((nodes: Node[]) => { + this.nodes = nodes; + this.mapChild.reload(); + }); + }); + } public createSnapshotModal() { const dialogRef = this.dialog.open(CreateSnapshotDialogComponent, { diff --git a/src/app/shared/services/node.service.ts b/src/app/shared/services/node.service.ts index c7517c09..8c1d1ea5 100644 --- a/src/app/shared/services/node.service.ts +++ b/src/app/shared/services/node.service.ts @@ -7,6 +7,7 @@ import 'rxjs/add/operator/map'; import { Server } from "../models/server"; import { HttpServer } from "./http-server.service"; import {Appliance} from "../models/appliance"; +import {Response} from "@angular/http"; @Injectable() @@ -26,10 +27,14 @@ export class NodeService { .map(response => response.json() as Node); } - createFromAppliance(server: Server, project: Project, appliance: Appliance): Observable { + createFromAppliance( + server: Server, project: Project, appliance: Appliance, + x: number, y: number, compute_id: string): Observable { return this.httpServer - .post(server, `/projects/${project.project_id}/appliances/${appliance.appliance_id}`, {}) - .map(response => response.json() as Node); + .post( + server, + `/projects/${project.project_id}/appliances/${appliance.appliance_id}`, + {'x': x, 'y': y, 'compute_id': compute_id}); } }