2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import * as _ from "lodash";
22 import { Component, ElementRef, forwardRef, Inject } from '@angular/core';
23 import {Link} from './link-row/link.model';
24 import {ForwardingPath} from 'app/models/forwarding-path';
25 import {ServiceServiceNg2} from "app/ng2/services/component-services/service.service";
26 import {ForwardingPathLink} from "app/models/forwarding-path-link";
27 import {ServicePathMapItem} from "app/models/graph/nodes-and-links-map";
30 selector: 'service-path-creator',
31 templateUrl: './service-path-creator.component.html',
32 styleUrls:['./service-path-creator.component.less'],
33 providers: [ServiceServiceNg2]
36 export class ServicePathCreatorComponent {
38 linksMap:Array<ServicePathMapItem>;
39 links:Array<Link> = [];
41 headers: Array<string> = [];
43 forwardingPath:ForwardingPath;
44 //isExtendAllowed:boolean = false;
46 constructor(private serviceService: ServiceServiceNg2) {
47 this.forwardingPath = new ForwardingPath();
48 this.links = [new Link(new ForwardingPathLink('', '', '', '', '', ''), true, false, true)];
49 this.headers = ['Source', 'Source Connection Point', 'Target', 'Target Connection Point', ' '];
50 this.removeRow = () => {
51 if (this.links.length === 1) {
54 this.links.splice(this.links.length-1, 1);
55 this.enableCurrentRow();
60 this.serviceService.getNodesAndLinksMap(this.input.service).subscribe((res:any) => {
63 this.processExistingPath();
67 private processExistingPath() {
68 if (this.input.pathId) {
69 let forwardingPath = <ForwardingPath>{...this.input.service.forwardingPaths[this.input.pathId]};
70 this.forwardingPath.name = forwardingPath.name;
71 this.forwardingPath.destinationPortNumber = forwardingPath.destinationPortNumber;
72 this.forwardingPath.protocol = forwardingPath.protocol;
73 this.forwardingPath.uniqueId = forwardingPath.uniqueId;
75 _.forEach(forwardingPath.pathElements.listToscaDataDefinition, (link:ForwardingPathLink) => {
76 this.links[this.links.length] = new Link(link, false, false, false);
78 this.links[this.links.length - 1].canEdit = true;
79 this.links[this.links.length - 1].canRemove = true;
80 this.links[0].isFirst = true;
84 isExtendAllowed():boolean {
85 if (this.links[this.links.length-1].toCP) {
92 this.links[this.links.length-1].canEdit = true;
93 if (this.links.length !== 1) {
94 this.links[this.links.length-1].canRemove = true;
100 this.links[this.links.length] = new Link(
101 new ForwardingPathLink(this.links[this.links.length-1].toNode,
102 this.links[this.links.length-1].toCP,
105 this.links[this.links.length-1].toCPOriginId,
115 for (let i = 0 ; i < this.links.length ; i++) {
116 this.links[i].canEdit = false;
117 this.links[i].canRemove = false;
121 createPathLinksObject() {
122 for (let i = 0 ; i < this.links.length ; i++) {
123 let link = this.links[i];
124 this.forwardingPath.addPathLink(link.fromNode, link.fromCP, link.toNode, link.toCP, link.fromCPOriginId, link.toCPOriginId);
128 createServicePathData() {
129 this.createPathLinksObject();
130 return this.forwardingPath;
133 checkFormValidForSubmit():boolean {
134 if (this.forwardingPath.name && this.isPathValid() ) {
140 isPathValid():boolean {
141 let lastLink = this.links[this.links.length -1] ;
142 if (lastLink.toNode && lastLink.toCP && lastLink.fromNode && lastLink.fromCP) {