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";
28 import {CompositionService} from "app/ng2/pages/composition/composition.service";
31 selector: 'service-path-creator',
32 templateUrl: './service-path-creator.component.html',
33 styleUrls:['./service-path-creator.component.less'],
34 providers: [ServiceServiceNg2]
37 export class ServicePathCreatorComponent {
39 linksMap:Array<ServicePathMapItem>;
40 links:Array<Link> = [];
42 headers: Array<string> = [];
44 forwardingPath:ForwardingPath;
45 //isExtendAllowed:boolean = false;
47 constructor(private serviceService: ServiceServiceNg2,
48 private compositionService: CompositionService) {
49 this.forwardingPath = new ForwardingPath();
50 this.links = [new Link(new ForwardingPathLink('', '', '', '', '', ''), true, false, true)];
51 this.headers = ['Source', 'Source Connection Point', 'Target', 'Target Connection Point', ' '];
52 this.removeRow = () => {
53 if (this.links.length === 1) {
56 this.links.splice(this.links.length-1, 1);
57 this.enableCurrentRow();
62 this.serviceService.getNodesAndLinksMap(this.input.serviceId).subscribe((res:any) => {
65 this.processExistingPath();
69 private processExistingPath() {
70 if (this.input.pathId) {
71 let forwardingPath = <ForwardingPath>{...this.compositionService.forwardingPaths[this.input.pathId]};
72 this.forwardingPath.name = forwardingPath.name;
73 this.forwardingPath.destinationPortNumber = forwardingPath.destinationPortNumber;
74 this.forwardingPath.protocol = forwardingPath.protocol;
75 this.forwardingPath.uniqueId = forwardingPath.uniqueId;
77 _.forEach(forwardingPath.pathElements.listToscaDataDefinition, (link:ForwardingPathLink) => {
78 this.links[this.links.length] = new Link(link, false, false, false);
80 this.links[this.links.length - 1].canEdit = true;
81 this.links[this.links.length - 1].canRemove = true;
82 this.links[0].isFirst = true;
86 isExtendAllowed():boolean {
87 if (this.links[this.links.length-1].toCP) {
94 this.links[this.links.length-1].canEdit = true;
95 if (this.links.length !== 1) {
96 this.links[this.links.length-1].canRemove = true;
102 this.links[this.links.length] = new Link(
103 new ForwardingPathLink(this.links[this.links.length-1].toNode,
104 this.links[this.links.length-1].toCP,
107 this.links[this.links.length-1].toCPOriginId,
117 for (let i = 0 ; i < this.links.length ; i++) {
118 this.links[i].canEdit = false;
119 this.links[i].canRemove = false;
123 createPathLinksObject() {
124 for (let i = 0 ; i < this.links.length ; i++) {
125 let link = this.links[i];
126 this.forwardingPath.addPathLink(link.fromNode, link.fromCP, link.toNode, link.toCP, link.fromCPOriginId, link.toCPOriginId);
130 createServicePathData() {
131 this.createPathLinksObject();
132 return this.forwardingPath;
135 checkFormValidForSubmit():boolean {
136 if (this.forwardingPath.name && this.isPathValid() ) {
142 isPathValid():boolean {
143 let lastLink = this.links[this.links.length -1] ;
144 if (lastLink.toNode && lastLink.toCP && lastLink.fromNode && lastLink.fromCP) {