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';
39 * @Component takes HistoryOperationsComponent.html as template url
42 templateUrl: './HistoryOperationsComponent.html',
43 styleUrls: ['./HistoryOperationsComponent.scss']
45 /** Exporting a class @exports HistoryOperationsComponent */
46 export class HistoryOperationsComponent implements OnInit {
47 /** Injector to invoke other services @public */
48 public injector: Injector;
50 /** NS Instance array @public */
51 public nsAndnstInstanceData: object[] = [];
53 /** Datasource instance @public */
54 public dataSource: LocalDataSource = new LocalDataSource();
56 /** Instance component are stored in settings @public */
57 public settings: {} = {};
59 /** Contains objects for smart table title and filter settings @public */
60 public columnList: {} = {};
62 /** Variable handles the page name @public */
65 /** Variable handles the title name @public */
66 public titleName: string;
68 /** Check the loading results @public */
69 public isLoadingResults: boolean = true;
71 /** Give the message for the loading @public */
72 public message: string = 'PLEASEWAIT';
74 /** Class for empty and present data @public */
75 public checkDataClass: string;
77 /** History State init data @public */
78 public historyStateFirstStep: string = CONFIGCONSTANT.historyStateFirstStep;
80 /** History State running data @public */
81 public historyStateSecondStep: string = CONFIGCONSTANT.historyStateSecondStep;
83 /** History State failed data @public */
84 public historyStateThirdStep: string = CONFIGCONSTANT.historyStateThirdStep;
86 /** dataService to pass the data from one component to another @private */
87 private dataService: DataService;
89 /** Utilizes rest service for any CRUD operations @private */
90 private restService: RestService;
92 /** Contains all methods related to shared @private */
93 private sharedService: SharedService;
95 /** Holds teh instance of AuthService class of type AuthService @private */
96 private activatedRoute: ActivatedRoute;
98 /** Instance of the modal service @private */
99 private modalService: NgbModal;
101 /** variables contains paramsID @private */
102 private paramsID: string;
104 /** variables contains paramsID @private */
105 private paramsType: string;
107 /** variables conatins URL of the History operations @public */
108 private historyURL: string;
110 /** Contains tranlsate instance @private */
111 private translateService: TranslateService;
113 /** Instance of subscriptions @private */
114 private generateDataSub: Subscription;
116 /** Service holds the router information @private */
117 private router: Router;
119 constructor(injector: Injector) {
120 this.injector = injector;
121 this.restService = this.injector.get(RestService);
122 this.dataService = this.injector.get(DataService);
123 this.sharedService = this.injector.get(SharedService);
124 this.activatedRoute = this.injector.get(ActivatedRoute);
125 this.modalService = this.injector.get(NgbModal);
126 this.translateService = this.injector.get(TranslateService);
127 this.router = this.injector.get(Router);
130 /** Lifecyle Hooks the trigger before component is instantiate @public */
131 public ngOnInit(): void {
132 // tslint:disable-next-line:no-backbone-get-set-outside-model
133 this.paramsID = this.activatedRoute.snapshot.paramMap.get('id');
134 // tslint:disable-next-line:no-backbone-get-set-outside-model
135 this.paramsType = this.activatedRoute.snapshot.paramMap.get('type');
136 if (this.paramsType === 'ns') {
137 this.historyURL = environment.NSHISTORYOPERATIONS_URL + '/?nsInstanceId=' + this.paramsID;
138 this.page = 'ns-history-operation';
139 this.titleName = 'INSTANCEDETAILS';
140 } else if (this.paramsType === 'netslice') {
141 this.historyURL = environment.NSTHISTORYOPERATIONS_URL + '/?netsliceInstanceId=' + this.paramsID;
142 this.page = 'nst-history-operation';
143 this.titleName = 'INSTANCEDETAILS';
145 this.generateTableColumn();
146 this.generateTableSettings();
148 this.generateDataSub = this.sharedService.dataEvent.subscribe(() => { this.generateData(); });
151 /** Generate smart table row title and filters @public */
152 public generateTableSettings(): void {
154 columns: this.columnList,
156 add: false, edit: false, delete: false, position: 'right',
158 name: 'showInformation', title: '<i class="fas fa-info" title=" ' + this.translateService.instant('INFO') + ' "></i>'}]
160 attr: this.sharedService.tableClassConfig(),
161 pager: this.sharedService.paginationPagerConfig(),
162 noDataMessage: this.translateService.instant('NODATAMSG')
166 /** Generate smart table row title and filters @public */
167 public generateTableColumn(): void {
169 id: { title: this.translateService.instant('ID'), width: '30%' },
170 type: { title: this.translateService.instant('TYPE'), width: '20%' },
172 type: 'html', title: this.translateService.instant('OPERATIONSTATE'), width: '15%',
176 selectText: 'Select',
178 { value: this.historyStateFirstStep, title: this.historyStateFirstStep },
179 { value: this.historyStateSecondStep, title: this.historyStateSecondStep },
180 { value: this.historyStateThirdStep, title: this.historyStateThirdStep }
184 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
185 if (row.state === this.historyStateFirstStep) {
186 return `<span class="icon-label" title="${row.state}">
187 <i class="fas fa-clock text-warning"></i>
189 } else if (row.state === this.historyStateSecondStep) {
190 return `<span class="icon-label" title="${row.state}">
191 <i class="fas fa-check-circle text-success"></i>
193 } else if (row.state === this.historyStateThirdStep) {
194 return `<span class="icon-label" title="${row.state}">
195 <i class="fas fa-times-circle text-danger"></i>
198 return `<span>${row.state}</span>`;
202 startTime: { title: this.translateService.instant('STARTTIME'), width: '15%' },
203 statusEnteredTime: { title: this.translateService.instant('STATUSENTEREDTIME'), width: '15%' }
207 /** smart table listing manipulation @public */
208 public onUserRowSelect(event: MessageEvent): void {
209 this.dataService.changeMessage(event.data);
211 /** smart table listing manipulation @public */
212 public onChange(perPageValue: number): void {
213 this.dataSource.setPaging(1, perPageValue, true);
215 /** show information methods modal with ns history info */
216 public showInformation(event: MessageEvent): void {
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: {}[]) => {
235 this.nsAndnstInstanceData = [];
236 nsdInstancesData.forEach((nsdAndnstInstanceData: NSDInstanceData) => {
237 const nsAndnstDataObj: {} = {
238 id: nsdAndnstInstanceData.id,
239 type: nsdAndnstInstanceData.lcmOperationType,
240 state: nsdAndnstInstanceData.operationState,
241 startTime: this.sharedService.convertEpochTime(nsdAndnstInstanceData.startTime),
242 statusEnteredTime: this.sharedService.convertEpochTime(nsdAndnstInstanceData.statusEnteredTime)
244 this.nsAndnstInstanceData.push(nsAndnstDataObj);
247 if (this.nsAndnstInstanceData.length > 0) {
248 this.checkDataClass = 'dataTables_present';
250 this.checkDataClass = 'dataTables_empty';
252 this.dataSource.load(this.nsAndnstInstanceData).then((data: {}) => {
255 this.isLoadingResults = false;
256 }, (error: ERRORDATA) => {
257 this.isLoadingResults = false;
258 if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED) {
259 this.router.navigateByUrl('404', { skipLocationChange: true }).catch();
261 this.restService.handleError(error, 'get');