blob: 702d8e6550393afc6aa30b6679ba2242ff7e41a0 [file] [log] [blame]
SANDHYA.JS26570112024-07-05 21:35:46 +05301/*
2 Copyright 2020 TATA ELXSI
3
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
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
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.
15
16 Author: SANDHYA JS (sandhya.j@tataelxsi.co.in)
17*/
18/**
19 * @file OKA Package details Component.
20 */
21import { Component, Injector, OnInit } from '@angular/core';
22import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
23import { TranslateService } from '@ngx-translate/core';
24import { CONFIGCONSTANT, ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
25import { ComposePackages } from 'ComposePackages';
26import { DataService } from 'DataService';
27import { environment } from 'environment';
28import { LocalDataSource } from 'ng2-smart-table';
29import { OkaPackagesActionComponent } from 'OkaPackagesActionComponent';
30import { RestService } from 'RestService';
31import { Subscription } from 'rxjs';
32import { SharedService } from 'SharedService';
33import { VNFD, VNFData } from 'VNFDModel';
34
35/**
36 * Creating component
37 * @Component takes OKAPackageComponent.html as template url
38 */
39@Component({
40 selector: 'app-oka-packages',
41 templateUrl: './OKAPackageComponent.html',
42 styleUrls: ['./OKAPackageComponent.scss']
43})
44/** Exporting a class @exports OKAPackageComponent */
45export class OKAPackageComponent implements OnInit {
46 /** To inject services @public */
47 public injector: Injector;
48
49 /** Data of smarttable populate through LocalDataSource @public */
50 public dataSource: LocalDataSource = new LocalDataSource();
51
52 /** handle translate @public */
53 public translateService: TranslateService;
54
55 /** Columns list of the smart table @public */
56 public columnLists: object = {};
57
58 /** Settings for smarttable to populate the table with columns @public */
59 public settings: object = {};
60
61 /** operational State created data @public */
62 public operationalStateFirstStep: string = CONFIGCONSTANT.k8OperationalStateFirstStep;
63
64 /** operational State in creation data @public */
65 public operationalStateSecondStep: string = CONFIGCONSTANT.k8OperationalStateStateSecondStep;
66
67 /** operational State in deletion data @public */
68 public operationalStateThirdStep: string = CONFIGCONSTANT.k8OperationalStateThirdStep;
69
70 /** operational State failed deletion data @public */
71 public operationalStateFourthStep: string = CONFIGCONSTANT.k8OperationalStateFourthStep;
72
73 /** operational State failed creation data @public */
74 public operationalStateFifthStep: string = CONFIGCONSTANT.k8OperationalStateFifthStep;
75
76 /** Check the loading results @public */
77 public isLoadingResults: boolean = true;
78
79 /** Give the message for the loading @public */
80 public message: string = 'PLEASEWAIT';
81
82 /** Class for empty and present data @public */
83 public checkDataClass: string;
84
85 /** Instance of the rest service @private */
86 private restService: RestService;
87
88 /** dataService to pass the data from one component to another @private */
89 private dataService: DataService;
90
91 /** Formation of appropriate Data for LocalDatasource @private */
92 private okaData: VNFData[] = [];
93
94 /** Contains all methods related to shared @private */
95 private sharedService: SharedService;
96
97 /** Instance of the modal service @private */
98 private modalService: NgbModal;
99
100 /** Instance of subscriptions @private */
101 private generateDataSub: Subscription;
102
103 constructor(injector: Injector) {
104 this.injector = injector;
105 this.restService = this.injector.get(RestService);
106 this.dataService = this.injector.get(DataService);
107 this.sharedService = this.injector.get(SharedService);
108 this.translateService = this.injector.get(TranslateService);
109 this.modalService = this.injector.get(NgbModal);
110 }
111
112 /**
113 * Lifecyle Hooks the trigger before component is instantiate
114 */
115 public ngOnInit(): void {
116 this.generateColumns();
117 this.generateSettings();
118 this.generateData();
119 this.generateDataSub = this.sharedService.dataEvent.subscribe((): void => { this.generateData(); });
120 }
121
122 /** smart table Header Colums @public */
123 public generateColumns(): void {
124 this.columnLists = {
125 name: { title: this.translateService.instant('NAME'), width: '15%', sortDirection: 'asc' },
126 identifier: { title: this.translateService.instant('IDENTIFIER'), width: '20%' },
127 state: {
SANDHYA.JSa3ff32a2025-02-13 16:24:46 +0530128 title: this.translateService.instant('GITSTATE'), width: '15%', type: 'html',
SANDHYA.JS26570112024-07-05 21:35:46 +0530129 filter: {
130 type: 'list',
131 config: {
132 selectText: 'Select',
133 list: [
134 { value: this.operationalStateFirstStep, title: this.operationalStateFirstStep },
135 { value: this.operationalStateSecondStep, title: this.operationalStateSecondStep },
136 { value: this.operationalStateThirdStep, title: this.operationalStateThirdStep },
137 { value: this.operationalStateThirdStep, title: this.operationalStateFourthStep },
138 { value: this.operationalStateThirdStep, title: this.operationalStateFifthStep }
139 ]
140 }
141 },
142 valuePrepareFunction: (cell: VNFD, row: VNFD): string => {
143 if (row.state === this.operationalStateFirstStep) {
144 return `<span class="icon-label" title="${row.state}">
145 <i class="fas fa-clock text-success"></i>
146 </span>`;
147 } else if (row.state === this.operationalStateSecondStep) {
148 return `<span class="icon-label" title="${row.state}">
149 <i class="fas fa-spinner text-warning"></i>
150 </span>`;
151 } else if (row.state === this.operationalStateThirdStep) {
152 return `<span class="icon-label" title="${row.state}">
153 <i class="fas fa-spinner text-danger"></i>
154 </span>`;
155 } else if (row.state === this.operationalStateFourthStep) {
156 return `<span class="icon-label" title="${row.state}">
157 <i class="fas fa-times-circle text-danger"></i>
158 </span>`;
159 } else if (row.state === this.operationalStateFifthStep) {
160 return `<span class="icon-label" title="${row.state}">
161 <i class="fas fa-times-circle text-warning"></i>
162 </span>`;
163 } else {
164 return `<span>${row.state}</span>`;
165 }
166 }
167 },
168 usageState: { title: this.translateService.instant('USAGESTATE'), width: '15%' },
169 created: { title: this.translateService.instant('CREATED'), width: '15%' },
170 Actions: {
171 name: 'Action', width: '10%', filter: false, sort: false, type: 'custom',
172 title: this.translateService.instant('ACTIONS'),
173 valuePrepareFunction: (cell: VNFData, row: VNFData): VNFData => row, renderComponent: OkaPackagesActionComponent
174 }
175 };
176 }
177
178 /** smart table Data Settings @public */
179 public generateSettings(): void {
180 this.settings = {
181 edit: {
182 editButtonContent: '<i class="fa fa-edit" title="Edit"></i>',
183 confirmSave: true
184 },
185 delete: {
186 deleteButtonContent: '<i class="far fa-trash-alt" title="delete"></i>',
187 confirmDelete: true
188 },
189 columns: this.columnLists,
190 actions: {
191 add: false,
192 edit: false,
193 delete: false,
194 position: 'right'
195 },
196 attr: this.sharedService.tableClassConfig(),
197 pager: this.sharedService.paginationPagerConfig(),
198 noDataMessage: this.translateService.instant('NODATAMSG')
199 };
200 }
201
202 /** smart table listing manipulation @public */
203 public onChange(perPageValue: number): void {
204 this.dataSource.setPaging(1, perPageValue, true);
205 }
206
207 /** OnUserRowSelect Function @public */
208 public onUserRowSelect(event: MessageEvent): void {
209 Object.assign(event.data, { page: 'oka-packages' });
210 this.dataService.changeMessage(event.data);
211 }
212
213 /** Generate okaData object from loop and return for the datasource @public */
214 public generateokaData(okadpackagedata: VNFD): VNFData {
215 return {
216 name: okadpackagedata.name,
217 identifier: okadpackagedata._id,
218 onboardingState: okadpackagedata._admin.onboardingState,
219 usageState: okadpackagedata._admin.usageState,
220 created: this.sharedService.convertEpochTime(Number(okadpackagedata._admin.created)),
221 state: okadpackagedata.state
222 };
223 }
224 /** Handle compose new oka package method @public */
225 public composeOKAPackage(): void {
226 // eslint-disable-next-line security/detect-non-literal-fs-filename
227 const modalRef: NgbModalRef = this.modalService.open(ComposePackages, { backdrop: 'static' });
SANDHYA.JSa3ff32a2025-02-13 16:24:46 +0530228 modalRef.componentInstance.params = { page: 'oka-packages', operationType: 'add' };
SANDHYA.JS26570112024-07-05 21:35:46 +0530229 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
230 if (result) {
231 this.sharedService.callData();
232 }
233 }).catch((): void => {
234 // Catch Navigation Error
235 });
236 }
237
238 /**
239 * Lifecyle hook which get trigger on component destruction
240 */
241 public ngOnDestroy(): void {
242 this.generateDataSub.unsubscribe();
243 }
244
245 /** Fetching the data from server to Load in the smarttable @protected */
246 protected generateData(): void {
247 this.isLoadingResults = true;
248 this.restService.getResource(environment.OKAPACKAGES_URL).subscribe((okadPackageData: VNFD[]): void => {
249 this.okaData = [];
250 okadPackageData.forEach((okadpackagedata: VNFD): void => {
251 const okaDataObj: VNFData = this.generateokaData(okadpackagedata);
252 this.okaData.push(okaDataObj);
253 });
254 if (this.okaData.length > 0) {
255 this.checkDataClass = 'dataTables_present';
256 } else {
257 this.checkDataClass = 'dataTables_empty';
258 }
259 this.dataSource.load(this.okaData).then((data: boolean): void => {
260 this.isLoadingResults = false;
261 }).catch((): void => {
262 this.isLoadingResults = false;
263 });
264 }, (error: ERRORDATA): void => {
265 this.restService.handleError(error, 'get');
266 this.isLoadingResults = false;
267 });
268 }
269}