Skip to content

Commit

Permalink
DialogUser - use DialogData.outputConversion before submit
Browse files Browse the repository at this point in the history
right now, when submitting a service dialog,
we simply take the dialogData object, convert to JSON and send to the API.

To allow for output conversions, adding a DialogData.outputConversion method,
which should return the dialogData in a suitable format.

(Right now, all this really means is that it converts Dates to strings before JSON stringification.)

https://bugzilla.redhat.com/show_bug.cgi?id=1744413
  • Loading branch information
himdel committed Nov 4, 2019
1 parent acaadac commit 8261b82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefreshService', 'miqService', 'dialogUserSubmitErrorHandlerService', 'dialogId', 'apiSubmitEndpoint', 'apiAction', 'finishSubmitEndpoint', 'cancelEndpoint', 'resourceActionId', 'targetId', 'targetType', 'realTargetType', 'openUrl', '$http', '$window', 'dialogReplaceData', function(API, dialogFieldRefreshService, miqService, dialogUserSubmitErrorHandlerService, dialogId, apiSubmitEndpoint, apiAction, finishSubmitEndpoint, cancelEndpoint, resourceActionId, targetId, targetType, realTargetType, openUrl, $http, $window, dialogReplaceData) {
ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefreshService', 'miqService', 'dialogUserSubmitErrorHandlerService', 'dialogId', 'apiSubmitEndpoint', 'apiAction', 'finishSubmitEndpoint', 'cancelEndpoint', 'resourceActionId', 'targetId', 'targetType', 'realTargetType', 'openUrl', '$http', '$window', 'dialogReplaceData', 'DialogData', function(API, dialogFieldRefreshService, miqService, dialogUserSubmitErrorHandlerService, dialogId, apiSubmitEndpoint, apiAction, finishSubmitEndpoint, cancelEndpoint, resourceActionId, targetId, targetType, realTargetType, openUrl, $http, $window, dialogReplaceData, DialogData) {
var vm = this;

vm.$onInit = function() {
Expand Down Expand Up @@ -68,14 +68,14 @@ ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefr
function submitButtonClicked() {
vm.dialogData.action = apiAction;
miqService.sparkleOn();
var apiData;

var apiData = DialogData.outputConversion(vm.dialogData);
if (apiSubmitEndpoint.match(/generic_objects/)) {
apiData = {action: apiAction, parameters: _.omit(vm.dialogData, 'action')};
apiData = {action: apiAction, parameters: _.omit(apiData, 'action')};
} else if (apiAction === 'reconfigure') {
apiData = {action: apiAction, resource: _.omit(vm.dialogData, 'action')};
} else {
apiData = vm.dialogData;
apiData = {action: apiAction, resource: _.omit(apiData, 'action')};
}

return API.post(apiSubmitEndpoint, apiData, {skipErrors: [400]})
.then(function(response) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ManageIQ.angular.app.controller('dialogUserReconfigureController', ['API', 'dialogFieldRefreshService', 'miqService', 'dialogUserSubmitErrorHandlerService', 'resourceActionId', 'targetId', function(API, dialogFieldRefreshService, miqService, dialogUserSubmitErrorHandlerService, resourceActionId, targetId) {
ManageIQ.angular.app.controller('dialogUserReconfigureController', ['API', 'dialogFieldRefreshService', 'miqService', 'dialogUserSubmitErrorHandlerService', 'resourceActionId', 'targetId', 'DialogData', function(API, dialogFieldRefreshService, miqService, dialogUserSubmitErrorHandlerService, resourceActionId, targetId, DialogData) {
var vm = this;

vm.$onInit = function() {
Expand Down Expand Up @@ -46,7 +46,10 @@ ManageIQ.angular.app.controller('dialogUserReconfigureController', ['API', 'dial
function submitButtonClicked() {
miqService.sparkleOn();

var apiData = {action: 'reconfigure', resource: _.omit(vm.dialogData, 'action')};
var apiData = {
action: 'reconfigure',
resource: _.omit(DialogData.outputConversion(vm.dialogData), 'action'),
};
var apiSubmitEndpoint = '/api/services/' + targetId;

return API.post(apiSubmitEndpoint, apiData, {skipErrors: [400]}).then(function() {
Expand Down

0 comments on commit 8261b82

Please sign in to comment.