blob: 49f4f42fd3578b41867f1d0ca1ea1bece07b96df [file] [log] [blame]
Skip Wonnell2c977e22018-03-01 08:30:15 -06001/*
2============LICENSE_START==========================================
3===================================================================
4Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5===================================================================
Sandeep J170263d2018-07-16 17:02:46 +05306Copyright (C) 2018 IBM.
7===================================================================
Skip Wonnell2c977e22018-03-01 08:30:15 -06008Unless otherwise specified, all software contained herein is licensed
9under the Apache License, Version 2.0 (the License);
10you may not use this software except in compliance with the License.
11You may obtain a copy of the License at
12
13 http://www.apache.org/licenses/LICENSE-2.0
14
15Unless required by applicable law or agreed to in writing, software
16distributed under the License is distributed on an "AS IS" BASIS,
17WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18See the License for the specific language governing permissions and
19limitations under the License.
20
Skip Wonnell2c977e22018-03-01 08:30:15 -060021============LICENSE_END============================================
22*/
23
Arundathi Patil897c4b72018-07-17 16:05:00 +053024import { Component, OnInit, OnDestroy } from '@angular/core';
Skip Wonnell2c977e22018-03-01 08:30:15 -060025import { ActivatedRoute, Router } from '@angular/router';
26import { HttpUtilService } from '../../shared/services/httpUtil/http-util.service';
Arundathi Patil897c4b72018-07-17 16:05:00 +053027import { Subscription } from 'rxjs/Subscription';
Skip Wonnell2c977e22018-03-01 08:30:15 -060028import { MappingEditorService } from '../../shared/services/mapping-editor.service';
29import { ParamShareService } from '../../shared/services/paramShare.service';
30import { environment } from '../../../environments/environment';
31import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
32import { NgProgress } from 'ngx-progressbar';
Sandeep J170263d2018-07-16 17:02:46 +053033import { NotificationsService } from 'angular2-notifications';
Arundathi Patil333a9bd2018-07-25 17:08:41 +053034import { appConstants } from '../../../constants/app-constants'
Skip Wonnell2c977e22018-03-01 08:30:15 -060035
36@Component({ selector: 'app-myvnfs', templateUrl: './myvnfs.component.html', styleUrls: ['./myvnfs.component.css'] })
Arundathi Patil897c4b72018-07-17 16:05:00 +053037export class MyvnfsComponent implements OnInit, OnDestroy {
Skip Wonnell2c977e22018-03-01 08:30:15 -060038 vnfData: Array<Object> = [];
39 sortOrder = false;
40 noData = true;
41 sortBy: string;
42 filter: Object = {};
43 noDataMsg: string;
44 vnfType: any;
45 vnfcType: any;
od7427b1ce3d42018-08-23 11:49:12 -040046 vnfcRequired: boolean = false;
47 errorMessage = '';
48 invalid = true;
Sandeep J170263d2018-07-16 17:02:46 +053049 options = {
Arundathi Patil897c4b72018-07-17 16:05:00 +053050 timeOut: 1000,
51 showProgressBar: true,
52 pauseOnHover: true,
53 clickToClose: true,
54 maxLength: 200
Sandeep J170263d2018-07-16 17:02:46 +053055 }
Arundathi Patil897c4b72018-07-17 16:05:00 +053056 subscription: Subscription;
Skip Wonnell2c977e22018-03-01 08:30:15 -060057
asgaraf56b682019-03-08 19:52:33 +053058 constructor (private paramShareService: ParamShareService, private ngProgress: NgProgress, private httpUtil: HttpUtilService, private router: Router, private activeROute: ActivatedRoute,
59 private mappingEditorService: MappingEditorService, private modalService: NgbModal) {
Skip Wonnell2c977e22018-03-01 08:30:15 -060060 }
61
62 ngOnInit() {
63
64 sessionStorage.setItem('updateParams', undefined);
65 this.mappingEditorService.latestAction = undefined;
66 const apiToken = localStorage['apiToken'];
67
68 const data = {
69 'input': {
70 'design-request': {
71 'request-id': apiToken,
72 'action': 'getDesigns',
73 'payload': '{"userID": "","filter":"reference"}'
74 }
75 }
76 };
77 const x = JSON.parse(data.input['design-request']['payload']);
78 x.userID = localStorage['userId'];
79 data.input['design-request']['payload'] = JSON.stringify(x);
80 // console.log("input to payload====", JSON.stringify(data));
81 this.getArtifacts(data);
82 this.clearCache();
83 }
84
Arundathi Patil897c4b72018-07-17 16:05:00 +053085 ngOnDestroy() {
86 if (this.subscription) { this.subscription.unsubscribe() };
87 }
88
Skip Wonnell2c977e22018-03-01 08:30:15 -060089 getArtifacts(data) {
od7427b1ce3d42018-08-23 11:49:12 -040090 let tempObj: any;
Skip Wonnell2c977e22018-03-01 08:30:15 -060091 this.ngProgress.start();
od7427b1ce3d42018-08-23 11:49:12 -040092 this.httpUtil.post({
Skip Wonnell2c977e22018-03-01 08:30:15 -060093 url: environment.getDesigns,
94 data: data
95 })
asgaraf56b682019-03-08 19:52:33 +053096 .subscribe(resp => {
od7427b1ce3d42018-08-23 11:49:12 -040097 if (resp.output.data.block !== undefined && resp.output.data.block !== null && resp.output.data.block.length !== 0) {
asgaraf56b682019-03-08 19:52:33 +053098 tempObj = JSON.parse(resp.output.data.block);
99 this.vnfData = tempObj.designInfo;
od7427b1ce3d42018-08-23 11:49:12 -0400100 }
asgaraf56b682019-03-08 19:52:33 +0530101 if (this.vnfData === undefined || this.vnfData === null || this.vnfData.length === 0) {
Skip Wonnell2c977e22018-03-01 08:30:15 -0600102 this.noData = true;
asgaraf56b682019-03-08 19:52:33 +0530103 // this.noDataMsg = resp.output.status.message;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600104 } else {
105 this.noData = false;
106 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600107 this.ngProgress.done();
od7427b1ce3d42018-08-23 11:49:12 -0400108 });
Arundathi Patil897c4b72018-07-17 16:05:00 +0530109
Skip Wonnell2c977e22018-03-01 08:30:15 -0600110 this.filter = ['vnf-type', 'vnfc-type', 'artifact-name'];
111 setTimeout(() => {
112 this.ngProgress.done();
113 }, 3500);
114 }
115
116
117
118 getData() {
119 }
120
asgaraf56b682019-03-08 19:52:33 +0530121 buildNewDesign(response) {
122
123 // this.modalService.open(content).result.then(res => {
124 // if(res=='yes'){
125 // sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType}));
126 // sessionStorage.setItem("vnfcSelectionFlag",''+this.vnfcRequired+'')
127 // } else{
128 // sessionStorage.setItem('vnfParams',"")
129 // }
130
131 // this.mappingEditorService.referenceNameObjects = undefined;
132 // this.mappingEditorService.identifier = '';
133 // //this.mappingEditorService.newObject = {};
134 // this.router.navigate([
135 // 'vnfs', 'design', 'references'
136 // ]);
137
138 // });
139
od7427b1ce3d42018-08-23 11:49:12 -0400140 if (response == 'yes') {
141 sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType }));
142 sessionStorage.setItem("vnfcSelectionFlag", '' + this.vnfcRequired + '')
143 } else {
144 sessionStorage.setItem('vnfParams', "")
145 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600146
od7427b1ce3d42018-08-23 11:49:12 -0400147 this.mappingEditorService.referenceNameObjects = undefined;
148 this.mappingEditorService.identifier = '';
149 //this.mappingEditorService.newObject = {};
150 this.router.navigate([
151 'vnfs', 'design', 'references'
152 ]);
153 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600154
od7427b1ce3d42018-08-23 11:49:12 -0400155 validateVnfName(name) {
156 if (!name.trim() || name.length < 1) {
157 this.errorMessage = '';
158 this.invalid = true;
159 } else if (name.startsWith(' ') || name.endsWith(' ')) {
160 this.errorMessage = 'Leading and trailing spaces are not allowed';
161 this.invalid = true;
162 } else if (name.includes(' ')) {
163 this.errorMessage = 'More than one space is not allowed in VNF Type';
164 this.invalid = true;
165 } else if (name.length > 150) {
166 this.errorMessage = 'VNF Type should be of minimum one character and maximum 150 character';
167 this.invalid = true;
168 } else {
169 this.invalid = false;
170 this.errorMessage = '';
171 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600172 }
173
174 navigateToReference(item) {
175 sessionStorage.setItem('updateParams', JSON.stringify(item));
176 this.mappingEditorService.referenceNameObjects = undefined;
od7427b1ce3d42018-08-23 11:49:12 -0400177 sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: item.vnfType, vnfcType: item.vnfcType }));
178 this.mappingEditorService.identifier = '';
179 if (this.mappingEditorService.newObject && this.mappingEditorService.newObject.vnfc != undefined) {
180 this.mappingEditorService.newObject.vnfc = '';
181 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600182 this
183 .router
184 .navigate(['../design/references'], {
185 relativeTo: this.activeROute,
186 queryParams: {
187 id: item.id
188 }
189 });
190 }
191
192 navigateToRefrenceUpdate() {
193
194 this
195 .router
196 .navigate(['../design/references/update'], {
197 relativeTo: this.activeROute,
198 queryParams: {
199 id: '10'
200 }
201 });
202 }
203
204 clearCache() {
205 // get the value and save the userid and persist it.
asgaraf56b682019-03-08 19:52:33 +0530206 sessionStorage.setItem("vnfcSelectionFlag", '' + this.vnfcRequired + '')
Skip Wonnell2c977e22018-03-01 08:30:15 -0600207 this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
208 localStorage['paramsContent'] = '{}';
209 this.mappingEditorService.setParamContent(undefined);
210 this.paramShareService.setSessionParamData(undefined);
211 const appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
212 const downloadData = {
213 reference: {},
214 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
215 pd: { pdData: '', pdFileName: '' }
216 };
217 this.mappingEditorService.changeNavAppData(appData);
218 this.mappingEditorService.changeNavDownloadData(downloadData);
219 }
asgaraf56b682019-03-08 19:52:33 +0530220 defineData(item) {
221 let artVnfc = item['artifact-name'].substring(this.lastIndexofEnd("AllAction_", item['artifact-name']), item['artifact-name'].lastIndexOf("_"))
222 if (item['vnf-type'] == artVnfc && item['vnfc-type'] == 'null') {
223
224 return item['vnfc-type']
225 } else {
226 return ""
227 }
228
229 }
230 lastIndexofEnd(str, originlStr) {
231 var io = originlStr.lastIndexOf(str);
232 return io == -1 ? -1 : io + str.length;
233 }
234
235
236}