Skip to content

Commit 39c6042

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

File tree

8 files changed

+124
-10
lines changed

8 files changed

+124
-10
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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@data-driven-forms/carbon-component-mapper": "~3.18.8",
3939
"@data-driven-forms/react-form-renderer": "~3.18.8",
4040
"@manageiq/font-fabulous": "~1.0.5",
41-
"@manageiq/ui-components": "1.4.4",
41+
"@manageiq/ui-components": "1.5.0",
4242
"@novnc/novnc": "~1.2.0",
4343
"@pf3/select": "~1.12.6",
4444
"@tshepomgaga/aws-sfn-graph": "0.0.6",

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,17 +1934,17 @@ __metadata:
19341934
languageName: node
19351935
linkType: hard
19361936

1937-
"@manageiq/ui-components@npm:1.4.4":
1938-
version: 1.4.4
1939-
resolution: "@manageiq/ui-components@npm:1.4.4"
1937+
"@manageiq/ui-components@npm:1.5.0":
1938+
version: 1.5.0
1939+
resolution: "@manageiq/ui-components@npm:1.5.0"
19401940
dependencies:
19411941
angular-bootstrap-switch: ^0.5.1
19421942
angular-dragdrop: ^1.0.13
19431943
angular-ui-sortable: ^0.16.1
19441944
es6-shim: ^0.35.3
19451945
es7-shim: ^6.0.0
19461946
sprintf-js: ^1.1.1
1947-
checksum: 4668f41f8c1f1107b2c21b2a3bbafa293a0e730130801120ccfb1ddf925224dfa3cc4d753a8bdf4af41c274d21b3c1f1d7e56ecfc9440bcc6e5e02174db58358
1947+
checksum: b7037c6a442ac0b35f69624ad085b58148d1005a41a02d43278d6d7f72112d4a4a5a025f2d048477156e903ec2e0b66def1ced467cb08c1581da70da1e1dcdb2
19481948
languageName: node
19491949
linkType: hard
19501950

@@ -11382,7 +11382,7 @@ fsevents@^1.2.7:
1138211382
"@data-driven-forms/carbon-component-mapper": ~3.18.8
1138311383
"@data-driven-forms/react-form-renderer": ~3.18.8
1138411384
"@manageiq/font-fabulous": ~1.0.5
11385-
"@manageiq/ui-components": 1.4.4
11385+
"@manageiq/ui-components": 1.5.0
1138611386
"@novnc/novnc": ~1.2.0
1138711387
"@pf3/select": ~1.12.6
1138811388
"@tshepomgaga/aws-sfn-graph": 0.0.6

0 commit comments

Comments
 (0)