Skip to content

Commit 187bcc7

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

File tree

6 files changed

+118
-4
lines changed

6 files changed

+118
-4
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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
AUTOMATION_TYPES = {
6+
:automate => {
7+
:key => 'embedded_automate',
8+
:label => _('Embedded Automate'),
9+
:fields => ['ae_namespace', 'ae_class', 'ae_instance', 'ae_message', 'ae_attributes'],
10+
},
11+
:workflow => {
12+
:key => 'embedded_workflow',
13+
:label => _('Embedded Workflow'),
14+
:fields => ['configuration_script_id', 'workflow_name'],
15+
},
16+
}.freeze
17+
18+
# Returns an array of entry point options.
19+
# used in provision_entry_points, retirement_entry_points, reconfigure_entry_points html files
20+
def automation_type_options
21+
options = [["<#{_('No Entry Point')}>", nil]]
22+
options + AUTOMATION_TYPES.values.map do |item|
23+
[item[:label], item[:key]]
24+
end
25+
end
26+
27+
# Returns true if the field holds value 'embedded_automate'
28+
def embedded_automate(field)
29+
field == AUTOMATION_TYPES[:automate][:key]
30+
end
31+
32+
# Returns true if the field holds value 'embedded_workflow'
33+
def embedded_workflow(field)
34+
field == AUTOMATION_TYPES[:workflow][:key]
35+
end
36+
37+
# Returns the default automation type 'embedded_automate'
38+
def default_automation_type
39+
AUTOMATION_TYPES[:automate][:key]
40+
end
41+
end
42+
end

app/helpers/miq_ae_customization_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
module MiqAeCustomizationHelper
2+
include Mixins::AutomationMixin
3+
4+
def editor_automation_types
5+
AUTOMATION_TYPES.to_json
6+
end
7+
28
def dialog_id_action
39
url = request.parameters
410
if url[:id].present?

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

Lines changed: 51 additions & 3 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', '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());

app/javascript/oldjs/services/dialog_editor_http_service.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,18 @@ 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+
.then((response) => ({ data: response, status: true }))
46+
.catch((error) => ({ data: error, status: false }));
47+
};
3448
}]);

app/views/miq_ae_customization/editor.html.haml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
'on-click' => "vm.dismissChanges()"}
3030
3131
:javascript
32-
ManageIQ.angular.app.value('dialogIdAction', '#{ dialog_id_action.to_json }');
32+
ManageIQ.angular.app.value('dialogIdAction', '#{dialog_id_action.to_json}');
33+
ManageIQ.angular.app.value('automationKeys', '#{editor_automation_types}');
34+
ManageIQ.angular.app.value('emsWorkflowsEnabled', '#{Settings.prototype.ems_workflows.enabled}');
35+
3336
miq_bootstrap('#dialog-editor');
3437
// Fixes wrong coordinates of draggable element after scrolling in #main-content.
3538
// 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)