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 let targetOptions = this.findOptions(srcCPOptions, this.link.fromCP);
36 if (!targetOptions) { return; }
37 this.target = this.convertValuesToDropDownOptions(targetOptions);
38 if (this.link.toNode) {
39 let targetCPOptions = this.findOptions(targetOptions, this.link.toNode);
40 if (!targetCPOptions) { return; }
41 this.targetCP = this.convertValuesToDropDownOptions(targetCPOptions);
47 private findOptions(items: Array<ServicePathMapItem>, nodeOrCPId: string) {
48 let item = items.find((dataItem)=> nodeOrCPId === dataItem.id);
49 if (item && item.data && item.data.options) {
50 return item.data.options;
52 console.warn('no option was found to match selection of Node/CP with id:' + nodeOrCPId);
56 private convertValuesToDropDownOptions(values: Array<ServicePathMapItem>) : Array<DropdownValue> {
58 for (let i = 0; i < values.length ; i++) {
59 result[result.length] = new DropdownValue(values[i].id, values[i].data.name);
64 onSourceSelected(id) {
66 let srcCPOptions = this.findOptions(this.data, id);
67 this.srcCP = this.convertValuesToDropDownOptions(srcCPOptions);
68 this.link.fromCP = '';
69 this.link.toNode = '';
76 onSrcCPSelected (id) {
78 let srcCPData = this.data.find((dataItem)=> this.link.fromNode === dataItem.id).data;
79 let srcCPOptions = srcCPData.options;
80 let targetOptions = this.findOptions(srcCPOptions, id);
81 this.target = this.convertValuesToDropDownOptions(targetOptions);
82 this.link.fromCPOriginId = srcCPData.ownerId;
83 this.link.toNode = '';
90 onTargetSelected(id) {
92 let srcCPOptions = this.findOptions(this.data, this.link.fromNode);
93 let targetOptions = this.findOptions(srcCPOptions, this.link.fromCP);
94 let targetCPOptions = this.findOptions(targetOptions, id);
95 this.targetCP = this.convertValuesToDropDownOptions(targetCPOptions);
101 onTargetCPSelected(id) {
103 let srcCPOptions = this.findOptions(this.data, this.link.fromNode);
104 let targetOptions = this.findOptions(srcCPOptions, this.link.fromCP);
105 let targetCPOptions = this.findOptions(targetOptions, this.link.toNode);
106 let targetCPDataObj = targetCPOptions.find((dataItem)=> id === dataItem.id).data;
107 this.link.toCPOriginId = targetCPDataObj.ownerId;