import { Component, OnInit, Output, EventEmitter, ViewChild, Input } from '@angular/core'; import { InitiatorPopupComponent } from '../initiator-popup/initiator-popup.component'; import { StepsPopupComponent } from '../steps-popup/steps-popup.component'; import { AutomationService } from '../../../shared/service/automation.service'; import { IStep } from '../../../shared/core/automation/IStep'; import { TreeNode, Message, MessageService } from 'primeng/api'; import { CombineModels } from '../../../shared/core/automation/CombineModels'; import { IInitiator } from '../../../shared/core/automation/IInitiator'; import { OverlayPanel } from 'primeng/primeng'; @Component({ selector: 'app-new-automation', templateUrl: './new-automation.component.html', styleUrls: ['./new-automation.component.css'] }) export class NewAutomationComponent implements OnInit { @Output() bindCloseAddNew: EventEmitter = new EventEmitter(); @ViewChild(InitiatorPopupComponent) initiatorPopupComponent: InitiatorPopupComponent; @ViewChild(StepsPopupComponent) stepsPopupComponent: StepsPopupComponent; @Input() automationId: number; @Input() companyId:number; showInintiatorPopup: boolean = false; showStepsPopup: boolean = false; stepList: IStep[]; combineModelList: CombineModels[] = []; combineModel: CombineModels = {}; stepTree: TreeNode[]; unassignedList: TreeNode[]; selectedNode: TreeNode; draggedItem: any; messages: Message[]; initiatorTreeNode: TreeNode; selectedItem: TreeNode; sendData: any; initiators: IInitiator[] = []; lastNodeKey: number = 0; btnType: string = ""; automationTitle: string = ""; loadingBar: boolean = false; selectedModelIndex: number; constructor(private automationService: AutomationService, private messageService: MessageService) { } ngOnInit() { this.PopulateSteps(); this.GetInitiators(); // for new automation if (this.automationId == 0) { this.initiatorTreeNode = { key: "1", type: 'person', styleClass: 'ui-person', expanded: true, data: { id: 1, name: 'Select an initiator...', modelIndex: 0 }, children: [] }; this.lastNodeKey = 1; this.stepTree = [this.initiatorTreeNode]; this.combineModel = {}; this.combineModel.InitiatorId = 0; this.combineModel.id = 1; this.combineModel.parentId = "0"; this.combineModel.nodeType = "initiator"; this.combineModelList.push(this.combineModel); } // for existing automation else { this.automationService.GetAutomation(this.automationId, this.companyId).subscribe(flow => { this.automationTitle = flow.AutomationTitle; this.combineModelList = flow.CombineModelList; this.combineModelList[0].InitiatorId = flow.InitiatorId; this.initiatorTreeNode = { key: "1", type: 'person', styleClass: 'ui-person', expanded: true, data: { id: flow.InitiatorId, name: "", modelIndex: 0, parentId: 0 }, children: [] }; this.lastNodeKey = 2; this.stepTree = [this.initiatorTreeNode]; this.selectedItem = this.initiatorTreeNode; this.combineModel = {}; this.combineModel.id = 1; this.combineModel.parentId = "0"; this.combineModel.nodeType = "initiator"; //this.combineModelList.push(this.combineModel); //flow.CombineModelList.splice(0,1); if (flow.CombineModelList.length > 1) { flow.CombineModelList.forEach(element => { if (element.StepCode != undefined && element.StepCode != null && element.StepCode != '') { this.lastNodeKey = element.id; var stepNode = { key: element.id.toString(), type: 'person', styleClass: 'ui-person', expanded: true, data: { id: 0, name: this.GetStepName(element), modelIndex: flow.CombineModelList.findIndex(x => x == element) }, children: [] } this.combineModel.nodeType = "steps"; this.combineModel.parentId = this.selectedItem.key; this.combineModel.id = this.lastNodeKey; //this.pushToTree(stepNode, this.stepTree); var parent = this.stepTree.find(x => x.key == element.parentId); if (parent != undefined && parent != null) { parent.children.push(stepNode); } else { this.stepTree.forEach(child => { this.pushToTreeEdit(stepNode, child.children, element.parentId); }) } } }); } // Get initiator name if (flow.InitiatorCode == "CDI") { var combineContactCriteria = ""; flow.CombineModelList[0].iContacts.contactList.forEach(element => { combineContactCriteria += element.Name + "
"; }); this.stepTree[0].data.name = "Contact details update:
" + combineContactCriteria; } else if (flow.InitiatorCode == "PAI") { this.automationService.GetCriteria(flow.InitiatorCode, this.companyId).subscribe(list => { var criteriaName = list.find(x => x.Id == flow.CombineModelList[0].iProject.CriteriaId).Name this.stepTree[0].data.name = "Projects activities:
" + criteriaName; }); } else if (flow.InitiatorCode == "EAI") { this.automationService.GetCriteria(flow.InitiatorCode, this.companyId).subscribe(list => { var criteriaName = list.find(x => x.Id == flow.CombineModelList[0].iEmailActivity.CriteriaId).Name this.stepTree[0].data.name = "Email activities:
" + criteriaName; }); } else if (flow.InitiatorCode == "NAI") { this.automationService.GetCriteria(flow.InitiatorCode, this.companyId).subscribe(list => { var criteriaName = list.find(x => x.Id == flow.CombineModelList[0].iNote.CriteriaId).Name this.stepTree[0].data.name = "Notes activities:
" + criteriaName; }); } else if (flow.InitiatorCode == "TAI") { this.automationService.GetCriteria(flow.InitiatorCode, this.companyId).subscribe(list => { var criteriaName = list.find(x => x.Id == flow.CombineModelList[0].iTask.CriteriaId).Name this.stepTree[0].data.name = "Task activities:
" + criteriaName; }); } else if (flow.InitiatorCode == "DCI") { this.automationService.GetCriteria(flow.InitiatorCode, this.companyId).subscribe(list => { var criteriaName = list.find(x => x.Id == flow.CombineModelList[0].iDataInfoCollection.CriteriaId).Name this.stepTree[0].data.name = "Data/info collection automation activities:
" + criteriaName; }); } }) } } GetInitiators() { this.automationService.GetInitiators(this.companyId).subscribe(initiators => { this.initiators = initiators; }); } // Get initiator name GetInitiatorName(initiator: CombineModels, InitiatorCode: string) { var initiatorName = ""; if (InitiatorCode == "CDI") { var combineContactCriteria = ""; initiator.iContacts.contactList.forEach(element => { combineContactCriteria += element.Name + "
"; }); initiatorName = "Contact details update:
" + combineContactCriteria; return initiatorName; } else if (InitiatorCode == "PAI") { this.automationService.GetCriteria(InitiatorCode, this.companyId).subscribe(list => { var criteriaName = list.find(x => x.Id == initiator.iProject.CriteriaId).Name initiatorName = "Projects activities:
" + criteriaName; return initiatorName; }); } else if (InitiatorCode == "EAI") { initiatorName = "Email activities:
"; return initiatorName; } else if (InitiatorCode == "NAI") { initiatorName = "Notes activities:
"; return initiatorName; } else if (InitiatorCode == "TAI") { initiatorName = "Task activities:
"; return initiatorName; } else if (InitiatorCode == "DCI") { initiatorName = "Data/info collection automation activities:
"; return initiatorName; } } // Get Step name GetStepName(step: CombineModels) { var stepName = ""; if (step.StepCode == 'DDS') { stepName = "Delay Duration:
" + step.iDelayTime.DelayDay + " days after" } else if (step.StepCode == 'ENS') { stepName = "Send email notification"; } else if (step.StepCode == 'INS') { stepName = "Send Internal notification"; } else if (step.StepCode == 'CTS') { stepName = "Create task"; } else if (step.StepCode == 'CNS') { stepName = "Create note"; } return stepName; } // CreateInitiatorStep(initiatorName: string, activityInitiator: string) { // const p: HTMLParagraphElement = this.renderer.createElement('div'); // p.innerHTML = ` //
//
//
//
// ` + initiatorName + ` //
//
// ` + activityInitiator + ` //
//
//
//
// `; // this.renderer.appendChild(this.div.nativeElement, p); // } //populate steps dropdown PopulateSteps() { this.automationService.GetStepList("CRM",this.companyId).subscribe(steps => { this.stepList = steps; }); } // cancel automation button click cancelAutomation() { this.bindCloseAddNew.emit(false); } // close initiator popup rebindCloseInitiator(isUpdate) { if (isUpdate == true) { this.showInintiatorPopup = false; this.combineModelList[0].iContacts = undefined; this.combineModelList[0].iProject = undefined; this.combineModelList[0].iEmailActivity = undefined; this.combineModelList[0].iNote = undefined; this.combineModelList[0].iTask = undefined; this.combineModelList[0].iDataInfoCollection = undefined; if (this.initiatorPopupComponent.showContactDetails) { var combineContactCriteria = ""; this.initiatorPopupComponent.contactActivity.contactList.forEach(element => { combineContactCriteria += element.Name + "
"; }); this.stepTree[0].data.id = this.initiatorPopupComponent.contactActivity.Id; this.stepTree[0].data.name = "Contact details update:
" + combineContactCriteria; this.combineModelList[0].iContacts = this.initiatorPopupComponent.contactActivity; } else if (this.initiatorPopupComponent.showProjectActivity) { this.stepTree[0].data.id = this.initiatorPopupComponent.projectActivity.Id; this.stepTree[0].data.name = "Projects activities:
Project due date < " + this.initiatorPopupComponent.projectActivity.DueDays + " business days"; this.combineModelList[0].iProject = this.initiatorPopupComponent.projectActivity; } else if (this.initiatorPopupComponent.showEmailActivity) { this.stepTree[0].data.id = this.initiatorPopupComponent.emailActivity.Id; this.stepTree[0].data.name = "Email activities:
" + this.initiatorPopupComponent.emailActivity.defaultEmailInitiator.name; this.combineModelList[0].iEmailActivity = this.initiatorPopupComponent.emailActivity; } else if (this.initiatorPopupComponent.showNoteActivity) { this.stepTree[0].data.id = this.initiatorPopupComponent.noteActivity.Id; this.stepTree[0].data.name = "Notes activities:
" + this.initiatorPopupComponent.noteActivity.defaultNoteInitiator.name; this.combineModelList[0].iNote = this.initiatorPopupComponent.noteActivity; } else if (this.initiatorPopupComponent.showTaskActivity) { this.stepTree[0].data.id = this.initiatorPopupComponent.taskActivity.Id; this.stepTree[0].data.name = "Task activities:
" + this.initiatorPopupComponent.taskActivity.defaultTaskInitiator.name; this.combineModelList[0].iTask = this.initiatorPopupComponent.taskActivity; } else if (this.initiatorPopupComponent.showDataInfoCollectionActivity) { this.stepTree[0].data.id = this.initiatorPopupComponent.dataInfoCollectionActivity.Id; this.stepTree[0].data.name = "Data/info collection automation activities:
" + this.initiatorPopupComponent.dataInfoCollectionActivity.defaultDataInfoCollectionInitiator.name; this.combineModelList[0].iDataInfoCollection = this.initiatorPopupComponent.dataInfoCollectionActivity; } this.combineModelList[0].InitiatorId = this.initiatorPopupComponent.criteriaList[0].InitiatorId; } this.initiatorPopupComponent.showContactDetails = false; this.initiatorPopupComponent.showProjectActivity = false; this.initiatorPopupComponent.showEmailActivity = false; this.initiatorPopupComponent.showNoteActivity = false; this.initiatorPopupComponent.showTaskActivity = false; this.initiatorPopupComponent.showDataInfoCollectionActivity = false; console.log(this.combineModelList); } // show project activities popup showProjectActivitiesInitiator() { this.automationService.GetCriteria('PAI', this.companyId).subscribe(list => { // Number '8' refers to Projects Details Initiator in db // bind criteria list this.initiatorPopupComponent.criteriaList = list; this.showInintiatorPopup = true; this.initiatorPopupComponent.showProjectActivity = true; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; this.initiatorPopupComponent.PopulateProjectActivityDetails(this.automationId, currentInitiator); } else { this.initiatorPopupComponent.PopulateProjectActivityDetails(0, null); } // console.log(this.initiatorPopupComponent.criteriaList); }); } // show Contact Details popup showContactDetailsInitiator() { this.automationService.GetCriteria('CDI', this.companyId).subscribe(list => { // Number '2' refers to Contact Details Initiator in db // bind criteria list this.initiatorPopupComponent.criteriaList = list; this.showInintiatorPopup = true; this.initiatorPopupComponent.showContactDetails = true; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; if (currentInitiator.iContacts != undefined && currentInitiator.iContacts != null) { currentInitiator.iContacts.contactList.forEach(contact => { this.initiatorPopupComponent.criteriaList.find(x => x.Id == contact.CriteriaId).Checked = true; }); } } }); } // show Email Activity popup showEmailActivityInitiator() { this.automationService.GetCriteria('EAI', this.companyId).subscribe(list => { // Number '4' refers to Email Activity Initiator in db // bind criteria list this.initiatorPopupComponent.criteriaList = list; this.showInintiatorPopup = true; this.initiatorPopupComponent.showEmailActivity = true; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; this.initiatorPopupComponent.PopulateEmailActivityDetails(this.automationId, currentInitiator); } else { this.initiatorPopupComponent.PopulateEmailActivityDetails(0, null); } }); } // show Note Activity Popup showNoteActivityInitiator() { this.automationService.GetCriteria('NAI', this.companyId).subscribe(list => { // Number '5' refers to Note Activity Initiator in db this.initiatorPopupComponent.criteriaList = list; this.showInintiatorPopup = true; this.initiatorPopupComponent.showNoteActivity = true; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; this.initiatorPopupComponent.PopulateNoteActivityDetails(this.automationId, currentInitiator); } else { this.initiatorPopupComponent.PopulateNoteActivityDetails(0, null); } // console.log(list); }); } // show Task Activity Popup showTaskActivityInitiator() { this.automationService.GetCriteria('TAI', this.companyId).subscribe(list => { // Number '7' refers to Task Activity Initiator in db this.initiatorPopupComponent.criteriaList = list; this.showInintiatorPopup = true; this.initiatorPopupComponent.showTaskActivity = true; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; this.initiatorPopupComponent.PopulateTaskActivityDetails(this.automationId, currentInitiator); } else { this.initiatorPopupComponent.PopulateTaskActivityDetails(0, null); } // console.log(list); }); } // show Data Info Collection Activity Popup showDataInfoCollectionActivitiesInitiator() { this.automationService.GetCriteria('DCI', this.companyId).subscribe(list => { // Number '9' refers to Data Info Collection Activity Initiator in db this.initiatorPopupComponent.criteriaList = list; this.showInintiatorPopup = true; this.initiatorPopupComponent.showDataInfoCollectionActivity = true; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; this.initiatorPopupComponent.PopulateDataInfoCollectionActivityDetails(this.automationId, currentInitiator); } else { this.initiatorPopupComponent.PopulateDataInfoCollectionActivityDetails(0, null); } console.log(list); }); } // close initiator popup rebindCloseStep(isUpdate) { if (isUpdate == true) { this.combineModel = {}; if (this.stepsPopupComponent.showCreateNote) { this.combineModel.iNotes = this.stepsPopupComponent.createNote; this.CreateStepNode(this.stepsPopupComponent.createNote.Id, "Create note"); } else if (this.stepsPopupComponent.showInternalNotification) { this.combineModel.iNotification = this.stepsPopupComponent.sendInternalNotification; this.CreateStepNode(this.stepsPopupComponent.sendInternalNotification.NotiicationId, "Send Internal notification"); } else if (this.stepsPopupComponent.showEmailNotification) { this.combineModel.iEmail = this.stepsPopupComponent.sendEmailNotification; this.CreateStepNode(this.stepsPopupComponent.sendEmailNotification.Id, "Send email notification"); } else if (this.stepsPopupComponent.showSetDelayDuration) { this.combineModel.iDelayTime = this.stepsPopupComponent.stepDelayTime; this.CreateStepNode(this.stepsPopupComponent.stepDelayTime.Id, "Delay Duration:
" + this.stepsPopupComponent.stepDelayTime.DelayDay + " days after"); } else if (this.stepsPopupComponent.showCreateTask) { this.combineModel.iCreateTask = this.stepsPopupComponent.createtask; this.CreateStepNode(this.stepsPopupComponent.createtask.Id, "Create task"); } } this.showStepsPopup = false; this.stepsPopupComponent.showCreateNote = false; this.stepsPopupComponent.showInternalNotification = false; this.stepsPopupComponent.showEmailNotification = false; this.stepsPopupComponent.showSetDelayDuration = false; this.stepsPopupComponent.showCreateTask = false; this.stepsPopupComponent.Heading = ""; this.stepsPopupComponent.ResetAllFields(); } CreateStepNode(moduleId, name) { var lastnodekay = ++this.lastNodeKey; var stepNode = { key: lastnodekay.toString(), type: 'person', styleClass: 'ui-person', expanded: true, data: { id: moduleId, name: name,modelIndex: this.combineModelList.length}, children: [] } this.combineModel.nodeType = "steps"; this.combineModel.parentId = this.selectedItem.key; if (this.btnType == "editStep") { // console.log(this.stepTree.find(x => x.key == this.selectedItem.key)); this.changeNodeName(this.stepTree, name); this.combineModel.parentId = this.combineModelList.find(x => x.id == Number(this.selectedItem.key)).parentId; this.combineModelList[this.combineModelList.findIndex(c => c.id == Number(this.selectedItem.key))] = this.combineModel; } else { this.combineModel.id = lastnodekay; this.pushToTree(stepNode, this.stepTree); this.combineModelList.push(this.combineModel); } console.log(this.combineModelList); console.log(this.stepTree); } changeNodeName(tree: TreeNode[], name) { var parent = tree.find(x => x.key == this.selectedItem.key); if (parent != undefined && parent != null) { this.combineModel.id = Number(parent.key); parent.data.name = name; } else { // console.log(tree[0].children); // this.recuringMethod(this.stepTree[0].children, name); tree.forEach(element => { this.changeNodeName(element.children, name); }); } } //runs when click on a node onNodeSelect(event) { alert(event); } dragStart(item: any) { this.draggedItem = item; //console.log(this.draggedItem); } //initial item dopping to start design organisation chart dropInit() { if (this.stepTree.length == 0) { this.stepTree.push(this.draggedItem); this.unassignedList.splice(this.unassignedList.findIndex(x => x.key == this.draggedItem.key), 1); } } selectData(event, overlaypanel: OverlayPanel, node: TreeNode, btnType: string) { overlaypanel.toggle(event); this.selectedItem = node; this.btnType = btnType; this.selectedModelIndex = node.data.modelIndex; } selectedInitiator(item) { // this.stepTree[0].data.id = item.Id; // this.stepTree[0].data.name = item.Title; if (item.Code == "CDI") { this.showContactDetailsInitiator(); } else if (item.Code == "EAI") { this.showEmailActivityInitiator(); } else if (item.Code == "NAI") { this.showNoteActivityInitiator(); } else if (item.Code == "TAI") { this.showTaskActivityInitiator(); } else if (item.Code == "PAI") { this.showProjectActivitiesInitiator(); } else if (item.Code == "DCI") { this.showDataInfoCollectionActivitiesInitiator(); } } // API Call for save and update automation addAutomation() { if (this.validateFields()) { this.loadingBar = true; if (this.automationId > 0) { this.automationService.EditAutomationDetails(this.combineModelList, this.automationTitle, this.automationId, this.companyId).subscribe(x => { this.loadingBar = false; if (x.result == "success") { this.messageService.add({ key: 'toastKey', severity: 'success', summary: 'All Good!', detail: 'Automation Updated Successfully' }); this.ResetAll(); } else if (x.result == "failed") { this.messageService.add({ key: 'toastKey', severity: 'error', summary: 'Something went wrong!', detail: 'Error While Updating Automation' }); } }); } else { this.automationService.SaveAutomationDetails(this.combineModelList, this.automationTitle,this.companyId).subscribe(x => { this.loadingBar = false; if (x.result == "success") { this.messageService.add({ key: 'toastKey', severity: 'success', summary: 'All Good!', detail: 'Automation Created Successfully' }); this.ResetAll(); } else if (x.result == "failed") { this.messageService.add({ key: 'toastKey', severity: 'error', summary: 'Something went wrong!', detail: 'Error While Creating Automation' }); } }); } } } ResetAll() { setTimeout( () => {this.cancelAutomation()}, 2000); } validateFields() { let flag = false; if (this.automationTitle == "") { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Field Empty', detail: 'Please Type a Title' }); } else if (this.combineModelList[0].InitiatorId < 1) { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Initiator Empty', detail: 'Need an Initiator to Continue' }); } else { flag = true; } return flag; } selectedStep(item) { this.showStepsPopup = true; if (item.Code == 'DDS') { this.stepsPopupComponent.showCreateNote = false; this.stepsPopupComponent.showInternalNotification = false; this.stepsPopupComponent.showEmailNotification = false; this.stepsPopupComponent.showSetDelayDuration = true; this.stepsPopupComponent.showCreateTask = false; this.stepsPopupComponent.Heading = "Set delay duration"; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; if (currentInitiator.iDelayTime != undefined && currentInitiator.iDelayTime != null) { this.stepsPopupComponent.stepDelayTime = currentInitiator.iDelayTime; } } } else if (item.Code == 'ENS') { this.stepsPopupComponent.showCreateNote = false; this.stepsPopupComponent.showInternalNotification = false; this.stepsPopupComponent.showEmailNotification = true; this.stepsPopupComponent.showSetDelayDuration = false; this.stepsPopupComponent.showCreateTask = false; this.stepsPopupComponent.Heading = " Send email notification"; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; if (currentInitiator.iEmail != undefined && currentInitiator.iEmail != null) { this.stepsPopupComponent.selectedEmailNotificationFromDetails = currentInitiator.iEmail.FromDetails; this.stepsPopupComponent.selectedEmailNotificationFromEmailDetails = currentInitiator.iEmail.FromEmailDetails; this.stepsPopupComponent.selectedEmailNotificationToDetails = currentInitiator.iEmail.ToDetails.split(','); this.stepsPopupComponent.selectedEmailNotificationSubjectDetails = currentInitiator.iEmail.SubjectDetails; this.stepsPopupComponent.isIncludeWordDocument = currentInitiator.iEmail.IsIncludeWordDocument; this.stepsPopupComponent.isIncludePDFDocument = currentInitiator.iEmail.IsIncludePDFDocument; this.stepsPopupComponent.notificationContentTxt = currentInitiator.iEmail.Content; } } } else if (item.Code == 'INS') { this.stepsPopupComponent.showCreateNote = false; this.stepsPopupComponent.showInternalNotification = true; this.stepsPopupComponent.showEmailNotification = false; this.stepsPopupComponent.showSetDelayDuration = false; this.stepsPopupComponent.showCreateTask = false; this.stepsPopupComponent.Heading = "Send internal notification"; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; if (currentInitiator.iNotification != undefined && currentInitiator.iNotification != null) { this.stepsPopupComponent.internalNotiToIds = currentInitiator.iNotification.NotiicationToDetails.split(','); this.stepsPopupComponent.selectedInternalNotificationSubjectDetails = currentInitiator.iNotification.SubjectDetails; this.stepsPopupComponent.notificationContentTxt = currentInitiator.iNotification.NotificationContent; this.stepsPopupComponent.showSelectedContactForInternalNotify(currentInitiator.iNotification.NotiicationToDetails); } } } else if (item.Code == 'CTS') { this.stepsPopupComponent.showCreateNote = false; this.stepsPopupComponent.showInternalNotification = false; this.stepsPopupComponent.showEmailNotification = false; this.stepsPopupComponent.showSetDelayDuration = false; this.stepsPopupComponent.showCreateTask = true; this.stepsPopupComponent.Heading = "Create task"; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; if (currentInitiator.iCreateTask != undefined && currentInitiator.iCreateTask != null) { this.stepsPopupComponent.createtask = currentInitiator.iCreateTask; this.stepsPopupComponent.createtask.contactsUnderTask = []; this.stepsPopupComponent.createtask.contactsUnderTaskIds = []; this.stepsPopupComponent.showSelectedContactForTask(currentInitiator.iCreateTask.TaskUnder); } } } else if (item.Code == 'CNS') { this.stepsPopupComponent.showCreateNote = true; this.stepsPopupComponent.showInternalNotification = false; this.stepsPopupComponent.showEmailNotification = false; this.stepsPopupComponent.showSetDelayDuration = false; this.stepsPopupComponent.showCreateTask = false; this.stepsPopupComponent.Heading = "Create note"; this.stepsPopupComponent.noteCreatedUnder = []; this.stepsPopupComponent.noteCreatedUnderIds = []; if (this.automationId > 0) { var currentInitiator = this.combineModelList[this.selectedModelIndex]; if (currentInitiator.iNotes != undefined && currentInitiator.iNotes != null) { this.stepsPopupComponent.noteCreatedUnder = currentInitiator.iNotes.noteCreateUnder.split(','); // this.stepsPopupComponent.selectedLogNote = currentInitiator.iNotes.NotesTypesId; this.stepsPopupComponent.noteContentTxt = currentInitiator.iNotes.Description; this.stepsPopupComponent.TaskCreate = currentInitiator.iNotes.IsFollowUp; this.stepsPopupComponent.followUpDay = currentInitiator.iNotes.FollowUpDay; this.stepsPopupComponent.showSelectedStaff(currentInitiator.iNotes.AssociateCount); this.stepsPopupComponent.selectedLogNote = this.stepsPopupComponent.lognote.find(x=>x.value.id ==currentInitiator.iNotes.NotesTypesId ).value; this.stepsPopupComponent.showSelectedContactForNote(currentInitiator.iNotes.noteCreateUnder); } } } this.stepsPopupComponent.stepId = item.Id; } pushToTree(node: TreeNode, tree: TreeNode[]) { var parent = tree.find(x => x.key == this.selectedItem.key); if (parent != undefined && parent != null) { parent.children.push(node); } else { tree.forEach(element => { this.pushToTree(node, element.children); }); } } pushToTreeEdit(node: TreeNode, tree: TreeNode[], parentId: string) { var parent = tree.find(x => x.key == parentId); if (parent != undefined && parent != null) { parent.children.push(node); } else { tree.forEach(element => { this.pushToTreeEdit(node, element.children, parentId); }); } } deleteData(node: TreeNode) { this.removeFromTree(node, this.stepTree); console.log(this.combineModelList); } removeFromTree(node: TreeNode, tree: TreeNode[]) { if (tree.find(x => x.key == node.key) != null||undefined) { tree.splice(tree.findIndex(x => x.key == node.key), 1); this.combineModelList = this.combineModelList.filter(c => c.id != Number(node.key)); this.combineModelList = this.combineModelList.filter(c => c.parentId != node.key); } else { tree.forEach(element => { this.removeFromTree(node, element.children); }); } } }