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

[WIP] Expose Custom Buttons for Generic Objects in Service #2554

Closed
Closed
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
12 changes: 10 additions & 2 deletions app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def ab_group_delete
BASE_MODEL_EXPLORER_CLASSES = [Vm, MiqTemplate, Service].freeze
APPLIES_TO_CLASS_BASE_MODELS = %w(AvailabilityZone CloudNetwork CloudObjectStoreContainer CloudSubnet CloudTenant
CloudVolume ContainerGroup ContainerImage ContainerNode ContainerProject
ContainerTemplate ContainerVolume EmsCluster ExtManagementSystem Host LoadBalancer
ContainerTemplate ContainerVolume EmsCluster ExtManagementSystem
GenericObjectDefinition Host LoadBalancer
MiqGroup MiqTemp NetworkRouter OrchestrationStack SecurityGroup Service
ServiceTemplate Storage Switch Tenant User Vm).freeze
def applies_to_class_model(applies_to_class)
Expand All @@ -259,7 +260,14 @@ def applies_to_class_model(applies_to_class)
raise ArgumentError, "Received: #{applies_to_class}, expected one of #{APPLIES_TO_CLASS_BASE_MODELS}"
end

applies_to_class == "ServiceTemplate" ? Service : applies_to_class.constantize
case applies_to_class
when "ServiceTemplate"
Service
when "GenericObjectDefinition"
GenericObject
else
applies_to_class.constantize
end
end

def custom_button_done
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/application_controller/ci_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def get_record(db)
@ems = @record = identify_record(params[:id], EmsCloud)
elsif db == "switch"
@switch = @record = identify_record(params[:id], Switch)
elsif db == "service"
@service = @record = identify_record(params[:id], Service)
end
end

Expand Down Expand Up @@ -139,7 +141,7 @@ def process_elements(elements, klass, task, display_name = nil, order_field = ni
end

def explorer_controller?
%w(vm_cloud vm_infra vm_or_template infra_networking).include?(controller_name)
%w(vm_cloud vm_infra vm_or_template infra_networking service).include?(controller_name)
end

def process_element_destroy(element, klass, name)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/mixins/custom_buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def custom_toolbar_simple
Mixins::CustomButtons::Result.new(:single)
elsif @lastaction == "show_list"
Mixins::CustomButtons::Result.new(:list)
elsif @display == 'generic_objects'
Mixins::CustomButtons::Result.new(:list)
end
end

Expand Down
96 changes: 91 additions & 5 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class ServiceController < ApplicationController
}

def button
if @lastaction == 'generic_objects'
params[:id] = 'LIST'
elsif @lastaction.starts_with?('generic_objects')
params[:id] #params[:id] = @sb[:rec_id]
end
custom_buttons if params[:pressed] == "custom_button"
return if ["custom_button"].include?(params[:pressed]) # custom button screen, so return, let custom_buttons method handle everything
tag(GenericObject) if @display == 'generic_objects' && params[:pressed] == 'generic_object_tag'
Expand Down Expand Up @@ -58,8 +63,31 @@ def show_list
redirect_to :action => 'explorer', :flash_msg => @flash_array.try(:fetch_path, 0, :message)
end

def show_details(db, options = {})
association = options[:association]
conditions = options[:conditions]
# generate the grid/tile/list url to come back here when gtl buttons are pressed
@gtl_url = "/#{@db}/#{@listicon.pluralize}/#{@record.id}?"
@no_checkboxes = false
@showlinks = true
@view, @pages = get_view(db,
:parent => @record,
:association => association,
:conditions => conditions,
:dbname => "#{@db}item") # Get the records into a view & paginator

@refresh_partial = "service/details"
replace_right_cell(:action => "generic_objects", :showtype => "details")
end

# show a single item from a detail list
def show_item
replace_right_cell(:action => "generic_objects", :showtype => "item")
end

def explorer
@explorer = true
@explorer = true
@lastaction = "explorer"

# if AJAX request, replace right cell, and return
if request.xml_http_request?
Expand Down Expand Up @@ -150,6 +178,27 @@ def service_form_fields
}
end

def generic_objects
return unless init_show_variables

@lastaction = "generic_objects"
id = params[:show] || params[:x_show]
if id.present?
@item = @record.generic_objects.find(from_cid(id)).first
item_breadcrumbs(_("Generic Objects"), 'generic_objects')
@view = get_db_view(GenericObject, :association => "generic_objects")
@lastaction = "generic_objects_#{@item_id}"
@sb[:rec_id] = @item.id
show_item
else
drop_breadcrumb(:name => _("%{name} (Generic Objects)") % {:name => @record.name},
:url => "/#{@db}/generic_objects/#{@record.id}")
@listicon = "generic_objects"
@explorer = true
show_details(GenericObject, :association => "generic_objects")
end
end

def self.display_methods
%w(generic_objects)
end
Expand Down Expand Up @@ -319,7 +368,7 @@ def load_adv_search
end

# set partial name and cell header for edit screens
def set_right_cell_vars(action)
def set_right_cell_vars(action, type = "details")
case action
when "dialog_provision"
partial = "shared/dialogs/dialog_provision"
Expand All @@ -341,6 +390,29 @@ def set_right_cell_vars(action)
partial = "layouts/tagging"
header = _("Edit Tags for Service")
action = "service_tag"
when "generic_objects"
table = request.parameters["controller"]
header = _("Generic Objects for %{service} \"%{name}\"") % {
:service => ui_lookup(:table => table),
:name => @record.name
}
table = controller_name
partial = if type == "details"
"layouts/x_gtl"
elsif type == "item"
"layouts/item"
end
if type == "item"
header = _("Generic Object \"%{item_name}\" for %{service} \"%{name}\"") % {
:service => ui_lookup(:table => table),
:name => @record.name,
:item_name => @item.name
}
x_history_add_item(:id => x_node,
:text => header,
:action => action,
:item => @item.id)
end
else
action = nil
end
Expand All @@ -353,9 +425,9 @@ def replace_right_cell(options = {})
javascript_flash
return
end
action, replace_trees = options.values_at(:action, :replace_trees)
action, replace_trees, showtype = options.values_at(:action, :replace_trees, :showtype)
@explorer = true
partial, action_url, @right_cell_text = set_right_cell_vars(action) if action # Set partial name, action and cell header
partial, action_url, @right_cell_text = set_right_cell_vars(action, showtype) if action # Set partial name, action and cell header
get_node_info(x_node) if !action && !@in_a_form && !params[:display]
replace_trees = @replace_trees if @replace_trees # get_node_info might set this
type, = parse_nodetype_and_id(x_node)
Expand Down Expand Up @@ -385,7 +457,21 @@ def replace_right_cell(options = {})
elsif params[:display]
r[:partial => 'layouts/x_gtl', :locals => {:controller => "vm", :action_url => @lastaction}]
elsif record_showing
r[:partial => "service/svcs_show", :locals => {:controller => "service"}]
if action
partial_locals = { :controller => ''}
if partial == 'layouts/x_gtl'
cb_tb = build_toolbar(Mixins::CustomButtons::Result.new(:list))
partial_locals[:action_url] = @lastaction
presenter[:parent_id] = @record.id # Set parent rec id for JS function miqGridSort to build URL
presenter[:parent_class] = params[:controller] # Set parent class for URL also
else
partial_locals[:item_id] = @item.id
end
cb_tb = build_toolbar(Mixins::CustomButtons::Result.new(:single))
r[:partial => partial, :locals => partial_locals]
else
r[:partial => "service/svcs_show", :locals => {:controller => "service"}]
end
else
r[:partial => "layouts/x_gtl"]
end
Expand Down
13 changes: 7 additions & 6 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,13 @@ def controller_to_model
}.freeze

HAS_ASSOCATION = {
"groups" => "groups",
"users" => "users",
"event_logs" => "event_logs",
"OsProcess" => "processes",
"scan_histories" => "scan_histories",
"based_volumes" => "based_volumes"
"groups" => "groups",
"users" => "users",
"event_logs" => "event_logs",
"OsProcess" => "processes",
"scan_histories" => "scan_histories",
"based_volumes" => "based_volumes",
"generic_objects" => "generic_objects"
}.freeze

def model_to_report_data
Expand Down
25 changes: 21 additions & 4 deletions app/helpers/application_helper/toolbar_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,26 @@ def group_skipped?(name)
def create_custom_button(input, model, record)
button_id = input[:id]
button_name = input[:name].to_s
record_id = record.present? ? record.id : 'LIST'
enabled = input[:enabled]
if @lastaction.starts_with?('generic_objects')
record_id = 'LIST'
enabled = @lastaction != 'generic_objects'
else
record_id = record.present? ? record.id : 'LIST'
end
button = {
:id => "custom__custom_#{button_id}",
:type => :button,
:icon => "#{input[:image]} fa-lg",
:color => input[:color],
:title => !input[:enabled] && input[:disabled_text] ? input[:disabled_text] : input[:description].to_s,
:enabled => input[:enabled],
:enabled => enabled,
:klass => ApplicationHelper::Button::ButtonWithoutRbacCheck,
:url => "button",
:url_parms => "?id=#{record_id}&button_id=#{button_id}&cls=#{model}&pressed=custom_button&desc=#{button_name}"
}
button[:text] = button_name if input[:text_display]
button[:onwhen] = '1+' if record_id == 'LIST'
button
end

Expand All @@ -276,23 +283,33 @@ def custom_button_selects(model, record, toolbar_result)
get_custom_buttons(model, record, toolbar_result).collect do |group|
buttons = group[:buttons].collect { |b| create_custom_button(b, model, record) }

enabled = if @lastaction == 'generic_objects'
false
else
record ? true : buttons.all?{ |button| button[:enabled]}
end
props = {
:id => "custom_#{group[:id]}",
:type => :buttonSelect,
:icon => "#{group[:image]} fa-lg",
:color => group[:color],
:title => group[:description],
:enabled => record ? true : buttons.all?{ |button| button[:enabled]},
:enabled => enabled,
:items => buttons
}
props[:text] = group[:text] if group[:text_display]
props[:onwhen] = '1+' if @lastaction == 'generic_objects'

{:name => "custom_buttons_#{group[:text]}", :items => [props]}
end
end

def custom_toolbar_class(toolbar_result)
model = @record ? @record.class : model_for_custom_toolbar
if @lastaction.starts_with?('generic_objects')
model = GenericObjectDefinition
else
model = @record ? @record.class : model_for_custom_toolbar
end
build_custom_toolbar_class(model, @record, toolbar_result)
end

Expand Down
7 changes: 4 additions & 3 deletions app/helpers/service_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ def textual_vmware_credential
def textual_generic_object_instances
num = @record.number_of(:generic_objects)
h = {:label => _("Instances"), :value => num}
if role_allows?(:feature => "generic_object_view") && num > 0
h.update(:link => url_for_only_path(:action => 'show', :id => @record, :display => 'generic_objects', :type => 'tile'),
:title => _('Show Generic Object Instances for this Service'))
if num > 0
h[:title] = n_('Show Generic Object Instances for this Service')
h[:explorer] = true
h[:link] = url_for_only_path(:action => 'generic_objects', :id => @record, :db => controller.controller_name)
end
h
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2977,6 +2977,7 @@
:post => %w(
button
explorer
generic_objects
listnav_search_selected
ownership_field_changed
ownership_update
Expand Down
79 changes: 79 additions & 0 deletions product/views/GenericObject-generic_objects.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# This is an MIQ Report configuration file
# Single value parameters are specified as:
# single_value_parm: value
# Multiple value parameters are specified as:
# multi_value_parm:
# - value 1
# - value 2
#

# Report title
title: Generic Objects

# Menu name
name: GenericObjects

# Main DB table report is based on
db: GenericObject

# Subset of main table records by association
scoped_association: generic_objects

# Columns to fetch from the main table
cols:
- name
- generic_object_definition_name
- created_at
- updated_at

# Included tables (joined, has_one, has_many) and columns
include:

# Order of columns (from all tables)
col_order:
- name
- generic_object_definition_name
- created_at
- updated_at

# Column titles, in order
headers:
- Name
- Definition
- Created
- Updated

# Condition(s) string for the SQL query
conditions:

# Order string for the SQL query
order: Ascending

# Columns to sort the report on, in order
sortby:
- name
- generic_object_definition_name
- created_at
- updated_at


# Group rows (y=yes,n=no,c=count)
group: n

# Graph type
# Bar
# Column
# ColumnThreed
# ParallelThreedColumn
# Pie
# PieThreed
# StackedBar
# StackedColumn
# StackedThreedColumn

graph:

# Dimensions of graph (1 or 2)
# Note: specifying 2 for a single dimension graph may not return expected results
dims: