-
diff --git a/src/dialog-editor/components/modal-field/modalFieldComponent.ts b/src/dialog-editor/components/modal-field/modalFieldComponent.ts
index 992d51ff07..6af625a8a6 100644
--- a/src/dialog-editor/components/modal-field/modalFieldComponent.ts
+++ b/src/dialog-editor/components/modal-field/modalFieldComponent.ts
@@ -21,15 +21,56 @@ class ModalFieldController extends ModalController {
public validation: any;
public $onInit() {
+
+ /** Function to load the selected workflow if configuration_script_id is available. */
+ if (this.modalData.resource_action && this.modalData.resource_action.configuration_script_id) {
+ this.loadWorkflow(this.modalData.resource_action.configuration_script_id);
+ };
+
this.treeOptions = {
...this.treeOptions,
show: false,
includeDomain: false,
data: null,
+ automationType: null,
+ automationTypes: {
+ automate: 'embedded_automate',
+ workflow: 'embedded_workflow',
+ },
+ emsWorkflowsEnabled: this.treeOptions.emsWorkflowsEnabled === 'true' ? true : false,
+
+ /** Function to reset the automation entries when the Automation Type drop down is changed. */
+ resetAutomationEntries: () => {
+ const resetFields = {
+ automate: ['ae_namespace', 'ae_class', 'ae_instance', 'ae_message'],
+ workflow: ['configuration_script_id', 'workflow_name'],
+ };
+
+ if (this.modalData.resource_action) {
+ const isEmbeddedAutomate = this.modalData.automation_type === this.treeOptions.automationTypes.automate;
+ const resetEntries = isEmbeddedAutomate ? resetFields.workflow : resetFields.automate;
+ resetEntries.forEach((item) => {
+ if (this.modalData.resource_action.hasOwnProperty(item)) {
+ this.modalData.resource_action = {
+ ...this.modalData.resource_action,
+ [item]: '',
+ };
+ }
+ });
+ }
+ },
+
+ /** Function to reset the modalData while changin the Automation Type. */
+ onAutomationTypeChange: () => {
+ this.treeOptions.automationType = this.modalData.automation_type;
+ this.treeOptions.resetAutomationEntries();
+ },
+ /** Function to open the modal box and load the automate tree. */
toggle: () => {
this.treeOptions.show = ! this.treeOptions.show;
+ this.treeOptions.automationType = this.treeOptions.automationTypes.automate;
if (this.treeOptions.show) {
const fqname = this.showFullyQualifiedName(this.modalData.resource_action) || null;
@@ -41,6 +82,21 @@ class ModalFieldController extends ModalController {
}
},
+ /** Function to open the modal box and load the workflows list. */
+ toggleWorkflows: () => {
+ this.treeOptions.show = ! this.treeOptions.show;
+ this.treeOptions.automationType = this.treeOptions.automationTypes.workflow;
+
+ if (this.treeOptions.show) {
+ this.treeOptions.loadAvailableWorkflows().then((data) => {
+ this.treeOptions.data = data.resources.filter((item: any) => item.payload);
+ const workflow = this.treeOptions.data.find((item) => item.id === this.modalData.resource_action.configuration_script_id);
+ this.treeOptions.selected = workflow ? workflow.name : null;
+ });
+ }
+ },
+
+ /** Function to handle the onclick event of an item in tree. */
onSelect: (node) => {
this.treeSelectorSelect(node, this.modalData);
}
@@ -48,31 +104,65 @@ class ModalFieldController extends ModalController {
}
public showFullyQualifiedName(resourceAction) {
- if (resourceAction.ae_namespace && resourceAction.ae_class && resourceAction.ae_instance) {
+ if (!resourceAction) {
+ return '';
+ }
+ const actionKeys = ['ae_namespace', 'ae_class', 'ae_instance'];
+ const keysPresent = actionKeys.every((item) => resourceAction.hasOwnProperty(item));
+
+ if (keysPresent && resourceAction.ae_namespace && resourceAction.ae_class && resourceAction.ae_instance) {
return `${resourceAction.ae_namespace}/${resourceAction.ae_class}/${resourceAction.ae_instance}`;
} else {
return '';
}
}
- public treeSelectorSelect(node, elementData) {
+ /** Function to extract the values needed for embedded_automate during onclick event of an item from the tree */
+ public onEmbeddedAutomateSelect(node, elementData) {
const fqname = node.fqname.split('/');
if (this.treeOptions.includeDomain === false) {
fqname.splice(1, 1);
}
+ if (elementData.resource_action) {
+ elementData.resource_action = {
+ ...elementData.resource_action,
+ ae_instance: fqname.pop(),
+ ae_class: fqname.pop(),
+ ae_namespace: fqname.filter(String).join('/'),
+ };
+ }
+ }
- elementData.resource_action = {
- ...elementData.resource_action,
- ae_instance: fqname.pop(),
- ae_class: fqname.pop(),
- ae_namespace: fqname.filter(String).join('/'),
- };
+ /** Function to extract the values needed for embedded_workflow during onclick event of an item from the list */
+ public onEmbeddedWorkflowsSelect(workflow, elementData) {
+ if (elementData.resource_action) {
+ elementData.resource_action = {
+ ...elementData.resource_action,
+ configuration_script_id: workflow.id,
+ workflow_name: workflow.name,
+ };
+ }
+ }
+ /** Function to extract the values needed for entry points during onclick event of an item from the tree or list */
+ public treeSelectorSelect(node, elementData) {
+ if (this.treeOptions.automationType === this.treeOptions.automationTypes.automate) {
+ this.onEmbeddedAutomateSelect(node, elementData);
+ } else if (this.treeOptions.automationType === this.treeOptions.automationTypes.workflow) {
+ this.onEmbeddedWorkflowsSelect(node, elementData);
+ }
this.treeOptions.show = false;
}
public modalFieldIsValid() {
return this.validation.validateField(this.modalData);
}
+
+ /** Function to load a selected workflow. */
+ public loadWorkflow(id: number) {
+ this.treeOptions.loadWorkflow(id).then((workflow) => {
+ this.modalData.resource_action.workflow_name = workflow.name;
+ });
+ }
}
diff --git a/src/dialog-editor/components/modal/modalComponent.ts b/src/dialog-editor/components/modal/modalComponent.ts
index d83be498de..faee10226d 100644
--- a/src/dialog-editor/components/modal/modalComponent.ts
+++ b/src/dialog-editor/components/modal/modalComponent.ts
@@ -81,6 +81,13 @@ class ModalController {
}
}
+ /** Function to set automationType in modalFieldData. */
+ private setAutomationType(modalFieldData: any) {
+ const automationType = modalFieldData.resource_action && modalFieldData.resource_action.configuration_script_id ? 'embedded_workflow' : 'embedded_automate';
+ modalFieldData.automation_type = automationType;
+ return modalFieldData;
+ }
+
public loadModalFieldData(tab: number, box: number, field: number) {
if (typeof tab !== 'undefined' &&
typeof box !== 'undefined' &&
@@ -88,7 +95,7 @@ class ModalController {
let tabList = this.DialogEditor.getDialogTabs();
let boxList = tabList[tab];
let fieldList = boxList.dialog_groups[box];
- return fieldList.dialog_fields[field];
+ return this.setAutomationType(fieldList.dialog_fields[field]);
}
}
diff --git a/src/dialog-editor/components/tree-selector/tree-selector.html b/src/dialog-editor/components/tree-selector/tree-selector.html
index 02f57f848b..48f30bf4f2 100644
--- a/src/dialog-editor/components/tree-selector/tree-selector.html
+++ b/src/dialog-editor/components/tree-selector/tree-selector.html
@@ -1,28 +1,53 @@
-
-
-
-
-
-
-
-
-
-