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; |
Sandeep J | 170263d | 2018-07-16 17:02:46 +0530 | [diff] [blame] | 46 | options = { |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 47 | timeOut: 1000, |
| 48 | showProgressBar: true, |
| 49 | pauseOnHover: true, |
| 50 | clickToClose: true, |
| 51 | maxLength: 200 |
Sandeep J | 170263d | 2018-07-16 17:02:46 +0530 | [diff] [blame] | 52 | } |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 53 | subscription: Subscription; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 54 | |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 55 | constructor(private paramShareService: ParamShareService, private ngProgress: NgProgress, private httpUtil: HttpUtilService, private router: Router, private activeROute: ActivatedRoute, |
| 56 | private mappingEditorService: MappingEditorService, private modalService: NgbModal, private nService: NotificationsService) { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | ngOnInit() { |
| 60 | |
| 61 | sessionStorage.setItem('updateParams', undefined); |
| 62 | this.mappingEditorService.latestAction = undefined; |
| 63 | const apiToken = localStorage['apiToken']; |
| 64 | |
| 65 | const data = { |
| 66 | 'input': { |
| 67 | 'design-request': { |
| 68 | 'request-id': apiToken, |
| 69 | 'action': 'getDesigns', |
| 70 | 'payload': '{"userID": "","filter":"reference"}' |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | const x = JSON.parse(data.input['design-request']['payload']); |
| 75 | x.userID = localStorage['userId']; |
| 76 | data.input['design-request']['payload'] = JSON.stringify(x); |
| 77 | // console.log("input to payload====", JSON.stringify(data)); |
| 78 | this.getArtifacts(data); |
| 79 | this.clearCache(); |
| 80 | } |
| 81 | |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 82 | ngOnDestroy() { |
| 83 | if (this.subscription) { this.subscription.unsubscribe() }; |
| 84 | } |
| 85 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 86 | getArtifacts(data) { |
| 87 | this.ngProgress.start(); |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 88 | this.subscription = this.httpUtil.post({ |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 89 | url: environment.getDesigns, |
| 90 | data: data |
| 91 | }) |
| 92 | .subscribe(resp => { |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 93 | console.log("resp:", resp); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 94 | const tempObj = JSON.parse(resp.output.data.block); |
| 95 | this.vnfData = tempObj.designInfo; |
| 96 | if (this.vnfData == undefined || this.vnfData == null || this.vnfData.length == 0) { |
| 97 | this.noData = true; |
| 98 | |
| 99 | this.noDataMsg = resp.output.data.status.message; |
| 100 | } else { |
| 101 | this.noData = false; |
| 102 | } |
| 103 | console.log(this.noData); |
| 104 | this.ngProgress.done(); |
Sandeep J | 170263d | 2018-07-16 17:02:46 +0530 | [diff] [blame] | 105 | } |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 106 | , |
| 107 | error => { |
| 108 | |
Arundathi Patil | 333a9bd | 2018-07-25 17:08:41 +0530 | [diff] [blame^] | 109 | this.nService.error(appConstants.errors.error, appConstants.errors.connectionError) |
Arundathi Patil | 897c4b7 | 2018-07-17 16:05:00 +0530 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | ); |
| 113 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 114 | this.filter = ['vnf-type', 'vnfc-type', 'artifact-name']; |
| 115 | setTimeout(() => { |
| 116 | this.ngProgress.done(); |
| 117 | }, 3500); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | |
| 122 | getData() { |
| 123 | } |
| 124 | |
| 125 | buildNewDesign(content) { |
| 126 | |
| 127 | this.modalService.open(content).result.then(res => { |
| 128 | this.mappingEditorService.referenceNameObjects = undefined; |
| 129 | sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: this.vnfType, vnfcType: this.vnfcType })); |
| 130 | this |
| 131 | .router |
| 132 | .navigate([ |
| 133 | 'vnfs', 'design', 'references' |
| 134 | ]); |
| 135 | }); |
| 136 | |
| 137 | |
| 138 | } |
| 139 | |
| 140 | navigateToReference(item) { |
| 141 | sessionStorage.setItem('updateParams', JSON.stringify(item)); |
| 142 | this.mappingEditorService.referenceNameObjects = undefined; |
| 143 | |
| 144 | this |
| 145 | .router |
| 146 | .navigate(['../design/references'], { |
| 147 | relativeTo: this.activeROute, |
| 148 | queryParams: { |
| 149 | id: item.id |
| 150 | } |
| 151 | }); |
| 152 | } |
| 153 | |
| 154 | navigateToRefrenceUpdate() { |
| 155 | |
| 156 | this |
| 157 | .router |
| 158 | .navigate(['../design/references/update'], { |
| 159 | relativeTo: this.activeROute, |
| 160 | queryParams: { |
| 161 | id: '10' |
| 162 | } |
| 163 | }); |
| 164 | } |
| 165 | |
| 166 | clearCache() { |
| 167 | // get the value and save the userid and persist it. |
| 168 | |
| 169 | this.mappingEditorService.setTemplateMappingDataFromStore(undefined); |
| 170 | localStorage['paramsContent'] = '{}'; |
| 171 | this.mappingEditorService.setParamContent(undefined); |
| 172 | this.paramShareService.setSessionParamData(undefined); |
| 173 | const appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} }; |
| 174 | const downloadData = { |
| 175 | reference: {}, |
| 176 | template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' }, |
| 177 | pd: { pdData: '', pdFileName: '' } |
| 178 | }; |
| 179 | this.mappingEditorService.changeNavAppData(appData); |
| 180 | this.mappingEditorService.changeNavDownloadData(downloadData); |
| 181 | } |
| 182 | |
| 183 | |
| 184 | } |