1- ManageIQ . angular . app . controller ( 'dialogEditorController' , [ '$window' , 'miqService' , 'DialogEditor' , 'DialogEditorHttp' , 'DialogValidation' , 'dialogIdAction' , function ( $window , miqService , DialogEditor , DialogEditorHttp , DialogValidation , dialogIdAction ) {
1+ ManageIQ . angular . app . controller ( 'dialogEditorController' , [ '$window' , 'miqService' , 'DialogEditor' , 'DialogEditorHttp' , 'DialogValidation' , 'dialogIdAction' , 'automationKeys' , 'emsWorkflowsEnabled' , function ( $window , miqService , DialogEditor , DialogEditorHttp , DialogValidation , dialogIdAction , automationKeys , emsWorkflowsEnabled ) {
22 var vm = this ;
33
44 vm . saveButtonDisabled = false ;
@@ -9,8 +9,13 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
99 vm . treeOptions = {
1010 load : DialogEditorHttp . treeSelectorLoadData ,
1111 lazyLoad : DialogEditorHttp . treeSelectorLazyLoadData ,
12+ loadAvailableWorkflows : DialogEditorHttp . loadAvailableWorkflows ,
13+ loadWorkflow : DialogEditorHttp . loadWorkflow ,
14+ emsWorkflowsEnabled,
1215 } ;
1316
17+ vm . dropDownEntryPoints = requestAutomationKeys ( ) ;
18+
1419 function requestDialogId ( ) {
1520 return JSON . parse ( dialogIdAction ) . id ;
1621 }
@@ -19,6 +24,11 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
1924 return JSON . parse ( dialogIdAction ) . action ;
2025 }
2126
27+ /** Function to get the automation_keys from editor.html.haml which gets the values from AutomationMixin */
28+ function requestAutomationKeys ( ) {
29+ return JSON . parse ( automationKeys ) ;
30+ }
31+
2232 if ( requestDialogAction ( ) === 'new' ) {
2333 var dialogInitContent = {
2434 'content' : [ {
@@ -53,13 +63,31 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
5363 }
5464 }
5565
66+ /** Function to set the automation_type as 'embedded_automate' / 'embedded_workflow'.
67+ * Also deletes few attributes from resource_action based on the selected automation_type.
68+ */
69+ function setAutomationFields ( field ) {
70+ const { automate, workflow } = vm . dropDownEntryPoints ;
71+ const automationFields = field . resource_action . configuration_script_id
72+ ? { automationType : workflow . key , resetFields : automate . fields }
73+ : { automationType : automate . key , resetFields : workflow . fields } ;
74+
75+ field . automation_type = automationFields . automationType ;
76+ automationFields . resetFields . forEach ( ( item ) => {
77+ if ( field . resource_action . hasOwnProperty ( item ) ) {
78+ delete field . resource_action [ item ] ;
79+ }
80+ } ) ;
81+ }
82+
5683 function translateResponderNamesToIds ( dialog ) {
5784 var dynamicFields = [ ] ;
5885 var allFields = [ ] ;
5986
6087 _ . forEach ( dialog . dialog_tabs , function ( tab ) {
6188 _ . forEach ( tab . dialog_groups , function ( group ) {
6289 _ . forEach ( group . dialog_fields , function ( field ) {
90+ setAutomationFields ( field ) ;
6391 if ( field . dynamic === true ) {
6492 dynamicFields . push ( field ) ;
6593 }
@@ -149,7 +177,8 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
149177 dialog_tabs : [ ] ,
150178 } ,
151179 } ;
152- dialogData . content . dialog_tabs = _ . cloneDeepWith ( DialogEditor . getDialogTabs ( ) , customizer ) ;
180+ const dialogTabs = _ . cloneDeepWith ( DialogEditor . getDialogTabs ( ) , customizer ) ;
181+ dialogData . content . dialog_tabs = reconfigureDialogTabs ( dialogTabs ) ;
153182 } else {
154183 action = 'create' ;
155184 dialogId = '' ;
@@ -159,12 +188,31 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
159188 buttons : 'submit,cancel' ,
160189 dialog_tabs : [ ] ,
161190 } ;
162- dialogData . dialog_tabs = _ . cloneDeepWith ( DialogEditor . getDialogTabs ( ) , customizer ) ;
191+ const dialogTabs = _ . cloneDeepWith ( DialogEditor . getDialogTabs ( ) , customizer ) ;
192+ dialogData . dialog_tabs = reconfigureDialogTabs ( dialogTabs ) ;
163193 }
164194
165195 DialogEditorHttp . saveDialog ( dialogId , action , dialogData ) . then ( saveSuccess , saveFailure ) ;
166196 }
167197
198+ /** Fnuction to remove the automation_type and workflow_name attributes from field's resource_action
199+ * as they are not required to be processed in backend. */
200+ function reconfigureDialogTabs ( dialogTabs ) {
201+ dialogTabs . forEach ( ( tab ) => {
202+ tab . dialog_groups . forEach ( ( group ) => {
203+ group . dialog_fields . forEach ( ( field ) => {
204+ if ( field . hasOwnProperty ( 'automation_type' ) ) {
205+ delete field . automation_type ;
206+ }
207+ if ( field . resource_action . hasOwnProperty ( 'workflow_name' ) ) {
208+ delete field . resource_action . workflow_name ;
209+ }
210+ } ) ;
211+ } ) ;
212+ } ) ;
213+ return dialogTabs ;
214+ }
215+
168216 function dismissChanges ( ) {
169217 if ( confirm ( __ ( 'Abandon changes?' ) ) ) {
170218 DialogEditor . clearSessionStorage ( DialogEditor . getDialogId ( ) ) ;
0 commit comments