Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 1 | /* |
| 2 | ============LICENSE_START========================================== |
| 3 | =================================================================== |
| 4 | Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. |
| 5 | =================================================================== |
Sandeep J | 170263d | 2018-07-16 17:02:46 +0530 | [diff] [blame] | 6 | Copyright (C) 2018 IBM. |
| 7 | =================================================================== |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 8 | Unless otherwise specified, all software contained herein is licensed |
| 9 | under the Apache License, Version 2.0 (the License); |
| 10 | you may not use this software except in compliance with the License. |
| 11 | You may obtain a copy of the License at |
| 12 | |
| 13 | http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | |
| 15 | Unless required by applicable law or agreed to in writing, software |
| 16 | distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | See the License for the specific language governing permissions and |
| 19 | limitations under the License. |
| 20 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 21 | ============LICENSE_END============================================ |
| 22 | */ |
| 23 | |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 24 | import { Component, OnInit, OnDestroy } from '@angular/core'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 25 | import { ActivatedRoute, Router } from '@angular/router'; |
| 26 | import { HttpUtilService } from '../../shared/services/httpUtil/http-util.service'; |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 27 | import { Subscription } from 'rxjs/Subscription'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 28 | import { MappingEditorService } from '../../shared/services/mapping-editor.service'; |
| 29 | import { ParamShareService } from '../../shared/services/paramShare.service'; |
| 30 | import { environment } from '../../../environments/environment'; |
| 31 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; |
| 32 | import { NgProgress } from 'ngx-progressbar'; |
Sandeep J | 170263d | 2018-07-16 17:02:46 +0530 | [diff] [blame] | 33 | import { NotificationsService } from 'angular2-notifications'; |
Arundathi Patil | 333a9bd | 2018-07-25 17:08:41 +0530 | [diff] [blame] | 34 | import { appConstants } from '../../../constants/app-constants' |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 35 | |
| 36 | @Component({ selector: 'app-myvnfs', templateUrl: './myvnfs.component.html', styleUrls: ['./myvnfs.component.css'] }) |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 37 | export class MyvnfsComponent implements OnInit, OnDestroy { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 38 | vnfData: Array<Object> = []; |
| 39 | sortOrder = false; |
| 40 | noData = true; |
| 41 | sortBy: string; |
| 42 | filter: Object = {}; |
| 43 | noDataMsg: string; |
| 44 | vnfType: any; |
| 45 | vnfcType: any; |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 46 | vnfcRequired: boolean = false; |
| 47 | errorMessage = ''; |
| 48 | invalid = true; |
Sandeep J | 170263d | 2018-07-16 17:02:46 +0530 | [diff] [blame] | 49 | options = { |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 50 | timeOut: 1000, |
| 51 | showProgressBar: true, |
| 52 | pauseOnHover: true, |
| 53 | clickToClose: true, |
| 54 | maxLength: 200 |
Sandeep J | 170263d | 2018-07-16 17:02:46 +0530 | [diff] [blame] | 55 | } |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 56 | subscription: Subscription; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 57 | |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 58 | 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 Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 60 | } |
| 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 Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 85 | ngOnDestroy() { |
| 86 | if (this.subscription) { this.subscription.unsubscribe() }; |
| 87 | } |
| 88 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 89 | getArtifacts(data) { |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 90 | let tempObj: any; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 91 | this.ngProgress.start(); |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 92 | //this.subscription = this.httpUtil.post({ |
| 93 | this.httpUtil.post({ |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 94 | url: environment.getDesigns, |
| 95 | data: data |
| 96 | }) |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 97 | .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 Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 103 | if (this.vnfData == undefined || this.vnfData == null || this.vnfData.length == 0) { |
| 104 | this.noData = true; |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 105 | // this.noDataMsg = resp.output.data.status.message; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 106 | } else { |
| 107 | this.noData = false; |
| 108 | } |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 109 | console.log("getArtifacts: noData:"+this.noData); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 110 | this.ngProgress.done(); |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 111 | }, |
| 112 | error => { |
| 113 | this.nService.error(appConstants.errors.error, appConstants.errors.connectionError) |
| 114 | }); |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 115 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 116 | this.filter = ['vnf-type', 'vnfc-type', 'artifact-name']; |
| 117 | setTimeout(() => { |
| 118 | this.ngProgress.done(); |
| 119 | }, 3500); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | |
| 124 | getData() { |
| 125 | } |
| 126 | |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 127 | 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 Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 141 | |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 142 | this.mappingEditorService.referenceNameObjects = undefined; |
| 143 | this.mappingEditorService.identifier = ''; |
| 144 | //this.mappingEditorService.newObject = {}; |
| 145 | this.router.navigate([ |
| 146 | 'vnfs', 'design', 'references' |
| 147 | ]); |
| 148 | } |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 149 | |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 150 | 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 Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | navigateToReference(item) { |
| 170 | sessionStorage.setItem('updateParams', JSON.stringify(item)); |
| 171 | this.mappingEditorService.referenceNameObjects = undefined; |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 172 | 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 Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 177 | 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. |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 201 | sessionStorage.setItem("vnfcSelectionFlag", '' + this.vnfcRequired + ''); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 202 | 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 | } |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 215 | } |