From fce083311cb33c13a90249fb6738d53a5678188e Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Tue, 24 Jul 2018 12:59:08 +0200 Subject: [PATCH 1/2] Allow Vm to open a url after a dialog is submitted Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1602023 --- .../dialog_user/dialog_user_controller.js | 20 ++++++++++++++++--- .../application_controller/buttons.rb | 8 +++++++- .../dialogs/_dialog_provision.html.haml | 3 ++- .../shared/dialogs/_dialog_user.html.haml | 1 + config/routes.rb | 1 + 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/controllers/dialog_user/dialog_user_controller.js b/app/assets/javascripts/controllers/dialog_user/dialog_user_controller.js index ad14057792c..f943eec6385 100644 --- a/app/assets/javascripts/controllers/dialog_user/dialog_user_controller.js +++ b/app/assets/javascripts/controllers/dialog_user/dialog_user_controller.js @@ -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() { @@ -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; @@ -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)); }); diff --git a/app/controllers/application_controller/buttons.rb b/app/controllers/application_controller/buttons.rb index faf6ed52ddd..2a1c418d721 100644 --- a/app/controllers/application_controller/buttons.rb +++ b/app/controllers/application_controller/buttons.rb @@ -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 @@ -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) diff --git a/app/views/shared/dialogs/_dialog_provision.html.haml b/app/views/shared/dialogs/_dialog_provision.html.haml index 73af5269793..bd493058f1a 100644 --- a/app/views/shared/dialogs/_dialog_provision.html.haml +++ b/app/views/shared/dialogs/_dialog_provision.html.haml @@ -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} diff --git a/app/views/shared/dialogs/_dialog_user.html.haml b/app/views/shared/dialogs/_dialog_user.html.haml index 5384890fbb7..570a632bafc 100644 --- a/app/views/shared/dialogs/_dialog_user.html.haml +++ b/app/views/shared/dialogs/_dialog_user.html.haml @@ -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'); diff --git a/config/routes.rb b/config/routes.rb index 0c08de722fc..10612fe1fe9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,6 +47,7 @@ dynamic_date_refresh dynamic_radio_button_refresh dynamic_text_box_refresh + open_url_after_dialog ) discover_get_post = %w( From 171214da750ba3c3f67daf17143e3287a109d459 Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Tue, 7 Aug 2018 13:19:50 +0200 Subject: [PATCH 2/2] Add openUrl set to false to tests as a default option --- .../controllers/dialog_user/dialog_user_controller.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/javascripts/controllers/dialog_user/dialog_user_controller.spec.js b/spec/javascripts/controllers/dialog_user/dialog_user_controller.spec.js index 69773f21831..e26fdcc5b07 100644 --- a/spec/javascripts/controllers/dialog_user/dialog_user_controller.spec.js +++ b/spec/javascripts/controllers/dialog_user/dialog_user_controller.spec.js @@ -40,6 +40,7 @@ describe('dialogUserController', function() { resourceActionId: '789', targetId: '987', targetType: 'targettype', + openUrl: false, }); })); @@ -119,6 +120,7 @@ describe('dialogUserController', function() { targetId: '987', targetType: 'targettype', saveable: true, + openUrl: false, }); $controller.setDialogData({data: {field1: 'field1'}, validations: { isValid : true}}); @@ -152,6 +154,7 @@ describe('dialogUserController', function() { targetId: '987', targetType: 'targettype', saveable: true, + openUrl: false, }); $controller.setDialogData({data: {field1: 'field1'}, validations: { isValid : true}});