2 Copyright 2020 TATA ELXSI
4 Licensed under the Apache License, Version 2.0 (the 'License');
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
19 * @file VNF-packagesAction Component
21 import { HttpHeaders } from '@angular/common/http';
22 import { ChangeDetectorRef, Component, Injector } from '@angular/core';
23 import { Router } from '@angular/router';
24 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
25 import { TranslateService } from '@ngx-translate/core';
26 import { NotifierService } from 'angular-notifier';
27 import { ClonePackageComponent } from 'ClonePackage';
28 import { ERRORDATA, GETAPIURLHEADER, MODALCLOSERESPONSEDATA } from 'CommonModel';
29 import { DeleteComponent } from 'DeleteComponent';
30 import { environment } from 'environment';
31 import { RestService } from 'RestService';
32 import { SharedService } from 'SharedService';
33 import { ShowContentComponent } from 'ShowContent';
34 import { VNFData } from 'VNFDModel';
38 * @Component takes VNFPackagesActionComponent.html as template url
41 templateUrl: './VNFPackagesActionComponent.html',
42 styleUrls: ['./VNFPackagesActionComponent.scss']
44 /** Exporting a class @exports VNFPackagesActionComponent */
45 export class VNFPackagesActionComponent {
46 /** To get the value from the vnfpackage via valuePrepareFunction default Property of ng-smarttable @public */
47 public value: VNFData;
49 /** To inject services @public */
50 public injector: Injector;
52 /** Check the loading results for loader status @public */
53 public isLoadingDownloadResult: boolean = false;
55 /** Give the message for the loading @public */
56 public message: string = 'PLEASEWAIT';
58 /** Instance of the rest service @private */
59 private restService: RestService;
61 /** Holds teh instance of AuthService class of type AuthService @private */
62 private router: Router;
64 /** Instance of the modal service @private */
65 private modalService: NgbModal;
67 /** Variables holds NS ID @private */
68 private vnfID: string;
70 /** Variables holds NS name @private */
71 private vnfName: string;
73 /** Controls the header form @private */
74 private headers: HttpHeaders;
76 /** Contains all methods related to shared @private */
77 private sharedService: SharedService;
79 /** Notifier service to popup notification @private */
80 private notifierService: NotifierService;
82 /** Contains tranlsate instance @private */
83 private translateService: TranslateService;
85 /** Detect changes for the User Input */
86 private cd: ChangeDetectorRef;
88 /** Set timeout @private */
89 private timeOut: number = 1000;
91 constructor(injector: Injector) {
92 this.injector = injector;
93 this.restService = this.injector.get(RestService);
94 this.sharedService = this.injector.get(SharedService);
95 this.modalService = this.injector.get(NgbModal);
96 this.router = this.injector.get(Router);
97 this.notifierService = this.injector.get(NotifierService);
98 this.translateService = this.injector.get(TranslateService);
99 this.cd = this.injector.get(ChangeDetectorRef);
103 * Lifecyle Hooks the trigger before component is instantiate
105 public ngOnInit(): void {
106 this.headers = new HttpHeaders({
107 Accept: 'application/zip, application/json',
108 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
110 this.vnfID = this.value.identifier;
111 this.vnfName = this.value.shortName;
114 /** Delete VNF packages @public */
115 public deleteVNFPackage(): void {
116 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
117 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
119 this.sharedService.callData();
124 /** Set instance for NSD Edit @public */
125 public vnfdEdit(): void {
126 this.router.navigate(['/packages/vnf/edit/', this.vnfID]).then((nav: {}) => {
127 // Navigated Successfully
128 }, (error: Error) => {
129 // Navigation Error Handler
133 /** list out all the file content of a descriptors @public */
134 public showContent(): void {
135 this.modalService.open(ShowContentComponent, { backdrop: 'static' }).componentInstance.params = { id: this.vnfID, page: 'vnfd' };
138 /** Download VNF Package @public */
139 public downloadVNFPackage(): void {
140 this.isLoadingDownloadResult = true;
141 const httpOptions: GETAPIURLHEADER = {
142 headers: this.headers,
145 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + this.vnfID + '/package_content', httpOptions)
146 .subscribe((response: Blob) => {
147 this.isLoadingDownloadResult = false;
148 this.changeDetactionforDownload();
149 const binaryData: Blob[] = [];
150 binaryData.push(response);
151 this.sharedService.downloadFiles(this.vnfName, binaryData, response.type);
152 }, (error: ERRORDATA) => {
153 this.isLoadingDownloadResult = false;
154 this.notifierService.notify('error', this.translateService.instant('ERROR'));
155 this.changeDetactionforDownload();
156 if (typeof error.error === 'object') {
157 error.error.text().then((data: string): void => {
158 error.error = JSON.parse(data);
159 this.restService.handleError(error, 'getBlob');
165 /** Compose VNF Packages @public */
166 public composeVNFPackages(): void {
167 this.router.navigate(['/packages/vnf/compose/', this.vnfID]).catch();
170 /** Change the detaction @public */
171 public changeDetactionforDownload(): void {
173 this.cd.detectChanges();
177 /** Clone NS Packages @public */
178 public cloneVNFPackage(): void {
179 const cloneModal: NgbModalRef = this.modalService.open(ClonePackageComponent, { backdrop: 'static' });
180 cloneModal.componentInstance.params = { id: this.vnfID, page: 'vnfd', name: this.vnfName };
181 cloneModal.result.then((result: MODALCLOSERESPONSEDATA) => {
183 this.sharedService.callData();