Skip to content

Commit

Permalink
Allow Vm to open a url after a dialog is submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
ZitaNemeckova committed Aug 2, 2018
1 parent 522c89d commit 39bea79
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 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', function(API, dialogFieldRefreshService, miqService, dialogUserSubmitErrorHandlerService, dialogId, apiSubmitEndpoint, apiAction, finishSubmitEndpoint, cancelEndpoint, resourceActionId, targetId, targetType) {
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) {
var vm = this;

vm.$onInit = function() {
Expand All @@ -21,6 +21,8 @@ ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefr

vm.refreshField = refreshField;
vm.setDialogData = setDialogData;
vm.openUrl = openUrl;
vm.targetId = targetId;
vm.refreshUrl = '/api/service_dialogs/';

vm.submitButtonClicked = submitButtonClicked;
Expand Down Expand Up @@ -55,8 +57,22 @@ ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefr
} else {
apiData = vm.dialogData;
}
return API.post(apiSubmitEndpoint, apiData, {skipErrors: [400]}).then(function() {
miqService.redirectBack(__('Order Request was Submitted'), 'info', finishSubmitEndpoint);
return API.post(apiSubmitEndpoint, apiData, {skipErrors: [400]}).then(function(response) {
if (vm.openUrl === "true") {
debugger;
return API.wait_for_task(response.task_id).then(function(response) {
return $http.post("open_url_after_dialog", {targetId: vm.targetId}).then(function(response) {
window.open(response.data.url, '_blank');
miqService.redirectBack(__('Order Request was Submitted'), 'info', finishSubmitEndpoint);
}).catch(function(err) {
return Promise.reject(dialogUserSubmitErrorHandlerService.handleError(err));
});
}).catch(function(err) {
return Promise.reject(dialogUserSubmitErrorHandlerService.handleError(err));
});
} else {
miqService.redirectBack(__('Order Request was Submitted'), 'info', finishSubmitEndpoint);
}
}).catch(function(err) {
return Promise.reject(dialogUserSubmitErrorHandlerService.handleError(err));
});
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ def ab_group_delete
end
end

def open_url_after_dialog
url = SystemConsole.find_by(:vm_id => params[:targetId]).url
# url = "www.redhat.com"
render :json => {:open_url => url}
end

private

BASE_MODEL_EXPLORER_CLASSES = [MiqGroup, MiqTemplate, Service, Switch, Tenant, User, Vm].freeze
Expand Down Expand Up @@ -338,6 +344,7 @@ def custom_buttons(ids = nil, display_options = {})
}

options[:dialog_locals] = DialogLocalService.new.determine_dialog_locals_for_custom_button(obj, button.name, button.resource_action, display_options)
options[:dialog_locals][:open_url] = button.options && button.options.key?(:open_url) && button.options[:open_url]
options.merge!(display_options) unless display_options.empty?
dialog_initialize(button.resource_action, options)

Expand Down
3 changes: 2 additions & 1 deletion app/views/shared/dialogs/_dialog_provision.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
:finish_submit_endpoint => finish_submit_endpoint,
:api_submit_endpoint => api_submit_endpoint,
:api_action => api_action,
:cancel_endpoint => cancel_endpoint}
:cancel_endpoint => cancel_endpoint,
:open_url => open_url}
1 change: 1 addition & 0 deletions app/views/shared/dialogs/_dialog_user.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
ManageIQ.angular.app.value('apiSubmitEndpoint', '#{api_submit_endpoint}');
ManageIQ.angular.app.value('apiAction', '#{api_action}');
ManageIQ.angular.app.value('cancelEndpoint', '#{cancel_endpoint}');
ManageIQ.angular.app.value('openUrl', '#{open_url}');
miq_bootstrap('.wrapper');
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
dynamic_date_refresh
dynamic_radio_button_refresh
dynamic_text_box_refresh
open_url_after_dialog
)

discover_get_post = %w(
Expand Down

0 comments on commit 39bea79

Please sign in to comment.