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 History Of Operations Component
21 import { isNullOrUndefined } from 'util';
22 import { Component, Injector, OnInit } from '@angular/core';
23 import { ActivatedRoute } from '@angular/router';
24 import { Router } from '@angular/router';
25 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
26 import { TranslateService } from '@ngx-translate/core';
27 import { CONFIGCONSTANT, ERRORDATA } from 'CommonModel';
28 import { DataService } from 'DataService';
29 import { environment } from 'environment';
30 import * as HttpStatus from 'http-status-codes';
31 import { LocalDataSource } from 'ng2-smart-table';
32 import { NSDInstanceData } from 'NSInstanceModel';
33 import { RestService } from 'RestService';
34 import { Subscription } from 'rxjs';
35 import { SharedService } from 'SharedService';
36 import { ShowInfoComponent } from 'ShowInfoComponent';
40 * @Component takes HistoryOperationsComponent.html as template url
43 templateUrl: './HistoryOperationsComponent.html',
44 styleUrls: ['./HistoryOperationsComponent.scss']
46 /** Exporting a class @exports HistoryOperationsComponent */
47 export class HistoryOperationsComponent implements OnInit {
48 /** Injector to invoke other services @public */
49 public injector: Injector;
51 /** NS Instance array @public */
52 public nsAndnstInstanceData: object[] = [];
54 /** Datasource instance @public */
55 public dataSource: LocalDataSource = new LocalDataSource();
57 /** Instance component are stored in settings @public */
58 public settings: {} = {};
60 /** Contains objects for smart table title and filter settings @public */
61 public columnList: {} = {};
63 /** Variable handles the page name @public */
66 /** Variable handles the title name @public */
67 public titleName: string;
69 /** Check the loading results @public */
70 public isLoadingResults: boolean = true;
72 /** Give the message for the loading @public */
73 public message: string = 'PLEASEWAIT';
75 /** Class for empty and present data @public */
76 public checkDataClass: string;
78 /** History State init data @public */
79 public historyStateFirstStep: string = CONFIGCONSTANT.historyStateFirstStep;
81 /** History State running data @public */
82 public historyStateSecondStep: string = CONFIGCONSTANT.historyStateSecondStep;
84 /** History State failed data @public */
85 public historyStateThirdStep: string = CONFIGCONSTANT.historyStateThirdStep;
87 /** dataService to pass the data from one component to another @private */
88 private dataService: DataService;
90 /** Utilizes rest service for any CRUD operations @private */
91 private restService: RestService;
93 /** Contains all methods related to shared @private */
94 private sharedService: SharedService;
96 /** Holds teh instance of AuthService class of type AuthService @private */
97 private activatedRoute: ActivatedRoute;
99 /** Instance of the modal service @private */
100 private modalService: NgbModal;
102 /** variables contains paramsID @private */
103 private paramsID: string;
105 /** variables contains paramsID @private */
106 private paramsType: string;
108 /** variables conatins URL of the History operations @public */
109 private historyURL: string;
111 /** Contains tranlsate instance @private */
112 private translateService: TranslateService;
114 /** Instance of subscriptions @private */
115 private generateDataSub: Subscription;
117 /** Service holds the router information @private */
118 private router: Router;
120 constructor(injector: Injector) {
121 this.injector = injector;
122 this.restService = this.injector.get(RestService);
123 this.dataService = this.injector.get(DataService);
124 this.sharedService = this.injector.get(SharedService);
125 this.activatedRoute = this.injector.get(ActivatedRoute);
126 this.modalService = this.injector.get(NgbModal);
127 this.translateService = this.injector.get(TranslateService);
128 this.router = this.injector.get(Router);
131 /** Lifecyle Hooks the trigger before component is instantiate @public */
132 public ngOnInit(): void {
133 this.paramsID = this.activatedRoute.snapshot.paramMap.get('id');
134 this.paramsType = this.activatedRoute.snapshot.paramMap.get('type');
135 if (this.paramsType === 'ns') {
136 this.historyURL = environment.NSHISTORYOPERATIONS_URL + '/?nsInstanceId=' + this.paramsID;
137 this.page = 'ns-history-operation';
138 this.titleName = 'INSTANCEDETAILS';
139 } else if (this.paramsType === 'netslice') {
140 this.historyURL = environment.NSTHISTORYOPERATIONS_URL + '/?netsliceInstanceId=' + this.paramsID;
141 this.page = 'nst-history-operation';
142 this.titleName = 'INSTANCEDETAILS';
144 this.generateTableColumn();
145 this.generateTableSettings();
147 this.generateDataSub = this.sharedService.dataEvent.subscribe(() => { this.generateData(); });
150 /** Generate smart table row title and filters @public */
151 public generateTableSettings(): void {
153 columns: this.columnList,
155 add: false, edit: false, delete: false, position: 'right',
157 name: 'showInformation', title: '<i class="fas fa-info" title=" ' + this.translateService.instant('INFO') + ' "></i>'}]
159 attr: this.sharedService.tableClassConfig(),
160 pager: this.sharedService.paginationPagerConfig(),
161 noDataMessage: this.translateService.instant('NODATAMSG')
165 /** Generate smart table row title and filters @public */
166 public generateTableColumn(): void {
168 id: { title: this.translateService.instant('ID'), width: '30%' },
169 type: { title: this.translateService.instant('TYPE'), width: '20%' },
171 type: 'html', title: this.translateService.instant('OPERATIONSTATE'), width: '15%',
175 selectText: 'Select',
177 { value: this.historyStateFirstStep, title: this.historyStateFirstStep },
178 { value: this.historyStateSecondStep, title: this.historyStateSecondStep },
179 { value: this.historyStateThirdStep, title: this.historyStateThirdStep }
183 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
184 if (row.state === this.historyStateFirstStep) {
185 return `<span class="icon-label" title="${row.state}">
186 <i class="fas fa-clock text-warning"></i>
188 } else if (row.state === this.historyStateSecondStep) {
189 return `<span class="icon-label" title="${row.state}">
190 <i class="fas fa-check-circle text-success"></i>
192 } else if (row.state === this.historyStateThirdStep) {
193 return `<span class="icon-label" title="${row.state}">
194 <i class="fas fa-times-circle text-danger"></i>
197 return `<span>${row.state}</span>`;
201 startTime: { title: this.translateService.instant('STARTTIME'), width: '15%' },
202 statusEnteredTime: { title: this.translateService.instant('STATUSENTEREDTIME'), width: '15%' }
206 /** smart table listing manipulation @public */
207 public onUserRowSelect(event: MessageEvent): void {
208 this.dataService.changeMessage(event.data);
210 /** smart table listing manipulation @public */
211 public onChange(perPageValue: number): void {
212 this.dataSource.setPaging(1, perPageValue, true);
214 /** show information methods modal with ns history info */
215 public showInformation(event: MessageEvent): void {
216 // eslint-disable-next-line security/detect-non-literal-fs-filename
217 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
220 titleName: this.titleName
225 * Lifecyle hook which get trigger on component destruction
227 public ngOnDestroy(): void {
228 this.generateDataSub.unsubscribe();
231 /** generateData initiate the ns-instance list @private */
232 private generateData(): void {
233 this.isLoadingResults = true;
234 this.restService.getResource(this.historyURL).subscribe((nsdInstancesData: {}[]): void => {
235 this.nsAndnstInstanceData = [];
236 nsdInstancesData.forEach((nsdAndnstInstanceData: NSDInstanceData): void => {
237 let scaleType: string = '';
238 if (!isNullOrUndefined(nsdAndnstInstanceData.operationParams.scaleVnfData)) {
239 scaleType = ' (' + nsdAndnstInstanceData.operationParams.scaleVnfData.scaleVnfType + ')';
241 const nsAndnstDataObj: {} = {
242 id: nsdAndnstInstanceData.id,
243 type: nsdAndnstInstanceData.lcmOperationType + scaleType,
244 state: nsdAndnstInstanceData.operationState,
245 startTime: this.sharedService.convertEpochTime(nsdAndnstInstanceData.startTime),
246 statusEnteredTime: this.sharedService.convertEpochTime(nsdAndnstInstanceData.statusEnteredTime)
248 this.nsAndnstInstanceData.push(nsAndnstDataObj);
251 if (this.nsAndnstInstanceData.length > 0) {
252 this.checkDataClass = 'dataTables_present';
254 this.checkDataClass = 'dataTables_empty';
256 this.dataSource.load(this.nsAndnstInstanceData).then((data: {}): void => {
258 }).catch((): void => {
259 // Catch Navigation Error
261 this.isLoadingResults = false;
262 }, (error: ERRORDATA): void => {
263 this.isLoadingResults = false;
264 if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED) {
265 this.router.navigateByUrl('404', { skipLocationChange: true }).catch((): void => {
266 // Catch Navigation Error
269 this.restService.handleError(error, 'get');