forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display custom buttons after comming from relationship table
The code displays the custom buttons if the previous screen was a provider screen ('@record') and displayed item ('@ display') is from the list of classes supported by custom buttons ('APPLIES_TO_CLASS_BASE_MODELS') Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1635738
- Loading branch information
1 parent
6f1bdbc
commit 828a7de
Showing
4 changed files
with
57 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/helpers/application_helper/toolbar/mixins/custom_button_toolbar_mixin.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module ApplicationHelper::Toolbar::Mixins::CustomButtonToolbarMixin | ||
APPLIES_TO_CLASS_BASE_MODELS = %w(AvailabilityZone CloudNetwork CloudObjectStoreContainer CloudSubnet CloudTenant | ||
CloudVolume ContainerGroup ContainerImage ContainerNode ContainerProject | ||
ContainerTemplate ContainerVolume EmsCluster ExtManagementSystem | ||
GenericObject GenericObjectDefinition Host LoadBalancer | ||
MiqGroup MiqTemp MiqTemplate NetworkRouter OrchestrationStack SecurityGroup Service | ||
ServiceTemplate Storage Switch Tenant User Vm VmOrTemplate).freeze | ||
|
||
def custom_button_appliable_class?(model) | ||
APPLIES_TO_CLASS_BASE_MODELS.include?(model) | ||
end | ||
|
||
def custom_button_class_model(applies_to_class) | ||
# TODO: Give a better name for this concept, including ServiceTemplate using Service | ||
# This should probably live in the model once this concept is defined. | ||
unless custom_button_appliable_class?(applies_to_class) | ||
raise ArgumentError, "Received: #{applies_to_class}, expected one of #{APPLIES_TO_CLASS_BASE_MODELS}" | ||
end | ||
|
||
case applies_to_class | ||
when "ServiceTemplate" | ||
Service | ||
when "GenericObjectDefinition" | ||
GenericObject | ||
else | ||
applies_to_class.constantize | ||
end | ||
end | ||
|
||
# Indicates, whether the user has came from providers relationship screen | ||
# or not | ||
# | ||
# Used to indicate if the custom buttons should be rendered | ||
def relationship_table_screen? | ||
return false if @display.nil? || @record.nil? | ||
|
||
display_model = @display.camelize.singularize | ||
providers = (EmsCloud.descendants + | ||
EmsInfra.descendants + | ||
EmsPhysicalInfra.descendants + | ||
ManageIQ::Providers::ContainerManager.descendants) | ||
|
||
custom_button_model = custom_button_appliable_class?(display_model) | ||
provider_screen = providers.any? { |provider| @record.instance_of?(provider) } | ||
show_action = @lastaction == "show" | ||
|
||
custom_button_model && provider_screen && show_action | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters