Untitled
unknown
plain_text
2 years ago
12 kB
9
Indexable
/*******************************************************************************
*
* Copyright (C) Capgemini Engineering ACT S.A.S. 2017-2023. All rights reserved.
*
********************************************************************************/
/*******************************************************************************
*
* Copyright (C) Altran ACT S.A.S. 2018,2020,2021,2022,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 {
PageHeaderModel, CommonUtilitiesLib, StorageUtilityLib, AuthticationLib, DropdownModel,
PageFooterModel
} from '../../../shared';
import { Router, ActivatedRoute } from '@angular/router';
import { AppCommonService } from '../../../app-common.service';
import { TranslateService } from '@ngx-translate/core';
import { environment } from '../../../../environments/environment';
import { UntypedFormGroup, UntypedFormBuilder, FormArray, Validators } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { Trans } from '../../../translate-service.constant';
/**
* Class contain the property and functions of create Nodes component
*
* @export
* @class AppAdminCreateNodeListComponent
*/
@Component({
templateUrl: './admin.create.node.component.html',
styleUrls: ['./admin.create.node.component.scss']
})
export class AppAdminCreateNodeListComponent implements OnInit {
headerConf: PageHeaderModel;
tableData = [];
newNodeCreateForm: UntypedFormGroup;
formKeys = ['adminNodeName', 'nodeIpAddress', 'port', 'adminProtocol', 'nodeDescription'];
adminProtocolDropdownConf: DropdownModel;
adminNodeName: any;
disableSubmit = false;
footerConf: PageFooterModel;
routeData;
exportData: [];
constructor( @Inject(UntypedFormBuilder) fb: UntypedFormBuilder,
private toastr: ToastrService,
protected appService: AppService,
private formBuilder: UntypedFormBuilder,
private router: Router,
private appCommonService: AppCommonService,
private commonUtilitiesLib: CommonUtilitiesLib,
private translate: TranslateService,
private activeRoute: ActivatedRoute,
@Inject(Trans) private trans: Trans
) {
this.newNodeCreateForm = fb.group({
'adminNodeName': ['', Validators.compose([Validators.required, Validators.minLength(1), Validators.maxLength(45)])],
'nodeIpAddress': ['', Validators.compose([Validators.required, Validators.maxLength(255)])],
'port': ['', Validators.compose([Validators.required, Validators.min(1), Validators.max(65535)])],
'adminProtocol': ['', Validators.required],
'nodeDescription': ['', Validators.maxLength(255)]
});
}
ngOnInit() {
const that = this;
const routeData = this.activeRoute.snapshot.data;
console.log(routeData);
const routeParams = {
adminNodeName: this.activeRoute.snapshot.paramMap.get('adminNodeName'),
};
this.adminNodeName = routeParams.adminNodeName;
this.headerConf = {
primaryHeadingNormal: '',
primaryHeadingBold: 'adminListing.createNode.createPageHeader',
primaryHeadingUrl: [],
action: [{
label: '',
disabled: false,
actionType: 'close',
isCustom: true,
url: []
}],
actionsHandler: {
doAction: function (actionType) {
switch (actionType) {
case 'close':
that.router.navigate(['/admin', 'list']);
break;
}
}
},
businessLogic: ''
};
this.setProtocolDropdownConf();
this.footerConf = {
action: [{
label: '',
disabled: true,
actionType: '',
isCustom: true,
url: ['']
}
],
actionsHandler: {
doAction: function (action) {
switch (action.actionType) {
case 'create':
that.createNode();
break;
case 'update':
that.editAdminNode();
break;
case 'duplicate':
that.setDuplicateAdminNode();
break;
}
}
}
};
if (routeData.new) {
this.footerConf.action[0].label = 'adminListing.createNode.submitButton';
this.footerConf.action[0].actionType = 'create';
} else {
this.getAdminNodeDetailsForEdit(this.adminNodeName);
this.footerConf.action[0].label = 'adminListing.createNode.updateButton';
this.footerConf.action[0].actionType = 'update';
this.newNodeCreateForm.controls['adminNodeName'].disable();
}
this.setProtocolOptions();
this.newNodeCreateForm.valueChanges.subscribe(() => {
if (this.newNodeCreateForm.valid) {
this.footerConf.action[0].disabled = false;
} else {
this.footerConf.action[0].disabled = true;
}
});
this.getAllNodesAdmin();
this.setPageDataBasedOnRouteData();
}
setPageDataBasedOnRouteData() {
this.headerConf.primaryHeadingBold = 'newContactView.duplicatePartner'
if (this.activeRoute.snapshot.data.duplicate ) {
this.getAdminNodeDetailsForEdit(this.adminNodeName);
//this.setDuplicateAdminNode();
this.getAllNodesAdmin();
console.log(this.exportData);
}
}
setDuplicateAdminNode(){
this.appService.masterWrapperAdmin(
{
params: {
'allparameters': this.commonUtilitiesLib.copy(this.newNodeCreateForm.getRawValue()),
'allconfig': this.commonUtilitiesLib.copy({
'verbtype': 'put',
'apiname': ['ADMINUSERNODENAMES;'],
'responseformat': {
'format': 'rest'
}
})
}
}
).subscribe((success: any) => {
const msg = this.translate.instant('masterData.nodeUpdate') + '\'' +
this.newNodeCreateForm.getRawValue().adminNodeName + '\' ' +
this.translate.instant('masterData.nodeUpdate2');
console.log(success);
this.toastr.success(msg);
this.router.navigate(['/admin', 'list', 'all']);
});
}
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
};
});
}
else{
this.exportData = [];
}
}, error => {
this.tableData = [];
});
}
/**
* @description To set protocol dropdown config.
*/
setProtocolDropdownConf() {
const that = this;
this.adminProtocolDropdownConf = {
options: [],
selectedOption: this.translate.instant('adminListing.createNode.pleaseSelect'),
displayKey: '',
id: 'adminProtocol',
className: 'admin-protocol-dropdown',
selectOption: (option) => {
that.adminProtocolDropdownConf.selectedOption = option;
that.newNodeCreateForm.patchValue({ adminProtocol: option.toLowerCase() });
},
isError: false
};
}
/**
* @description To set protocol dropdown options.
*/
setProtocolOptions() {
this.appService.getProtocols({}).subscribe((success: any) => {
let protocols = success.protocol;
this.adminProtocolDropdownConf.options = protocols;
});
}
createNode() {
this.appService.masterWrapperAdmin(
{
params: {
'allparameters': [this.commonUtilitiesLib.copy(this.newNodeCreateForm.value)],
'allconfig': this.commonUtilitiesLib.copy({
'verbtype': 'post',
'apiname': ['ADMINUSERNODENAMES;'],
'responseformat': {
'format': 'rest'
}
})
}
}
).subscribe((success: any) => {
const msg = '\'' + this.newNodeCreateForm.value.adminNodeName + '\' ' +
this.translate.instant('masterData.nodeAddAdmin');
this.toastr.success(msg);
this.router.navigate(['/admin', 'list', 'all']);
});
}
editAdminNode() {
this.appService.masterWrapperAdmin(
{
params: {
'allparameters': this.commonUtilitiesLib.copy(this.newNodeCreateForm.getRawValue()),
'allconfig': this.commonUtilitiesLib.copy({
'verbtype': 'put',
'apiname': ['ADMINUSERNODENAMES;'],
'responseformat': {
'format': 'rest'
}
})
}
}
).subscribe((success: any) => {
const msg = this.translate.instant('masterData.nodeUpdate') + '\'' +
this.newNodeCreateForm.getRawValue().adminNodeName + '\' ' +
this.translate.instant('masterData.nodeUpdate2');
this.toastr.success(msg);
this.router.navigate(['/admin', 'list', 'all']);
});
}
getAdminNodeDetailsForEdit(nodeName: any) {
const currentNode = nodeName;
this.appService.masterWrapperAdmin(
{
params: {
'allparameters': { 'adminNodeName': nodeName },
'allconfig': this.commonUtilitiesLib.copy({
'verbtype': 'get',
'apiname': ['ADMINUSERNODENAMES;'],
'responseformat': {
'format': 'rest'
}
})
}
}
).subscribe((success: any) => {
for (let i = 0; i < success.data[0].ADMINUSERNODENAMES.length; i++) {
if (currentNode === success.data[0].ADMINUSERNODENAMES[i].adminNodeName) {
this.newNodeCreateForm.patchValue(success.data[0].ADMINUSERNODENAMES[i]);
this.adminProtocolDropdownConf.selectedOption = success.data[0].ADMINUSERNODENAMES[i].adminProtocol.toUpperCase();
}
}
this.headerConf.primaryHeadingBold = this.translate.instant('adminListing.createNode.editPageHeader');
});
}
}
Editor is loading...