1 import {Component, Input} from '@angular/core';
2 import {DropdownValue} from "app/ng2/components/ui/form-components/dropdown/ui-element-dropdown.component";
3 import {Link} from './link.model';
4 import {ServicePathMapItem} from "app/models/graph/nodes-and-links-map";
8 templateUrl: './link-row.component.html',
9 styleUrls: ['./link-row.component.less']
13 export class LinkRowComponent {
14 @Input() data:Array<ServicePathMapItem>;
16 @Input() removeRow:Function;
17 source: Array<DropdownValue> = [];
18 target: Array<DropdownValue> = [];
19 srcCP: Array<DropdownValue> = [];
20 targetCP: Array<DropdownValue> = [];
24 this.parseInitialData(this.data);
28 parseInitialData(data: Array<ServicePathMapItem>) {
29 this.source = this.convertValuesToDropDownOptions(data);
30 if (this.link.fromNode) {
31 let srcCPOptions = this.findOptions(data, this.link.fromNode);
32 if (!srcCPOptions) { return; }
33 this.srcCP = this.convertValuesToDropDownOptions(srcCPOptions);
34 if (this.link.fromCP) {
35 this.target = this.convertValuesToDropDownOptions(data);
36 if (this.link.toNode) {
37 let targetCPOptions = this.findOptions(data, this.link.toNode);
38 if (!targetCPOptions) { return; }
39 this.targetCP = this.convertValuesToDropDownOptions(targetCPOptions);
45 private findOptions(items: Array<ServicePathMapItem>, nodeOrCPId: string) {
46 let item = _.find(items, (dataItem) => nodeOrCPId === dataItem.id);
47 if (item && item.data && item.data.options) {
48 return item.data.options;
50 console.warn('no option was found to match selection of Node/CP with id:' + nodeOrCPId);
54 private convertValuesToDropDownOptions(values: Array<ServicePathMapItem>): Array<DropdownValue> {
55 let result:Array<DropdownValue> = [];
56 for (let i = 0; i < values.length ; i++) {
57 result[result.length] = new DropdownValue(values[i].id, values[i].data.name);
59 return result.sort((a, b) => a.label.localeCompare(b.label));
62 onSourceSelected(id) {
64 let srcCPOptions = this.findOptions(this.data, id);
65 this.srcCP = this.convertValuesToDropDownOptions(srcCPOptions);
66 this.link.fromCP = '';
67 this.link.toNode = '';
74 onSrcCPSelected (id) {
76 let srcCPOptions = this.findOptions(this.data, this.link.fromNode);
77 let srcCPData = srcCPOptions.find(option => id === option.id).data;
78 this.target = this.convertValuesToDropDownOptions(this.data);
79 this.link.fromCPOriginId = srcCPData.ownerId;
80 this.link.toNode = '';
87 onTargetSelected(id) {
89 let targetCPOptions = this.findOptions(this.data, id);
90 this.targetCP = this.convertValuesToDropDownOptions(targetCPOptions);
96 onTargetCPSelected(id) {
98 let targetCPOptions = this.findOptions(this.data, this.link.toNode);
99 let targetCPDataObj = targetCPOptions.find(option => id === option.id).data;
100 this.link.toCPOriginId = targetCPDataObj.ownerId;