Untitled
unknown
plain_text
2 years ago
11 kB
8
Indexable
/*******************************************************************************
*
* Copyright (C) Capgemini Engineering ACT S.A.S. 2017-2023. All rights reserved.
*
********************************************************************************/
/*******************************************************************************
*
* Copyright (C) Altran ACT S.A.S. 2018,2019,2020,2021,2023. All rights reserved.
*
********************************************************************************/
import { Component, Inject, OnInit } from '@angular/core';
import { DataTableV2, Modal } from 'carbon-components';
import { AppService } from '../../../app.service';
import { ConfigConstant } from '../../../app.constant';
import { OverflowMenuModel, CommonUtilitiesLib, StorageUtilityLib, AuthticationLib ,
SearchModel, PaginationModel } from '../../../shared';
import { Router, ActivatedRoute } from '@angular/router';
import { AppCommonService } from '../../../app-common.service';
import { DeleteConfirmationModel } from '../../../shared/models';
import { TranslateService } from '@ngx-translate/core';
import { environment } from '../../../../environments/environment';
import { ToastrService } from 'ngx-toastr';
import { Trans } from '../../../translate-service.constant';
/**
* Class contain the property and functions of list Nodes component
*
* @export
* @class AppAdminNodeListComponent
*/
@Component({
templateUrl: './admin.listing.component.html',
styleUrls: ['./admin.listing.component.scss']
})
export class AppAdminNodeListComponent implements OnInit {
tableHeaderKeys = ['adminNodeName', 'nodeIpAddress', 'port', 'adminProtocol', 'nodeDescription'];
tableData = [];
nodeId:string;
editDeleteOverFlowMenuConf: OverflowMenuModel;
searchConf: SearchModel;
deleteConfirmationTab: DeleteConfirmationModel;
deleteAuthModal: Modal;
rowNumbToDelete: any;
textLimit: number = ConfigConstant.getData('grid').maxColumnText;
paginationConf: PaginationModel;
sourceData: any;
exportData = [];
showMoreRecordNotification: Boolean = false;
headerListSearch = [];
listlength = 0;
keyListTemp: any[] = [];
constructor(
protected appService: AppService,
private router: Router,
private toastr: ToastrService,
private commonUtilitiesLib: CommonUtilitiesLib,
private appCommonService: AppCommonService,
private translateService: TranslateService,
private activeRoute: ActivatedRoute,
private authticationLib: AuthticationLib,
@Inject(Trans) private trans: Trans
) {
}
ngOnInit() {
this.deleteAuthModal = Modal.create(document.querySelector('[data-modal].delete-confirm'));
const that = this;
this.getAllNodesAdmin();
this.editDeleteOverFlowMenuConf = {
menuImage: 'assets/source-images/menu_icon.svg',
menuAltImage: 'assets/source-images/menu_colored_icon.svg',
menuStyleConf: {
parentClass: 'custom-datatable-menu',
optionsClass: 'custom-datatable-menu-options'
},
menuOptions: [
{
label: 'adminListing.edit',
actionType: 'edit'
},
{
label: 'adminListing.delete',
actionType: 'delete'
},
{
label: 'adminListing.duplicate',
actionType: 'duplicate'
}
],
actionsHandler: {
doAction: (rowItem, actionType) => {
switch (actionType) {
case 'delete':
that.deleteAuthModal.show();
this.rowNumbToDelete = rowItem;
break;
case 'edit':
this.editNode(rowItem);
break;
case 'duplicate':
this.duplicateNode(rowItem);
break;
}
}
}
};
this.searchConf = {
searchText: ''
};
this.deleteConfirmationTab = {
primaryHeadingNormal: 'adminListing.deleteConfirmation',
primaryHeadingBold: 'adminListing.deleteConfirmationLabel',
primaryHeadingUrl: '',
primarybutton: {
label: 'adminListing.yesButton',
url: [],
activeUrl: '',
customAction: false,
actionType: 'primary',
className: '',
showActive: false,
activeLogo: '',
showAlert: false,
alertClass: '',
alertlogo: ''
},
secondarybutton: {
label: 'adminListing.noButton',
url: [],
activeUrl: '',
customAction: false,
actionType: 'secondary',
className: '',
showActive: false,
activeLogo: '',
showAlert: false,
alertClass: '',
alertlogo: ''
},
actionsHandler: {
decideAction: function (actionType) {
switch (actionType) {
case 'primary':
that.deleteNode(that.rowNumbToDelete);
break;
case 'secondary':
break;
}
}
}
};
this.paginationConf = {
showTotalItems: false,
showTotalPage: false,
disablePreviousBtn: true,
disableForwardBtn: true,
itemLabel: 'adminListing.nodesPerPage',
itemPerPageOption: [10, 20, 30, 40, 50],
itemPerPage: 10,
pageNumber: 1,
actionsHandler: {
doAction: (pageNo, itemPerPage) => {
this.displayData(pageNo, itemPerPage);
}
}
};
}
getAllNodesAdmin() {
const dummyGrpJson = {};
dummyGrpJson['adminNodeName'] = '*ALL';
this.appService.masterWrapperAdmin(
this.appCommonService.designMaterRequest({
'allparameters': this.commonUtilitiesLib.copy(dummyGrpJson),
'verbtype': 'get',
'apisname': ['ADMINUSERNODENAMES'],
'responseformat': 'rest'
})
).subscribe((success: any) => {
const nodes = success.data[0].ADMINUSERNODENAMES;
if(!nodes[0]['messageCode']) {
this.exportData = this.commonUtilitiesLib.copy(nodes);
this.exportData = nodes.map(node => {
return {
...node,
nodeDescription: node.nodeDescription ? node.nodeDescription : '', // Change nodeDescription to empty string if it's null
};
});
for (let i = 0; i < nodes.length; i++) {
nodes[i].adminProtocol = nodes[i].adminProtocol.toUpperCase();
this.tableData[i] = nodes[i];
this.tableData[i]['highlight'] = false;
}
}
else{
this.exportData = [];
}
this.sourceData = this.tableData;
this.paginationConf.pageNumber = 1;
this.displayData( this.paginationConf.pageNumber, this.paginationConf.itemPerPage);
}, error => {
this.tableData = [];
});
}
exportNode() {
if (this.exportData.length == 0) {
this.toastr.success('No data to be exported.', '', { easeTime: 3000 });
} else {
this.appCommonService.exportNodeList(this.exportData);
}
}
duplicateNode(object) {
// Create a deep copy of the node to duplicate
const duplicatedNode: Node = JSON.parse(JSON.stringify(object));
console.log(duplicatedNode);
// Generate a unique identifier for the duplicated node (optional)
const uniqueIdentifier = Date.now().toString();
// Assign the new unique identifier to the duplicated node (optional)
// duplicatedNode.nodeId = uniqueIdentifier;
this.router.navigate(['/admin', 'new', object.item.adminNodeName, 'duplicate']);
// Navigate to the new route for editing and creating a new node
// this.router.navigate(['/duplicate-and-edit-node'], {
// state: { duplicatedNodeData: duplicatedNode },
// });
}
editNode(object: any) {
this.router.navigate(['/admin', 'new', object.item.adminNodeName, 'editAdminNode']);
}
deleteNode(objectID: any) {
this.appService.masterWrapperAdmin(
{
params: {
'allparameters': this.commonUtilitiesLib.copy(objectID.item),
'allconfig': this.commonUtilitiesLib.copy({
'verbtype': 'delete',
'apiname': ['ADMINUSERNODENAMES;'],
'responseformat': {
'format': 'rest'
}
})
}
}
).subscribe((success: any) => {
this.toastr.success(this.translateService.instant('adminListing.deleteSuccesssMessage'));
this.getAllNodesAdmin();
this.tableData = [];
this.deleteAuthModal.hide();
}, error => {
this.toastr.error(this.translateService.instant('adminListing.deleteFailMessage'));
});
}
displayData(page, itemPerPage) {
if (page === 1) {
this.paginationConf.disablePreviousBtn = true;
} else {
this.paginationConf.disablePreviousBtn = false;
}
if (page * itemPerPage < this.sourceData.length) {
this.paginationConf.disableForwardBtn = false;
} else {
this.paginationConf.disableForwardBtn = true;
}
if ((page - 1) * itemPerPage <= this.sourceData.length) {
this.tableData = this.sourceData.slice((page - 1) * itemPerPage, page * itemPerPage);
this.tableData = (this.tableData[0] && this.tableData[0].adminNodeName) ? this.tableData : [];
this.listlength = this.tableData.length;
this.keyListTemp = this.trans.getData('keyList').keyListAll;
this.keyListTemp.forEach(element => {
this.headerListSearch.push(element.key);
});
} else {
if (this.sourceData.length > 500) {
this.showMoreRecordNotification = true;
}
}
}
}
Editor is loading...