From f225de7467d04111f76cfdd7646a31a2e0a3e47b Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Thu, 14 Nov 2019 00:42:22 -0800 Subject: [PATCH] Support for different names --- .../project-map/project-map.component.ts | 15 ++++++++++++--- .../template-list-dialog.component.html | 8 ++++---- .../template-list-dialog.component.ts | 2 +- src/app/services/node.service.ts | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/app/components/project-map/project-map.component.ts b/src/app/components/project-map/project-map.component.ts index 1e6c39d0..41894384 100644 --- a/src/app/components/project-map/project-map.component.ts +++ b/src/app/components/project-map/project-map.component.ts @@ -407,13 +407,16 @@ export class ProjectMapComponent implements OnInit, OnDestroy { this.subscriptions.push(onInterfaceLabelContextMenu); this.mapChangeDetectorRef.detectChanges(); } - + onNodeCreation(nodeAddedEvent: NodeAddedEvent) { if(!nodeAddedEvent) { return; } - - this.nodeService.createFromTemplate(this.server, this.project, nodeAddedEvent.template, nodeAddedEvent.x, nodeAddedEvent.y, 'local').subscribe(() => { + this.nodeService.createFromTemplate(this.server, this.project, nodeAddedEvent.template, nodeAddedEvent.x, nodeAddedEvent.y, 'local').subscribe((node: Node) => { + if (nodeAddedEvent.name !== nodeAddedEvent.template.name) { + node.name = nodeAddedEvent.name; + this.nodeService.updateNode(this.server, node).subscribe(()=>{}); + } this.projectService.nodes(this.server, this.project.project_id).subscribe((nodes: Node[]) => { nodes.filter((node) => node.label.style === null).forEach((node) => { @@ -422,6 +425,12 @@ export class ProjectMapComponent implements OnInit, OnDestroy { }); this.nodesDataSource.set(nodes); + nodeAddedEvent.numberOfNodes--; + if (nodeAddedEvent.numberOfNodes > 0) { + nodeAddedEvent.x = nodeAddedEvent.x + 50 < this.project.scene_width/2 ? nodeAddedEvent.x + 50 : nodeAddedEvent.x; + nodeAddedEvent.y = nodeAddedEvent.y + 50 < this.project.scene_height/2 ? nodeAddedEvent.y + 50 : nodeAddedEvent.y; + this.onNodeCreation(nodeAddedEvent); + } }); }); } diff --git a/src/app/components/template/template-list-dialog/template-list-dialog.component.html b/src/app/components/template/template-list-dialog/template-list-dialog.component.html index 1bf9d570..4306d9dd 100644 --- a/src/app/components/template/template-list-dialog/template-list-dialog.component.html +++ b/src/app/components/template/template-list-dialog/template-list-dialog.component.html @@ -40,10 +40,10 @@
- + - +
@@ -53,11 +53,11 @@
Left:  - + Top:  - +
diff --git a/src/app/components/template/template-list-dialog/template-list-dialog.component.ts b/src/app/components/template/template-list-dialog/template-list-dialog.component.ts index 76283bd5..37fa20e0 100644 --- a/src/app/components/template/template-list-dialog/template-list-dialog.component.ts +++ b/src/app/components/template/template-list-dialog/template-list-dialog.component.ts @@ -70,7 +70,7 @@ export class TemplateListDialogComponent implements OnInit { } onAddClick(): void { - if (!this.selectedTemplate) { + if (!this.selectedTemplate || this.filteredTemplates.length === 0) { this.toasterService.error('Please firstly choose template.'); } else if (!this.positionForm.valid || !this.configurationForm.valid) { this.toasterService.error('Please fill all required fields.'); diff --git a/src/app/services/node.service.ts b/src/app/services/node.service.ts index ff1b2bb6..2e8467ae 100644 --- a/src/app/services/node.service.ts +++ b/src/app/services/node.service.ts @@ -45,7 +45,7 @@ export class NodeService { return this.httpServer.post(server, `/projects/${project.project_id}/nodes/reload`, {}); } - createFromTemplate(server: Server, project: Project, template: Template, x: number, y: number, compute_id: string) { + createFromTemplate(server: Server, project: Project, template: Template, x: number, y: number, compute_id: string): Observable { return this.httpServer.post(server, `/projects/${project.project_id}/templates/${template.template_id}`, { x: Math.round(x), y: Math.round(y),