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 { Component, Injector, OnInit } from '@angular/core';
22 import { ActivatedRoute } from '@angular/router';
23 import { Router } from '@angular/router';
24 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
25 import { TranslateService } from '@ngx-translate/core';
26 import { CONFIGCONSTANT, ERRORDATA } from 'CommonModel';
27 import { DataService } from 'DataService';
28 import { environment } from 'environment';
29 import * as HttpStatus from 'http-status-codes';
30 import { LocalDataSource } from 'ng2-smart-table';
31 import { NSDInstanceData } from 'NSInstanceModel';
32 import { RestService } from 'RestService';
33 import { Subscription } from 'rxjs';
34 import { SharedService } from 'SharedService';
35 import { ShowInfoComponent } from 'ShowInfoComponent';
36 import { isNullOrUndefined } from 'util';
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 // tslint:disable-next-line:no-backbone-get-set-outside-model
134 this.paramsID = this.activatedRoute.snapshot.paramMap.get('id');
135 // tslint:disable-next-line:no-backbone-get-set-outside-model
136 this.paramsType = this.activatedRoute.snapshot.paramMap.get('type');
137 if (this.paramsType === 'ns') {
138 this.historyURL = environment.NSHISTORYOPERATIONS_URL + '/?nsInstanceId=' + this.paramsID;
139 this.page = 'ns-history-operation';
140 this.titleName = 'INSTANCEDETAILS';
141 } else if (this.paramsType === 'netslice') {
142 this.historyURL = environment.NSTHISTORYOPERATIONS_URL + '/?netsliceInstanceId=' + this.paramsID;
143 this.page = 'nst-history-operation';
144 this.titleName = 'INSTANCEDETAILS';
146 this.generateTableColumn();
147 this.generateTableSettings();
149 this.generateDataSub = this.sharedService.dataEvent.subscribe(() => { this.generateData(); });
152 /** Generate smart table row title and filters @public */
153 public generateTableSettings(): void {
155 columns: this.columnList,
157 add: false, edit: false, delete: false, position: 'right',
159 name: 'showInformation', title: '<i class="fas fa-info" title=" ' + this.translateService.instant('INFO') + ' "></i>'}]
161 attr: this.sharedService.tableClassConfig(),
162 pager: this.sharedService.paginationPagerConfig(),
163 noDataMessage: this.translateService.instant('NODATAMSG')
167 /** Generate smart table row title and filters @public */
168 public generateTableColumn(): void {
170 id: { title: this.translateService.instant('ID'), width: '30%' },
171 type: { title: this.translateService.instant('TYPE'), width: '20%' },
173 type: 'html', title: this.translateService.instant('OPERATIONSTATE'), width: '15%',
177 selectText: 'Select',
179 { value: this.historyStateFirstStep, title: this.historyStateFirstStep },
180 { value: this.historyStateSecondStep, title: this.historyStateSecondStep },
181 { value: this.historyStateThirdStep, title: this.historyStateThirdStep }
185 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
186 if (row.state === this.historyStateFirstStep) {
187 return `<span class="icon-label" title="${row.state}">
188 <i class="fas fa-clock text-warning"></i>
190 } else if (row.state === this.historyStateSecondStep) {
191 return `<span class="icon-label" title="${row.state}">
192 <i class="fas fa-check-circle text-success"></i>
194 } else if (row.state === this.historyStateThirdStep) {
195 return `<span class="icon-label" title="${row.state}">
196 <i class="fas fa-times-circle text-danger"></i>
199 return `<span>${row.state}</span>`;
203 startTime: { title: this.translateService.instant('STARTTIME'), width: '15%' },
204 statusEnteredTime: { title: this.translateService.instant('STATUSENTEREDTIME'), width: '15%' }
208 /** smart table listing manipulation @public */
209 public onUserRowSelect(event: MessageEvent): void {
210 this.dataService.changeMessage(event.data);
212 /** smart table listing manipulation @public */
213 public onChange(perPageValue: number): void {
214 this.dataSource.setPaging(1, perPageValue, true);
216 /** show information methods modal with ns history info */
217 public showInformation(event: MessageEvent): void {
218 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
221 titleName: this.titleName
226 * Lifecyle hook which get trigger on component destruction
228 public ngOnDestroy(): void {
229 this.generateDataSub.unsubscribe();
232 /** generateData initiate the ns-instance list @private */
233 private generateData(): void {
234 this.isLoadingResults = true;
235 this.restService.getResource(this.historyURL).subscribe((nsdInstancesData: {}[]): void => {
236 this.nsAndnstInstanceData = [];
237 nsdInstancesData.forEach((nsdAndnstInstanceData: NSDInstanceData): void => {
238 let scaleType: string = '';
239 if (!isNullOrUndefined(nsdAndnstInstanceData.operationParams.scaleVnfData)) {
240 scaleType = ' (' + nsdAndnstInstanceData.operationParams.scaleVnfData.scaleVnfType + ')';
242 const nsAndnstDataObj: {} = {
243 id: nsdAndnstInstanceData.id,
244 type: nsdAndnstInstanceData.lcmOperationType + scaleType,
245 state: nsdAndnstInstanceData.operationState,
246 startTime: this.sharedService.convertEpochTime(nsdAndnstInstanceData.startTime),
247 statusEnteredTime: this.sharedService.convertEpochTime(nsdAndnstInstanceData.statusEnteredTime)
249 this.nsAndnstInstanceData.push(nsAndnstDataObj);
252 if (this.nsAndnstInstanceData.length > 0) {
253 this.checkDataClass = 'dataTables_present';
255 this.checkDataClass = 'dataTables_empty';
257 this.dataSource.load(this.nsAndnstInstanceData).then((data: {}): void => {
260 this.isLoadingResults = false;
261 }, (error: ERRORDATA): void => {
262 this.isLoadingResults = false;
263 if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED) {
264 this.router.navigateByUrl('404', { skipLocationChange: true }).catch();
266 this.restService.handleError(error, 'get');