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 NVF Instance Component
21 import { Component, Injector, OnInit } from '@angular/core';
22 import { TranslateService } from '@ngx-translate/core';
23 import { ERRORDATA } from 'CommonModel';
24 import { DataService } from 'DataService';
25 import { environment } from 'environment';
26 import { LocalDataSource } from 'ng2-smart-table';
27 import { RestService } from 'RestService';
28 import { Subscription } from 'rxjs';
29 import { SharedService } from 'SharedService';
30 import { VNFInstanceData, VNFInstanceDetails } from 'VNFInstanceModel';
31 import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
32 import { VNFLinkComponent } from 'VNFLinkComponent';
36 * @Component takes VNFInstancesComponent.html as template url
39 templateUrl: './VNFInstancesComponent.html',
40 styleUrls: ['./VNFInstancesComponent.scss']
42 /** Exporting a class @exports VNFInstancesComponent */
43 export class VNFInstancesComponent implements OnInit {
44 /** To inject services @public */
45 public injector: Injector;
47 /** smart table data service collections @public */
48 public dataSource: LocalDataSource = new LocalDataSource();
50 /** Instance component are stored in settings @public */
51 public settings: {} = {};
53 /** Contains objects for menu settings @public */
54 public columnList: {} = {};
56 /** vnf instance array @public */
57 public vnfInstanceData: {}[] = [];
59 /** selected rows array @public */
60 public selectedRows: string[] = [];
62 /** selected list array @public */
63 public selectList: string[] = [];
65 /** Check the loading results @public */
66 public isLoadingResults: boolean = true;
68 /** Give the message for the loading @public */
69 public message: string = 'PLEASEWAIT';
71 /** Class for empty and present data @public */
72 public checkDataClass: string;
74 /** Utilizes rest service for any CRUD operations @private */
75 private restService: RestService;
77 /** packages data service collections @private */
78 private dataService: DataService;
80 /** Contains all methods related to shared @private */
81 private sharedService: SharedService;
83 /** Contains tranlsate instance @private */
84 private translateService: TranslateService;
86 /** Instance of subscriptions @private */
87 private generateDataSub: Subscription;
89 constructor(injector: Injector) {
90 this.injector = injector;
91 this.restService = this.injector.get(RestService);
92 this.dataService = this.injector.get(DataService);
93 this.sharedService = this.injector.get(SharedService);
94 this.translateService = this.injector.get(TranslateService);
98 * Lifecyle Hooks the trigger before component is instantiate
100 public ngOnInit(): void {
101 this.generateTableColumn();
102 this.generateTableSettings();
104 this.generateDataSub = this.sharedService.dataEvent.subscribe(() => { this.generateData(); });
107 /** Generate smart table row title and filters @public */
108 public generateTableSettings(): void {
110 actions: { add: false, edit: false, delete: false, position: 'right' },
111 columns: this.columnList,
112 attr: this.sharedService.tableClassConfig(),
113 pager: this.sharedService.paginationPagerConfig(),
114 noDataMessage: this.translateService.instant('NODATAMSG')
118 /** Generate smart table row title and filters @public */
119 public generateTableColumn(): void {
121 identifier: { title: this.translateService.instant('IDENTIFIER'), width: '25%' },
123 title: this.translateService.instant('VNFD'), width: '20%', type: 'custom',
124 valuePrepareFunction: (cell: VNFInstanceData, row: VNFInstanceData): VNFInstanceData => row,
125 renderComponent: VNFLinkComponent
127 MemberIndex: { title: this.translateService.instant('MEMBERINDEX'), width: '15%' },
128 NS: { title: this.translateService.instant('NS'), width: '20%' },
130 title: this.translateService.instant('CREATEDAT'), width: '15%', sortDirection: 'desc',
131 compareFunction: this.sharedService.compareFunction
134 name: 'Action', width: '5%', filter: false, sort: false, type: 'custom',
135 title: this.translateService.instant('ACTIONS'),
136 valuePrepareFunction: (cell: VNFInstanceData, row: VNFInstanceData): VNFInstanceData => row,
137 renderComponent: VNFInstancesActionComponent
142 /** generateData initiate the vnf-instance list */
143 public generateData(): void {
144 this.isLoadingResults = true;
145 this.restService.getResource(environment.VNFINSTANCES_URL).subscribe((vnfInstancesData: VNFInstanceDetails[]) => {
146 this.vnfInstanceData = [];
147 vnfInstancesData.forEach((vnfInstanceData: VNFInstanceDetails): void => {
148 const vnfDataObj: {} =
150 VNFD: vnfInstanceData['vnfd-ref'],
151 identifier: vnfInstanceData._id,
152 MemberIndex: vnfInstanceData['member-vnf-index-ref'],
153 NS: vnfInstanceData['nsr-id-ref'],
154 VNFID: vnfInstanceData['vnfd-id'],
155 CreatedAt: this.sharedService.convertEpochTime(Number(vnfInstanceData['created-time']))
157 this.vnfInstanceData.push(vnfDataObj);
159 if (this.vnfInstanceData.length > 0) {
160 this.checkDataClass = 'dataTables_present';
162 this.checkDataClass = 'dataTables_empty';
164 this.dataSource.load(this.vnfInstanceData).then((data: {}) => {
165 this.isLoadingResults = false;
166 }).catch((): void => {
167 // Catch Navigation Error
169 }, (error: ERRORDATA) => {
170 this.restService.handleError(error, 'get');
171 this.isLoadingResults = false;
175 /** smart table listing manipulation @public */
176 public onChange(perPageValue: number): void {
177 this.dataSource.setPaging(1, perPageValue, true);
180 /** smart table listing manipulation @public */
181 public onUserRowSelect(event: MessageEvent): void {
182 Object.assign(event.data, { page: 'vnf-instance' });
183 this.dataService.changeMessage(event.data);
187 * Lifecyle hook which get trigger on component destruction
189 public ngOnDestroy(): void {
190 this.generateDataSub.unsubscribe();