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 NS 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 { InstantiateNsComponent } from 'InstantiateNs';
32 import { NSData } from 'NSDModel';
33 import { RestService } from 'RestService';
34 import { SharedService } from 'SharedService';
35 import { ShowContentComponent } from 'ShowContent';
39 * @Component takes NsPackagesActionComponent.html as template url
42 selector: 'app-ns-packages-action',
43 templateUrl: './NsPackagesActionComponent.html',
44 styleUrls: ['./NsPackagesActionComponent.scss']
47 /** Exporting a class @exports NsPackagesActionComponent */
48 export class NsPackagesActionComponent {
49 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
52 /** To inject services @public */
53 public injector: Injector;
55 /** Check the loading results for loader status @public */
56 public isLoadingDownloadResult: boolean = false;
58 /** Give the message for the loading @public */
59 public message: string = 'PLEASEWAIT';
61 /** Instance of the rest service @private */
62 private restService: RestService;
64 /** Holds teh instance of AuthService class of type AuthService @private */
65 private router: Router;
67 /** Instance of the modal service @private */
68 private modalService: NgbModal;
70 /** Variables holds NS ID @private */
71 private nsdID: string;
73 /** Variables holds NS name @private */
74 private nsdName: string;
76 /** Controls the header form @private */
77 private headers: HttpHeaders;
79 /** Contains all methods related to shared @private */
80 private sharedService: SharedService;
82 /** Notifier service to popup notification @private */
83 private notifierService: NotifierService;
85 /** Contains tranlsate instance @private */
86 private translateService: TranslateService;
88 /** Detect changes for the User Input */
89 private cd: ChangeDetectorRef;
91 /** Set timeout @private */
92 private timeOut: number = 1000;
94 constructor(injector: Injector) {
95 this.injector = injector;
96 this.restService = this.injector.get(RestService);
97 this.sharedService = this.injector.get(SharedService);
98 this.modalService = this.injector.get(NgbModal);
99 this.router = this.injector.get(Router);
100 this.notifierService = this.injector.get(NotifierService);
101 this.translateService = this.injector.get(TranslateService);
102 this.cd = this.injector.get(ChangeDetectorRef);
105 /** Lifecyle Hooks the trigger before component is instantiate @public */
106 public ngOnInit(): void {
107 this.headers = new HttpHeaders({
108 Accept: 'application/zip, application/json',
109 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
111 this.nsdID = this.value.identifier;
112 this.nsdName = this.value.shortName;
115 /** Instantiate NS using modalservice @public */
116 public instantiateNS(): void {
117 this.modalService.open(InstantiateNsComponent, { backdrop: 'static' });
120 /** Delete NS Package @public */
121 public deleteNSPackage(): void {
122 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
123 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
125 this.sharedService.callData();
130 /** Set instance for NSD Edit @public */
131 public nsdEdit(): void {
132 this.router.navigate(['/packages/ns/edit/', this.nsdID]).catch(() => {
133 // Catch Navigation Error
137 /** list out all the file content of a descriptors @public */
138 public showContent(): void {
139 this.modalService.open(ShowContentComponent, { backdrop: 'static' }).componentInstance.params = { id: this.nsdID, page: 'nsd' };
142 /** Download NS Package @public */
143 public downloadNSPackage(): void {
144 this.isLoadingDownloadResult = true;
145 const httpOptions: GETAPIURLHEADER = {
146 headers: this.headers,
149 this.restService.getResource(environment.NSDESCRIPTORS_URL + '/' + this.nsdID + '/nsd_content', httpOptions)
150 .subscribe((response: Blob) => {
151 const binaryData: Blob[] = [];
152 binaryData.push(response);
153 this.sharedService.downloadFiles(this.nsdName, binaryData, response.type);
154 this.isLoadingDownloadResult = false;
155 this.changeDetactionforDownload();
156 }, (error: ERRORDATA) => {
157 this.isLoadingDownloadResult = false;
158 this.notifierService.notify('error', this.translateService.instant('ERROR'));
159 this.changeDetactionforDownload();
160 if (typeof error.error === 'object') {
161 error.error.text().then((data: string): void => {
162 error.error = JSON.parse(data);
163 this.restService.handleError(error, 'getBlob');
169 /** Compose NS Packages @public */
170 public composeNSPackages(): void {
171 this.router.navigate(['/packages/ns/compose/', this.nsdID]).catch(() => {
172 // Catch Navigation Error
176 /** Change the detaction @public */
177 public changeDetactionforDownload(): void {
179 this.cd.detectChanges();
183 /** Clone NS Packages @public */
184 public cloneNSPackage(): void {
185 const cloneModal: NgbModalRef = this.modalService.open(ClonePackageComponent, { backdrop: 'static' });
186 cloneModal.componentInstance.params = { id: this.nsdID, page: 'nsd', name: this.nsdName };
187 cloneModal.result.then((result: MODALCLOSERESPONSEDATA) => {
189 this.sharedService.callData();