From cf71b5cfc401486620290e2a421006276127a9d4 Mon Sep 17 00:00:00 2001 From: tillias Date: Thu, 22 Oct 2020 18:11:21 +0200 Subject: [PATCH] Remember start dependency when creating new one #56 --- .../create-dependency-dialog.component.html | 2 +- .../create-dependency-dialog.component.ts | 6 ++- .../create-dependency-dialog.service.ts | 4 +- .../dependency-dashboard.component.ts | 43 +++++++++++++++---- .../microservice-search.component.ts | 7 ++- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.component.html b/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.component.html index 880cdd8..2788ef7 100644 --- a/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.component.html +++ b/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.component.html @@ -10,7 +10,7 @@
- +
diff --git a/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.component.ts b/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.component.ts index 42fd87c..92de8f7 100644 --- a/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.component.ts +++ b/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.component.ts @@ -21,7 +21,11 @@ export class CreateDependencyDialogComponent implements OnInit { this.name = 'Please specify source & target'; } - ngOnInit(): void {} + ngOnInit(): void { + if (this.source) { + this.updateName(); + } + } createDependency(): void { if (this.source && this.target) { diff --git a/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.service.ts b/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.service.ts index 3f5a8bb..242a5d7 100644 --- a/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.service.ts +++ b/src/main/webapp/app/dashboard/dependency-dashboard/create-dependency-dialog/create-dependency-dialog.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import { NgbModal, NgbModalOptions, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { CreateDependencyDialogComponent } from './create-dependency-dialog.component'; +import { IMicroservice } from '../../../shared/model/microservice.model'; @Injectable({ providedIn: 'root' }) export class CreateDependencyDialogService { @@ -8,7 +9,7 @@ export class CreateDependencyDialogService { constructor(private modalService: NgbModal) {} - open(): void { + open(initialSource?: IMicroservice): void { if (this.isOpen) { return; } @@ -19,6 +20,7 @@ export class CreateDependencyDialogService { }; const modalRef: NgbModalRef = this.modalService.open(CreateDependencyDialogComponent, options); + modalRef.componentInstance.source = initialSource; modalRef.result.finally(() => (this.isOpen = false)); } } diff --git a/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.ts b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.ts index 74712f7..3ffdb2f 100644 --- a/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.ts +++ b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.ts @@ -125,13 +125,11 @@ export class DependencyDashboardComponent implements OnInit, AfterViewInit, OnDe } refreshGraph(dependencies: IDependency[], microservices: IMicroservice[]): void { - const edges = new DataSet(); - - const microservicesMap = new Map(microservices.map(m => [m.id, m])); + let filteredDependencies = dependencies; if (this.searchValue) { const searchID = this.searchValue.id; - dependencies = dependencies.filter(d => { + filteredDependencies = dependencies.filter(d => { if (this.onlyIncomingFilter && !this.onlyOutgoingFilter) { return d.target?.id === searchID; } @@ -148,16 +146,30 @@ export class DependencyDashboardComponent implements OnInit, AfterViewInit, OnDe }); } - dependencies.forEach(d => { + const edges = new DataSet(); + const nodeIds = new Set(); + + filteredDependencies.forEach(d => { if (d.source != null && d.target != null) { + const sourceID = d.source.id; + const targetID = d.target.id; + edges.add({ - from: d.source.id, - to: d.target.id, + from: sourceID, + to: targetID, }); + + nodeIds.add(sourceID); + nodeIds.add(targetID); } }); - const nodes = new DataSet([...microservicesMap.values()].map(m => this.convertToGraphNode(m))); + let filteredMicroservices = microservices; + if (this.searchValue) { + filteredMicroservices = microservices.filter(m => nodeIds.has(m.id)); + } + + const nodes = new DataSet(filteredMicroservices.map(m => this.convertToGraphNode(m))); const data = { nodes, edges }; @@ -179,6 +191,19 @@ export class DependencyDashboardComponent implements OnInit, AfterViewInit, OnDe buildDeploymentPath(): void {} createDependency(): void { - this.createDependencyDialogService.open(); + // Use selected microservice as dependency's start + if (this.selection) { + const id = this.selection.nodes[0]; + this.microserviceService + .find(id) + .pipe(map(r => r.body || undefined)) + .subscribe(r => this.openDialog(r)); + } else { + this.openDialog(this.searchValue); + } + } + + openDialog(initialSource?: IMicroservice): void { + this.createDependencyDialogService.open(initialSource); } } diff --git a/src/main/webapp/app/entities/microservice/microservice-dashboard/microservice-search/microservice-search.component.ts b/src/main/webapp/app/entities/microservice/microservice-dashboard/microservice-search/microservice-search.component.ts index 49da211..b1f662b 100644 --- a/src/main/webapp/app/entities/microservice/microservice-dashboard/microservice-search/microservice-search.component.ts +++ b/src/main/webapp/app/entities/microservice/microservice-dashboard/microservice-search/microservice-search.component.ts @@ -17,12 +17,17 @@ export class MicroserviceSearchComponent implements OnInit { * Enables advanced search capabilities. Default: false */ @Input() advanced = false; + @Input() initialValue?: IMicroservice; @Output() itemSelected = new EventEmitter(); @Output() groupFilterChanged = new EventEmitter(); constructor(protected microserviceService: MicroserviceService) {} - ngOnInit(): void {} + ngOnInit(): void { + if (this.initialValue) { + this.model = this.initialValue; + } + } search = (text$: Observable) => text$.pipe(