blob: bf6e122ba225f2bcc89561ef9e56aab1bd35f545 [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
SANDHYA.JS26570112024-07-05 21:35:46 +053073 /** Check the loading results @public */
74 public isLoadingResults: boolean = true;
75
76 /** Give the message for the loading @public */
77 public message: string = 'PLEASEWAIT';
78
79 /** Class for empty and present data @public */
80 public checkDataClass: string;
81
82 /** Instance of the rest service @private */
83 private restService: RestService;
84
85 /** dataService to pass the data from one component to another @private */
86 private dataService: DataService;
87
88 /** Formation of appropriate Data for LocalDatasource @private */
89 private okaData: VNFData[] = [];
90
91 /** Contains all methods related to shared @private */
92 private sharedService: SharedService;
93
94 /** Instance of the modal service @private */
95 private modalService: NgbModal;
96
97 /** Instance of subscriptions @private */
98 private generateDataSub: Subscription;
99
100 constructor(injector: Injector) {
101 this.injector = injector;
102 this.restService = this.injector.get(RestService);
103 this.dataService = this.injector.get(DataService);
104 this.sharedService = this.injector.get(SharedService);
105 this.translateService = this.injector.get(TranslateService);
106 this.modalService = this.injector.get(NgbModal);
107 }
108
109 /**
110 * Lifecyle Hooks the trigger before component is instantiate
111 */
112 public ngOnInit(): void {
113 this.generateColumns();
114 this.generateSettings();
115 this.generateData();
116 this.generateDataSub = this.sharedService.dataEvent.subscribe((): void => { this.generateData(); });
117 }
118
119 /** smart table Header Colums @public */
120 public generateColumns(): void {
121 this.columnLists = {
122 name: { title: this.translateService.instant('NAME'), width: '15%', sortDirection: 'asc' },
123 identifier: { title: this.translateService.instant('IDENTIFIER'), width: '20%' },
124 state: {
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530125 title: this.translateService.instant('STATE'), width: '15%', type: 'html',
SANDHYA.JS26570112024-07-05 21:35:46 +0530126 filter: {
127 type: 'list',
128 config: {
129 selectText: 'Select',
130 list: [
131 { value: this.operationalStateFirstStep, title: this.operationalStateFirstStep },
132 { value: this.operationalStateSecondStep, title: this.operationalStateSecondStep },
133 { value: this.operationalStateThirdStep, title: this.operationalStateThirdStep },
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530134 { value: this.operationalStateThirdStep, title: this.operationalStateFourthStep }
SANDHYA.JS26570112024-07-05 21:35:46 +0530135 ]
136 }
137 },
138 valuePrepareFunction: (cell: VNFD, row: VNFD): string => {
139 if (row.state === this.operationalStateFirstStep) {
140 return `<span class="icon-label" title="${row.state}">
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530141 <i class="fas fa-clock text-success"></i>
142 </span>`;
SANDHYA.JS26570112024-07-05 21:35:46 +0530143 } else if (row.state === this.operationalStateSecondStep) {
144 return `<span class="icon-label" title="${row.state}">
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530145 <i class="fas fa-times-circle text-danger"></i>
146 </span>`;
SANDHYA.JS26570112024-07-05 21:35:46 +0530147 } else if (row.state === this.operationalStateFourthStep) {
148 return `<span class="icon-label" title="${row.state}">
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530149 <i class="fas fa-ban text-danger"></i>
150 </span>`;
SANDHYA.JS26570112024-07-05 21:35:46 +0530151 } else {
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530152 return `<span class="icon-label" title="${row.state}">
153 <i class="fas fa-spinner text-warning"></i>
154 </span>`;
SANDHYA.JS26570112024-07-05 21:35:46 +0530155 }
156 }
157 },
158 usageState: { title: this.translateService.instant('USAGESTATE'), width: '15%' },
159 created: { title: this.translateService.instant('CREATED'), width: '15%' },
160 Actions: {
161 name: 'Action', width: '10%', filter: false, sort: false, type: 'custom',
162 title: this.translateService.instant('ACTIONS'),
163 valuePrepareFunction: (cell: VNFData, row: VNFData): VNFData => row, renderComponent: OkaPackagesActionComponent
164 }
165 };
166 }
167
168 /** smart table Data Settings @public */
169 public generateSettings(): void {
170 this.settings = {
171 edit: {
172 editButtonContent: '<i class="fa fa-edit" title="Edit"></i>',
173 confirmSave: true
174 },
175 delete: {
176 deleteButtonContent: '<i class="far fa-trash-alt" title="delete"></i>',
177 confirmDelete: true
178 },
179 columns: this.columnLists,
180 actions: {
181 add: false,
182 edit: false,
183 delete: false,
184 position: 'right'
185 },
186 attr: this.sharedService.tableClassConfig(),
187 pager: this.sharedService.paginationPagerConfig(),
188 noDataMessage: this.translateService.instant('NODATAMSG')
189 };
190 }
191
192 /** smart table listing manipulation @public */
193 public onChange(perPageValue: number): void {
194 this.dataSource.setPaging(1, perPageValue, true);
195 }
196
197 /** OnUserRowSelect Function @public */
198 public onUserRowSelect(event: MessageEvent): void {
199 Object.assign(event.data, { page: 'oka-packages' });
200 this.dataService.changeMessage(event.data);
201 }
202
203 /** Generate okaData object from loop and return for the datasource @public */
204 public generateokaData(okadpackagedata: VNFD): VNFData {
205 return {
206 name: okadpackagedata.name,
207 identifier: okadpackagedata._id,
208 onboardingState: okadpackagedata._admin.onboardingState,
209 usageState: okadpackagedata._admin.usageState,
210 created: this.sharedService.convertEpochTime(Number(okadpackagedata._admin.created)),
SANDHYA.JS92379ec2025-06-13 17:29:35 +0530211 state: okadpackagedata.resourceState
SANDHYA.JS26570112024-07-05 21:35:46 +0530212 };
213 }
214 /** Handle compose new oka package method @public */
215 public composeOKAPackage(): void {
216 // eslint-disable-next-line security/detect-non-literal-fs-filename
217 const modalRef: NgbModalRef = this.modalService.open(ComposePackages, { backdrop: 'static' });
SANDHYA.JSa3ff32a2025-02-13 16:24:46 +0530218 modalRef.componentInstance.params = { page: 'oka-packages', operationType: 'add' };
SANDHYA.JS26570112024-07-05 21:35:46 +0530219 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
220 if (result) {
221 this.sharedService.callData();
222 }
223 }).catch((): void => {
224 // Catch Navigation Error
225 });
226 }
227
228 /**
229 * Lifecyle hook which get trigger on component destruction
230 */
231 public ngOnDestroy(): void {
232 this.generateDataSub.unsubscribe();
233 }
234
235 /** Fetching the data from server to Load in the smarttable @protected */
236 protected generateData(): void {
237 this.isLoadingResults = true;
238 this.restService.getResource(environment.OKAPACKAGES_URL).subscribe((okadPackageData: VNFD[]): void => {
239 this.okaData = [];
240 okadPackageData.forEach((okadpackagedata: VNFD): void => {
241 const okaDataObj: VNFData = this.generateokaData(okadpackagedata);
242 this.okaData.push(okaDataObj);
243 });
244 if (this.okaData.length > 0) {
245 this.checkDataClass = 'dataTables_present';
246 } else {
247 this.checkDataClass = 'dataTables_empty';
248 }
249 this.dataSource.load(this.okaData).then((data: boolean): void => {
250 this.isLoadingResults = false;
251 }).catch((): void => {
252 this.isLoadingResults = false;
253 });
254 }, (error: ERRORDATA): void => {
255 this.restService.handleError(error, 'get');
256 this.isLoadingResults = false;
257 });
258 }
259}