From 8f94aa7f8cae7237575e138d681848be1349f7ac Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Mon, 7 Oct 2019 16:05:42 +0200 Subject: [PATCH 1/5] Toolbar delete button for Button/Button Group goes via generic API delete code not via genericObjectDefinitionToolbarController Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1753388 --- .../application_helper/button/basic.rb | 4 ++++ ...t_definition_button_button_group_delete.rb | 19 ++++++++++++++++++- ...generic_object_definition_button_center.rb | 7 +++---- ...c_object_definition_button_group_center.rb | 8 +++----- .../application_helper/toolbar_builder.rb | 2 +- app/javascript/toolbar-actions/delete.js | 11 ++++++++--- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/app/helpers/application_helper/button/basic.rb b/app/helpers/application_helper/button/basic.rb index e32ec6cfb90..1c1b8574a11 100644 --- a/app/helpers/application_helper/button/basic.rb +++ b/app/helpers/application_helper/button/basic.rb @@ -14,6 +14,10 @@ def initialize(view_context, view_binding, instance_data, props) end end + def data + nil + end + def role_allows_feature? # for select buttons RBAC is checked only for nested buttons return true if self[:type] == :buttonSelect diff --git a/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb b/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb index e7b3286c637..72b998a7d1f 100644 --- a/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb +++ b/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb @@ -1,5 +1,22 @@ class ApplicationHelper::Button::GenericObjectDefinitionButtonButtonGroupDelete < ApplicationHelper::Button::Basic + needs :@record + def disabled? - !@record.custom_buttons.count.zero? + @record.kind_of?(CustomButtonSet) && !@record.custom_buttons.count.zero? + end + + def data + {'function' => 'sendDataWithRx', + 'function-data' => { + :type => 'delete', + :controller => 'toolbarActions', + :url => "show_list", + :payload => { + :entity => @record.class.model_name.plural, + :redirect_url => "/generic_object_definition/", + :name => @record.name, + :labels => { :single => @record.class.name } + } + }.to_json} end end diff --git a/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb b/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb index bd840642dda..88dfc5cf498 100644 --- a/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb +++ b/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb @@ -12,12 +12,11 @@ class ApplicationHelper::Toolbar::GenericObjectDefinitionButtonCenter < Applicat :url => 'custom_button_edit', ), button( - :ab_button_delete, + :custom_button_delete, 'pficon pficon-delete fa-lg', - N_('Remove this Button from Inventory'), - :data => {'function' => 'sendDataWithRx', - 'function-data' => '{"type": "delete_custom_button", "controller": "genericObjectDefinitionToolbarController", "entity": "Button"}'}, + N_('Remove this Custom Button from Inventory'), :confirm => N_("Warning: This Button will be permanently removed!"), + :klass => ApplicationHelper::Button::GenericObjectDefinitionButtonButtonGroupDelete ) ] ) diff --git a/app/helpers/application_helper/toolbar/generic_object_definition_button_group_center.rb b/app/helpers/application_helper/toolbar/generic_object_definition_button_group_center.rb index 9b4d5fc52df..0ea3cf39542 100644 --- a/app/helpers/application_helper/toolbar/generic_object_definition_button_group_center.rb +++ b/app/helpers/application_helper/toolbar/generic_object_definition_button_group_center.rb @@ -18,13 +18,11 @@ class ApplicationHelper::Toolbar::GenericObjectDefinitionButtonGroupCenter < App :url => 'custom_button_new', ), button( - :ab_button_delete, + :custom_button_set_delete, 'pficon pficon-delete fa-lg', - N_('Remove this Button Group from Inventory'), - :data => {'function' => 'sendDataWithRx', - 'function-data' => '{"type": "delete_custom_button_set", "controller": "genericObjectDefinitionToolbarController", "entity": "Button Group"}'}, + N_('Remove this Custom Button Group from Inventory'), + :confirm => N_("Warning: This Custom Button Group will be permanently removed!"), :klass => ApplicationHelper::Button::GenericObjectDefinitionButtonButtonGroupDelete, - :confirm => N_("Warning: This Button Group will be permanently removed!"), ), ] ) diff --git a/app/helpers/application_helper/toolbar_builder.rb b/app/helpers/application_helper/toolbar_builder.rb index c023cc13e90..32c65d6c59e 100644 --- a/app/helpers/application_helper/toolbar_builder.rb +++ b/app/helpers/application_helper/toolbar_builder.rb @@ -112,7 +112,7 @@ def build_select_button(bgi, index) def apply_common_props(button, input) button.update( :color => input[:color], - :data => input[:data], + :data => input[:data] || button.data, :hidden => button[:hidden] || !!input[:hidden], :icon => input[:icon], :name => button[:id], diff --git a/app/javascript/toolbar-actions/delete.js b/app/javascript/toolbar-actions/delete.js index 530301cde55..9bc4db28371 100644 --- a/app/javascript/toolbar-actions/delete.js +++ b/app/javascript/toolbar-actions/delete.js @@ -23,12 +23,17 @@ export function generateMessages(results) { }, { false: 0, true: 0 }); } -export function APIDelete(entity, resources, labels) { +export function APIDelete(entity, resources, labels = { single: '', multiple: '' }, redirectUrl, name) { API.post(`/api/${entity}`, { action: 'delete', resources, }).then((data) => { - showMessage(generateMessages(data.results), labels); + if (redirectUrl) { + miqFlashLater({ message: sprintf(__('%s: "%s" was successfully deleted'), labels.single, name) }); + window.location.href = redirectUrl; + } else { + showMessage(generateMessages(data.results), labels); + }; return data; }); } @@ -41,6 +46,6 @@ export function onDelete(data, resources) { if (data.customAction) { customActionDelete(data, resources); } else { - APIDelete(data.entity, resources, data.labels); + APIDelete(data.entity, resources, data.labels, data.redirect_url, data.name); } } From 4816977668708f798762b1934aa666d1c677951a Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Mon, 7 Oct 2019 16:08:27 +0200 Subject: [PATCH 2/5] Revert change from #6214 as it's no longer needed --- .../generic_object/generic-object-definition-toolbar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/components/generic_object/generic-object-definition-toolbar.js b/app/assets/javascripts/components/generic_object/generic-object-definition-toolbar.js index 4048a6ecbdd..b394d4917bc 100644 --- a/app/assets/javascripts/components/generic_object/generic-object-definition-toolbar.js +++ b/app/assets/javascripts/components/generic_object/generic-object-definition-toolbar.js @@ -70,8 +70,8 @@ function genericObjectDefinitionToolbarController(API, miqService, $window) { .catch(miqService.handleFailure); } - function postAction() { - var entityName = toolbar.entityName; + function postAction(response) { + var entityName = response.name; var saveMsg = sprintf(__('%s: "%s" was successfully deleted'), toolbar.entity, entityName); if (toolbar.redirectUrl) { miqService.redirectBack(saveMsg, 'success', toolbar.redirectUrl); From 35e5cf7377ade03478fa201519cad51f20ccc035 Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Wed, 9 Oct 2019 15:04:37 +0200 Subject: [PATCH 3/5] Changes to make it compatible with Toolbar conversion to React --- app/helpers/application_helper/button/basic.rb | 2 +- ...ect_definition_button_button_group_delete.rb | 17 +++++++++-------- .../application_helper/toolbar_builder.rb | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/helpers/application_helper/button/basic.rb b/app/helpers/application_helper/button/basic.rb index 1c1b8574a11..c5c6da8cdd5 100644 --- a/app/helpers/application_helper/button/basic.rb +++ b/app/helpers/application_helper/button/basic.rb @@ -14,7 +14,7 @@ def initialize(view_context, view_binding, instance_data, props) end end - def data + def self.data(_record) nil end diff --git a/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb b/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb index 72b998a7d1f..5c768fb9b87 100644 --- a/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb +++ b/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb @@ -5,18 +5,19 @@ def disabled? @record.kind_of?(CustomButtonSet) && !@record.custom_buttons.count.zero? end - def data - {'function' => 'sendDataWithRx', - 'function-data' => { + def self.data(record) + { + 'function' => 'sendDataWithRx', + 'function-data' => { :type => 'delete', :controller => 'toolbarActions', - :url => "show_list", :payload => { - :entity => @record.class.model_name.plural, + :entity => record.class.model_name.plural, :redirect_url => "/generic_object_definition/", - :name => @record.name, - :labels => { :single => @record.class.name } + :name => record.name, + :labels => { :single => record.class.name } } - }.to_json} + } + } end end diff --git a/app/helpers/application_helper/toolbar_builder.rb b/app/helpers/application_helper/toolbar_builder.rb index 32c65d6c59e..dbfde62518c 100644 --- a/app/helpers/application_helper/toolbar_builder.rb +++ b/app/helpers/application_helper/toolbar_builder.rb @@ -112,7 +112,7 @@ def build_select_button(bgi, index) def apply_common_props(button, input) button.update( :color => input[:color], - :data => input[:data] || button.data, + :data => input[:data] || (input[:klass].present? ? input[:klass].data(@record) : nil), :hidden => button[:hidden] || !!input[:hidden], :icon => input[:icon], :name => button[:id], From 6d1b46c81938cf31315490b7c1dbb123ab169f01 Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Wed, 23 Oct 2019 12:19:55 +0200 Subject: [PATCH 4/5] Use instance methods instead of class ones. Each button has its own class. --- .../application_helper/button/basic.rb | 4 ++-- ..._object_definition_button_button_delete.rb | 19 +++++++++++++++ ...t_definition_button_button_group_delete.rb | 24 +++++++++---------- ...generic_object_definition_button_center.rb | 2 +- .../application_helper/toolbar_builder.rb | 2 +- 5 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 app/helpers/application_helper/button/generic_object_definition_button_button_delete.rb diff --git a/app/helpers/application_helper/button/basic.rb b/app/helpers/application_helper/button/basic.rb index c5c6da8cdd5..a26799288ba 100644 --- a/app/helpers/application_helper/button/basic.rb +++ b/app/helpers/application_helper/button/basic.rb @@ -14,8 +14,8 @@ def initialize(view_context, view_binding, instance_data, props) end end - def self.data(_record) - nil + def data(data) + data end def role_allows_feature? diff --git a/app/helpers/application_helper/button/generic_object_definition_button_button_delete.rb b/app/helpers/application_helper/button/generic_object_definition_button_button_delete.rb new file mode 100644 index 00000000000..1bc7b9efd40 --- /dev/null +++ b/app/helpers/application_helper/button/generic_object_definition_button_button_delete.rb @@ -0,0 +1,19 @@ +class ApplicationHelper::Button::GenericObjectDefinitionButtonButtonDelete < ApplicationHelper::Button::Basic + needs :@record + + def data(_data) + { + 'function' => 'sendDataWithRx', + 'function-data' => { + :type => 'delete', + :controller => 'toolbarActions', + :payload => { + :entity => "custom_buttons", + :redirect_url => "/generic_object_definition/", + :name => @record.name, + :labels => { :single => _("Button") } + } + } + } + end +end diff --git a/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb b/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb index 5c768fb9b87..9868a13ba99 100644 --- a/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb +++ b/app/helpers/application_helper/button/generic_object_definition_button_button_group_delete.rb @@ -2,22 +2,22 @@ class ApplicationHelper::Button::GenericObjectDefinitionButtonButtonGroupDelete needs :@record def disabled? - @record.kind_of?(CustomButtonSet) && !@record.custom_buttons.count.zero? + !@record.custom_buttons.count.zero? end - def self.data(record) + def data(_data) { 'function' => 'sendDataWithRx', - 'function-data' => { - :type => 'delete', - :controller => 'toolbarActions', - :payload => { - :entity => record.class.model_name.plural, - :redirect_url => "/generic_object_definition/", - :name => record.name, - :labels => { :single => record.class.name } - } - } + 'function-data' => { + :type => 'delete', + :controller => 'toolbarActions', + :payload => { + :entity => "custom_button_sets", + :redirect_url => "/generic_object_definition/", + :name => @record.name, + :labels => { :single => _("Button Group") } + } + } } end end diff --git a/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb b/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb index 88dfc5cf498..9942aeb8d70 100644 --- a/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb +++ b/app/helpers/application_helper/toolbar/generic_object_definition_button_center.rb @@ -16,7 +16,7 @@ class ApplicationHelper::Toolbar::GenericObjectDefinitionButtonCenter < Applicat 'pficon pficon-delete fa-lg', N_('Remove this Custom Button from Inventory'), :confirm => N_("Warning: This Button will be permanently removed!"), - :klass => ApplicationHelper::Button::GenericObjectDefinitionButtonButtonGroupDelete + :klass => ApplicationHelper::Button::GenericObjectDefinitionButtonButtonDelete ) ] ) diff --git a/app/helpers/application_helper/toolbar_builder.rb b/app/helpers/application_helper/toolbar_builder.rb index dbfde62518c..92f729eb239 100644 --- a/app/helpers/application_helper/toolbar_builder.rb +++ b/app/helpers/application_helper/toolbar_builder.rb @@ -112,7 +112,7 @@ def build_select_button(bgi, index) def apply_common_props(button, input) button.update( :color => input[:color], - :data => input[:data] || (input[:klass].present? ? input[:klass].data(@record) : nil), + :data => button.data(input[:data]), :hidden => button[:hidden] || !!input[:hidden], :icon => input[:icon], :name => button[:id], From 3073ae1ad10e41890962ec042df5c5ae03e8e776 Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Wed, 23 Oct 2019 14:05:52 +0200 Subject: [PATCH 5/5] Delete dead code --- .../generic_object/generic-object-definition-toolbar.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/assets/javascripts/components/generic_object/generic-object-definition-toolbar.js b/app/assets/javascripts/components/generic_object/generic-object-definition-toolbar.js index b394d4917bc..bb5f27d6703 100644 --- a/app/assets/javascripts/components/generic_object/generic-object-definition-toolbar.js +++ b/app/assets/javascripts/components/generic_object/generic-object-definition-toolbar.js @@ -46,10 +46,6 @@ function genericObjectDefinitionToolbarController(API, miqService, $window) { }); } else if (toolbar.action === 'delete' && currentRecordId) { deleteWithAPI('/api/generic_object_definitions/', currentRecordId); - } else if (toolbar.action === 'delete_custom_button_set' && currentRecordId) { - deleteWithAPI('/api/custom_button_sets/', currentRecordId); - } else if (toolbar.action === 'delete_custom_button' && currentRecordId) { - deleteWithAPI('/api/custom_buttons/', currentRecordId); } }