Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember start dependency when creating new one #56 #60

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h4 class="modal-title">Create dependency</h4>
<div class="form-group">
<label>Source: </label>
<div>
<jhi-microservice-search (itemSelected)="onSourceSelected($event)"></jhi-microservice-search>
<jhi-microservice-search [initialValue]="source" (itemSelected)="onSourceSelected($event)"></jhi-microservice-search>
</div>
</div>
<div class="form-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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 {
private isOpen = false;

constructor(private modalService: NgbModal) {}

open(): void {
open(initialSource?: IMicroservice): void {
if (this.isOpen) {
return;
}
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,11 @@ export class DependencyDashboardComponent implements OnInit, AfterViewInit, OnDe
}

refreshGraph(dependencies: IDependency[], microservices: IMicroservice[]): void {
const edges = new DataSet<any>();

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;
}
Expand All @@ -148,16 +146,30 @@ export class DependencyDashboardComponent implements OnInit, AfterViewInit, OnDe
});
}

dependencies.forEach(d => {
const edges = new DataSet<any>();
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<any>([...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<any>(filteredMicroservices.map(m => this.convertToGraphNode(m)));

const data = { nodes, edges };

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMicroservice>();
@Output() groupFilterChanged = new EventEmitter<IMicroserviceGroupFilter>();

constructor(protected microserviceService: MicroserviceService) {}

ngOnInit(): void {}
ngOnInit(): void {
if (this.initialValue) {
this.model = this.initialValue;
}
}

search = (text$: Observable<string>) =>
text$.pipe(
Expand Down