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

Fix open_url with dialog #4334

Merged
merged 2 commits into from
Aug 17, 2018
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', 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 Down Expand Up @@ -35,6 +35,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 @@ -69,8 +71,20 @@ 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") {
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.open_url);
miqService.redirectBack(__('Order Request was Submitted'), 'info', finishSubmitEndpoint);
});
});
} else {
miqService.redirectBack(__('Order Request was Submitted'), 'info', finishSubmitEndpoint);
}
}).catch(function(err) {
return Promise.reject(dialogUserSubmitErrorHandlerService.handleError(err));
});
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ def ab_group_delete
end
end

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

private

BASE_MODEL_EXPLORER_CLASSES = [MiqGroup, MiqTemplate, Service, Switch, Tenant, User, Vm].freeze
Expand Down Expand Up @@ -338,10 +343,11 @@ 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.present? && button.options.fetch_path(:open_url)
options.merge!(display_options) unless display_options.empty?
dialog_initialize(button.resource_action, options)

elsif button.options && button.options.key?(:open_url) && button.options[:open_url]
elsif button.options.present? && button.options.fetch_path(:open_url)
# not supported for objs: cannot do wait for task for multiple tasks
task_id = button.invoke_async(obj)
initiate_wait_for_task(:task_id => task_id, :action => :custom_button_done)
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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZitaNemeckova is causing an error on upstream, please take a look
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #4521

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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('dialogUserController', function() {
resourceActionId: '789',
targetId: '987',
targetType: 'targettype',
openUrl: false,
});
}));

Expand Down Expand Up @@ -119,6 +120,7 @@ describe('dialogUserController', function() {
targetId: '987',
targetType: 'targettype',
saveable: true,
openUrl: false,
});

$controller.setDialogData({data: {field1: 'field1'}, validations: { isValid : true}});
Expand Down Expand Up @@ -152,6 +154,7 @@ describe('dialogUserController', function() {
targetId: '987',
targetType: 'targettype',
saveable: true,
openUrl: false,
});

$controller.setDialogData({data: {field1: 'field1'}, validations: { isValid : true}});
Expand Down