blob: a12470547f9babb54dba1ed8eb7806a75ad7070e [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
Arundathi Patil897c4b72018-07-17 16:05:00 +053058 constructor(private paramShareService: ParamShareService, private ngProgress: NgProgress, private httpUtil: HttpUtilService, private router: Router, private activeROute: ActivatedRoute,
59 private mappingEditorService: MappingEditorService, private modalService: NgbModal, private nService: NotificationsService) {
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.subscription = this.httpUtil.post({
93 this.httpUtil.post({
Skip Wonnell2c977e22018-03-01 08:30:15 -060094 url: environment.getDesigns,
95 data: data
96 })
od7427b1ce3d42018-08-23 11:49:12 -040097 .subscribe( resp => {
98 if (resp.output.data.block !== undefined && resp.output.data.block !== null && resp.output.data.block.length !== 0) {
99 console.log("getArtifacts: resp:", resp.output.data.block);
100 tempObj = JSON.parse(resp.output.data.block);
101 this.vnfData = tempObj.designInfo;
102 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600103 if (this.vnfData == undefined || this.vnfData == null || this.vnfData.length == 0) {
104 this.noData = true;
od7427b1ce3d42018-08-23 11:49:12 -0400105 // this.noDataMsg = resp.output.data.status.message;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600106 } else {
107 this.noData = false;
108 }
od7427b1ce3d42018-08-23 11:49:12 -0400109 console.log("getArtifacts: noData:"+this.noData);
Skip Wonnell2c977e22018-03-01 08:30:15 -0600110 this.ngProgress.done();
od7427b1ce3d42018-08-23 11:49:12 -0400111 },
112 error => {
113 this.nService.error(appConstants.errors.error, appConstants.errors.connectionError)
114 });
Arundathi Patil897c4b72018-07-17 16:05:00 +0530115
Skip Wonnell2c977e22018-03-01 08:30:15 -0600116 this.filter = ['vnf-type', 'vnfc-type', 'artifact-name'];
117 setTimeout(() => {
118 this.ngProgress.done();
119 }, 3500);
120 }
121
122
123
124 getData() {
125 }
126
od7427b1ce3d42018-08-23 11:49:12 -0400127 buildNewDesign( response) {
128 // this.modalService.open(content).result.then(res => {
129 // this.mappingEditorService.referenceNameObjects = undefined;
130 // sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType, vnfcType: this.vnfcType }));
131 // this.router.navigate([
132 // 'vnfs', 'design', 'references'
133 // ]);
134 // });
135 if (response == 'yes') {
136 sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType }));
137 sessionStorage.setItem("vnfcSelectionFlag", '' + this.vnfcRequired + '')
138 } else {
139 sessionStorage.setItem('vnfParams', "")
140 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600141
od7427b1ce3d42018-08-23 11:49:12 -0400142 this.mappingEditorService.referenceNameObjects = undefined;
143 this.mappingEditorService.identifier = '';
144 //this.mappingEditorService.newObject = {};
145 this.router.navigate([
146 'vnfs', 'design', 'references'
147 ]);
148 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600149
od7427b1ce3d42018-08-23 11:49:12 -0400150 validateVnfName(name) {
151 if (!name.trim() || name.length < 1) {
152 this.errorMessage = '';
153 this.invalid = true;
154 } else if (name.startsWith(' ') || name.endsWith(' ')) {
155 this.errorMessage = 'Leading and trailing spaces are not allowed';
156 this.invalid = true;
157 } else if (name.includes(' ')) {
158 this.errorMessage = 'More than one space is not allowed in VNF Type';
159 this.invalid = true;
160 } else if (name.length > 150) {
161 this.errorMessage = 'VNF Type should be of minimum one character and maximum 150 character';
162 this.invalid = true;
163 } else {
164 this.invalid = false;
165 this.errorMessage = '';
166 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600167 }
168
169 navigateToReference(item) {
170 sessionStorage.setItem('updateParams', JSON.stringify(item));
171 this.mappingEditorService.referenceNameObjects = undefined;
od7427b1ce3d42018-08-23 11:49:12 -0400172 sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: item.vnfType, vnfcType: item.vnfcType }));
173 this.mappingEditorService.identifier = '';
174 if (this.mappingEditorService.newObject && this.mappingEditorService.newObject.vnfc != undefined) {
175 this.mappingEditorService.newObject.vnfc = '';
176 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600177 this
178 .router
179 .navigate(['../design/references'], {
180 relativeTo: this.activeROute,
181 queryParams: {
182 id: item.id
183 }
184 });
185 }
186
187 navigateToRefrenceUpdate() {
188
189 this
190 .router
191 .navigate(['../design/references/update'], {
192 relativeTo: this.activeROute,
193 queryParams: {
194 id: '10'
195 }
196 });
197 }
198
199 clearCache() {
200 // get the value and save the userid and persist it.
od7427b1ce3d42018-08-23 11:49:12 -0400201 sessionStorage.setItem("vnfcSelectionFlag", '' + this.vnfcRequired + '');
Skip Wonnell2c977e22018-03-01 08:30:15 -0600202 this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
203 localStorage['paramsContent'] = '{}';
204 this.mappingEditorService.setParamContent(undefined);
205 this.paramShareService.setSessionParamData(undefined);
206 const appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
207 const downloadData = {
208 reference: {},
209 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
210 pd: { pdData: '', pdFileName: '' }
211 };
212 this.mappingEditorService.changeNavAppData(appData);
213 this.mappingEditorService.changeNavDownloadData(downloadData);
214 }
od7427b1ce3d42018-08-23 11:49:12 -0400215}