Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HAMMER] DialogUser - use DialogData.outputConversion before submit and refresh #6415

Merged
merged 5 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', 'openUrl', '$http', function(API, dialogFieldRefreshService, miqService, dialogUserSubmitErrorHandlerService, dialogId, apiSubmitEndpoint, apiAction, finishSubmitEndpoint, cancelEndpoint, resourceActionId, targetId, targetType, openUrl, $http) {
ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefreshService', 'miqService', 'dialogUserSubmitErrorHandlerService', 'dialogId', 'apiSubmitEndpoint', 'apiAction', 'finishSubmitEndpoint', 'cancelEndpoint', 'resourceActionId', 'targetId', 'targetType', 'openUrl', '$http', 'DialogData', function(API, dialogFieldRefreshService, miqService, dialogUserSubmitErrorHandlerService, dialogId, apiSubmitEndpoint, apiAction, finishSubmitEndpoint, cancelEndpoint, resourceActionId, targetId, targetType, openUrl, $http, DialogData) {
var vm = this;

vm.$onInit = function() {
Expand Down Expand Up @@ -63,14 +63,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) {
if (vm.openUrl === "true") {
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
28 changes: 16 additions & 12 deletions app/assets/javascripts/services/dialog_field_refresh_service.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
ManageIQ.angular.app.service('dialogFieldRefreshService', ['API', function(API) {
this.refreshField = function(dialogData, dialogField, url, idList) {
this.areFieldsBeingRefreshed = true;
var data = angular.toJson({
ManageIQ.angular.app.service('dialogFieldRefreshService', ['API', 'DialogData', function(API, DialogData) {
var self = this;

self.refreshField = function(dialogData, dialogField, url, idList) {
self.areFieldsBeingRefreshed = true;

var data = {
action: 'refresh_dialog_fields',
resource: {
dialog_fields: dialogData,
dialog_fields: DialogData.outputConversion(dialogData),
fields: dialogField,
resource_action_id: idList.resourceActionId,
target_id: idList.targetId,
target_type: idList.targetType,
},
});
};

return new Promise(function(resolve) {
API.post(url + idList.dialogId, data).then(function(response) {
resolve(response.result[dialogField]);
return API.post(url + idList.dialogId, angular.toJson(data))
.then(function(response) {
// FIXME: API requests don't actually count towards $.active
if ($.active < 1) {
this.areFieldsBeingRefreshed = false;
self.areFieldsBeingRefreshed = false;
}
}.bind(this));
}.bind(this));

return response.result[dialogField];
});
};
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('dialogUserController', function() {
_API_,
_dialogFieldRefreshService_,
_dialogUserSubmitErrorHandlerService_,
_miqService_) {
_miqService_,
DialogData) {
API = _API_;
dialogFieldRefreshService = _dialogFieldRefreshService_;
dialogUserSubmitErrorHandlerService = _dialogUserSubmitErrorHandlerService_;
Expand Down Expand Up @@ -42,6 +43,10 @@ describe('dialogUserController', function() {
targetType: 'targettype',
openUrl: false,
});

DialogData.data = {
fields: {},
};
}));

describe('$onInit', function() {
Expand Down
7 changes: 7 additions & 0 deletions spec/javascripts/helpers/object.values.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if (! Object.values) {
Object.values = function(o) {
return Object.keys(o).map(function(k) {
return o[k];
});
}
}
12 changes: 8 additions & 4 deletions spec/javascripts/services/dialog_field_refresh_service_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ describe('dialogFieldRefreshService', function() {

beforeEach(module('ManageIQ'));

beforeEach(inject(function(dialogFieldRefreshService, _API_) {
beforeEach(inject(function(dialogFieldRefreshService, _API_, DialogData) {
testDialogFieldRefreshService = dialogFieldRefreshService;
API = _API_;

Expand All @@ -14,12 +14,16 @@ describe('dialogFieldRefreshService', function() {
};

spyOn(API, 'post').and.callFake(function() {
return {then: function(response) { response(responseResult); }};
return Promise.resolve(responseResult);
});

DialogData.data = {
fields: {},
};
}));

describe('#refreshField', function() {
var data = 'the data';
var data = { "the field": "data1" };
var field = 'the field';
var url = 'url';
var idList = {
Expand Down Expand Up @@ -49,7 +53,7 @@ describe('dialogFieldRefreshService', function() {
var requestData = {
action: 'refresh_dialog_fields',
resource: {
dialog_fields: 'the data',
dialog_fields: data,
fields: 'the field',
resource_action_id: '321',
target_id: '456',
Expand Down
1 change: 1 addition & 0 deletions spec/javascripts/support/jasmine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
src_files:
- __spec__/helpers/i18n-test.js
- __spec__/helpers/object.values.js
- packs/runtime.js
- packs/shims.js
- packs/vendor.js
Expand Down