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%', sortDirection: 'asc' },
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%' },
129 CreatedAt: { title: this.translateService.instant('CREATEDAT'), width: '15%' },
131 name: 'Action', width: '5%', filter: false, sort: false, type: 'custom',
132 title: this.translateService.instant('ACTIONS'),
133 valuePrepareFunction: (cell: VNFInstanceData, row: VNFInstanceData): VNFInstanceData => row,
134 renderComponent: VNFInstancesActionComponent
139 /** generateData initiate the vnf-instance list */
140 public generateData(): void {
141 this.isLoadingResults = true;
142 this.restService.getResource(environment.VNFINSTANCES_URL).subscribe((vnfInstancesData: VNFInstanceDetails[]) => {
143 this.vnfInstanceData = [];
144 vnfInstancesData.forEach((vnfInstanceData: VNFInstanceDetails): void => {
145 const vnfDataObj: {} =
147 VNFD: vnfInstanceData['vnfd-ref'],
148 identifier: vnfInstanceData._id,
149 MemberIndex: vnfInstanceData['member-vnf-index-ref'],
150 NS: vnfInstanceData['nsr-id-ref'],
151 VNFID: vnfInstanceData['vnfd-id'],
152 CreatedAt: this.sharedService.convertEpochTime(Number(vnfInstanceData['created-time']))
154 this.vnfInstanceData.push(vnfDataObj);
156 if (this.vnfInstanceData.length > 0) {
157 this.checkDataClass = 'dataTables_present';
159 this.checkDataClass = 'dataTables_empty';
161 this.dataSource.load(this.vnfInstanceData).then((data: {}) => {
162 this.isLoadingResults = false;
164 }, (error: ERRORDATA) => {
165 this.restService.handleError(error, 'get');
166 this.isLoadingResults = false;
170 /** smart table listing manipulation @public */
171 public onChange(perPageValue: number): void {
172 this.dataSource.setPaging(1, perPageValue, true);
175 /** smart table listing manipulation @public */
176 public onUserRowSelect(event: MessageEvent): void {
177 Object.assign(event.data, { page: 'vnf-instance' });
178 this.dataService.changeMessage(event.data);
182 * Lifecyle hook which get trigger on component destruction
184 public ngOnDestroy(): void {
185 this.generateDataSub.unsubscribe();