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' , function ( $window , miqService , DialogEditor , DialogEditorHttp , DialogValidation , dialogIdAction , automationKeys ) {
22 var vm = this ;
33
44 vm . saveButtonDisabled = false ;
@@ -9,8 +9,12 @@ 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 ,
1214 } ;
1315
16+ vm . dropDownEntryPoints = requestAutomationKeys ( ) ;
17+
1418 function requestDialogId ( ) {
1519 return JSON . parse ( dialogIdAction ) . id ;
1620 }
@@ -19,6 +23,11 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
1923 return JSON . parse ( dialogIdAction ) . action ;
2024 }
2125
26+ /** Function to get the automation_keys from editor.html.haml which gets the values from AutomationMixin */
27+ function requestAutomationKeys ( ) {
28+ return JSON . parse ( automationKeys ) ;
29+ }
30+
2231 if ( requestDialogAction ( ) === 'new' ) {
2332 var dialogInitContent = {
2433 'content' : [ {
@@ -53,13 +62,31 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
5362 }
5463 }
5564
65+ /** Function to set the automation_type as 'embedded_automate' / 'embedded_workflow'.
66+ * Also deletes few attributes from resource_action based on the selected automation_type.
67+ */
68+ function setAutomationFields ( field ) {
69+ const { automate, workflow } = vm . dropDownEntryPoints ;
70+ const automationFields = field . resource_action . configuration_script_id
71+ ? { automationType : workflow . key , resetFields : automate . fields }
72+ : { automationType : automate . key , resetFields : workflow . fields } ;
73+
74+ field . automation_type = automationFields . automationType ;
75+ automationFields . resetFields . forEach ( ( item ) => {
76+ if ( field . resource_action . hasOwnProperty ( item ) ) {
77+ delete field . resource_action [ item ] ;
78+ }
79+ } ) ;
80+ }
81+
5682 function translateResponderNamesToIds ( dialog ) {
5783 var dynamicFields = [ ] ;
5884 var allFields = [ ] ;
5985
6086 _ . forEach ( dialog . dialog_tabs , function ( tab ) {
6187 _ . forEach ( tab . dialog_groups , function ( group ) {
6288 _ . forEach ( group . dialog_fields , function ( field ) {
89+ setAutomationFields ( field ) ;
6390 if ( field . dynamic === true ) {
6491 dynamicFields . push ( field ) ;
6592 }
@@ -107,16 +134,16 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
107134 }
108135
109136 var beingCloned = null ; // hack that solves recursion problem for cloneDeepWith
110- function customizer ( value ) {
111- var keysToDelete = [ 'active' , '$$hashKey' , 'href' , 'dynamicFieldList' , 'id' ] ;
112- var useCustomizer =
113- ( value !== beingCloned ) &&
114- _ . isObject ( value ) &&
115- keysToDelete . some ( function ( key ) {
116- return key in value ;
117- } ) ;
118-
119- if ( ! useCustomizer ) {
137+ function customizer ( value ) {
138+ var keysToDelete = [ 'active' , '$$hashKey' , 'href' , 'dynamicFieldList' , 'id' ] ;
139+ var useCustomizer =
140+ ( value !== beingCloned ) &&
141+ _ . isObject ( value ) &&
142+ keysToDelete . some ( function ( key ) {
143+ return key in value ;
144+ } ) ;
145+
146+ if ( ! useCustomizer ) {
120147 return undefined ;
121148 }
122149
@@ -149,7 +176,8 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
149176 dialog_tabs : [ ] ,
150177 } ,
151178 } ;
152- dialogData . content . dialog_tabs = _ . cloneDeepWith ( DialogEditor . getDialogTabs ( ) , customizer ) ;
179+ const dialogTabs = _ . cloneDeepWith ( DialogEditor . getDialogTabs ( ) , customizer ) ;
180+ dialogData . content . dialog_tabs = reconfigureDialogTabs ( dialogTabs ) ;
153181 } else {
154182 action = 'create' ;
155183 dialogId = '' ;
@@ -159,12 +187,31 @@ ManageIQ.angular.app.controller('dialogEditorController', ['$window', 'miqServic
159187 buttons : 'submit,cancel' ,
160188 dialog_tabs : [ ] ,
161189 } ;
162- dialogData . dialog_tabs = _ . cloneDeepWith ( DialogEditor . getDialogTabs ( ) , customizer ) ;
190+ const dialogTabs = _ . cloneDeepWith ( DialogEditor . getDialogTabs ( ) , customizer ) ;
191+ dialogData . dialog_tabs = reconfigureDialogTabs ( dialogTabs ) ;
163192 }
164193
165194 DialogEditorHttp . saveDialog ( dialogId , action , dialogData ) . then ( saveSuccess , saveFailure ) ;
166195 }
167196
197+ /** Fnuction to remove the automation_type and workflow_name attributes from field's resource_action
198+ * as they are not required to be processed in backend. */
199+ function reconfigureDialogTabs ( dialogTabs ) {
200+ dialogTabs . forEach ( ( tab ) => {
201+ tab . dialog_groups . forEach ( ( group ) => {
202+ group . dialog_fields . forEach ( ( field ) => {
203+ if ( field . hasOwnProperty ( 'automation_type' ) ) {
204+ delete field . automation_type ;
205+ }
206+ if ( field . resource_action . hasOwnProperty ( 'workflow_name' ) ) {
207+ delete field . resource_action . workflow_name ;
208+ }
209+ } ) ;
210+ } ) ;
211+ } ) ;
212+ return dialogTabs ;
213+ }
214+
168215 function dismissChanges ( ) {
169216 if ( confirm ( __ ( 'Abandon changes?' ) ) ) {
170217 DialogEditor . clearSessionStorage ( DialogEditor . getDialogId ( ) ) ;
0 commit comments