Skip to content

Commit eb77f31

Browse files
committed
Introducing embedded_workflow to dynamic select box in service dialogs
1 parent d425c87 commit eb77f31

File tree

6 files changed

+120
-13
lines changed

6 files changed

+120
-13
lines changed

app/controllers/catalog_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class CatalogController < ApplicationController
22
include AutomateTreeHelper
33
include Mixins::ServiceDialogCreationMixin
44
include Mixins::BreadcrumbsMixin
5+
include Mixins::AutomationMixin
56

67
before_action :check_privileges
78
before_action :get_session_data
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module Mixins
2+
module AutomationMixin
3+
# Returns an object to be reused for passing down to service catalogs(rails) and dialog(angular) form.
4+
# used in catalogs_helper, miq_ae_customization_helper, catalog_controller, editor.html.haml
5+
def automation_types
6+
{
7+
:automate => {
8+
:key => 'embedded_automate',
9+
:label => _('Embedded Automate'),
10+
:fields => ['ae_namespace', 'ae_class', 'ae_instance', 'ae_message', 'ae_attributes'],
11+
},
12+
:workflow => {
13+
:key => 'embedded_workflow',
14+
:label => _('Embedded Workflow'),
15+
:fields => ['configuration_script_id', 'workflow_name'],
16+
},
17+
}
18+
end
19+
20+
# Returns an array of entry point options.
21+
# used in provision_entry_points, retirement_entry_points, reconfigure_entry_points html files
22+
def automation_type_options
23+
options = [["<#{_('No Entry Point')}>", nil]]
24+
options + automation_types.map do |item|
25+
[item[1][:label], item[1][:key]]
26+
end
27+
end
28+
29+
# Returns true if the field holds value 'embedded_automate'
30+
def embedded_automate(field)
31+
field == automation_types[:automate][:key]
32+
end
33+
34+
# Returns true if the field holds value 'embedded_workflow'
35+
def embedded_workflow(field)
36+
field == automation_types[:workflow][:key]
37+
end
38+
39+
# Returns the default automation type 'embedded_automate'
40+
def default_automation_type
41+
automation_types[:automate][:key]
42+
end
43+
end
44+
end

app/helpers/miq_ae_customization_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module MiqAeCustomizationHelper
2+
include Mixins::AutomationMixin
3+
24
def dialog_id_action
35
url = request.parameters
46
if url[:id].present?

app/javascript/oldjs/controllers/dialog_editor/dialog_editor_controller.js

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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());

app/javascript/oldjs/services/dialog_editor_http_service.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,16 @@ ManageIQ.angular.app.service('DialogEditorHttp', ['$http', 'API', function($http
3131
'?expand=resources' +
3232
'&attributes=id,name,description,single_value,children');
3333
};
34+
35+
/** Function to load all available workflows when 'Embedded Workflow' is selected for dynamic field. */
36+
this.loadAvailableWorkflows = () => {
37+
const url = '/api/configuration_script_payloads/?expand=resources';
38+
return API.get(url);
39+
};
40+
41+
/** Function to load a workflow with the provided 'id' */
42+
this.loadWorkflow = (id) => {
43+
const url = `/api/configuration_script_payloads/${id}`;
44+
return API.get(url);
45+
};
3446
}]);

app/views/miq_ae_customization/editor.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
3131
:javascript
3232
ManageIQ.angular.app.value('dialogIdAction', '#{ dialog_id_action.to_json }');
33+
ManageIQ.angular.app.value('automationKeys', '#{ automation_types.to_json }');
3334
miq_bootstrap('#dialog-editor');
3435
// Fixes wrong coordinates of draggable element after scrolling in #main-content.
3536
// To be selected as scrollParent it cannot have position: static(default setting of #main-content) so it's overridden here

0 commit comments

Comments
 (0)