Skip to content

Commit

Permalink
Stay in service explorer for generic objects attached to the service
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalis committed Oct 30, 2017
1 parent 2a7afaa commit 6137d23
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 16 deletions.
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
89 changes: 83 additions & 6 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,31 @@ def show_list
redirect_to :action => 'explorer', :flash_msg => @flash_array.try(:fetch_path, 0, :message)
end

def show_details(db, options = {}) # Pass in the db, parent vm is in @vm
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 = @no_checkboxes.nil? || @no_checkboxes
@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,12 +173,31 @@ 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")
show_item
else
drop_breadcrumb(:name => _("%{name} (Generic Objects)") % {:name => @record.name},
:url => "/#{@db}/generic_objects/#{@record.id}")
@listicon = "generic_object"
@explorer = true
show_details(GenericObject, :association => "generic_objects")
end
end

def self.display_methods
%w(generic_objects)
end

def display_generic_objects
nested_list("generic_object", GenericObject)
nested_list(self.controller_name, GenericObject)
end

private
Expand Down Expand Up @@ -319,7 +361,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 +383,31 @@ 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 = _("%{action} for %{service} \"%{name}\"") % {
:service => ui_lookup(:table => table),
:name => @record.name,
:action => action.to_s.capitalize
}
name = @record.try(:name).to_s
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 +420,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 +452,17 @@ 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'
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
end
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 @@ -234,12 +234,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
15 changes: 13 additions & 2 deletions app/helpers/service_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,27 @@ def textual_vmware_credential
:link => url_for_only_path(:action => 'show', :id => credential.id, :controller => 'ansible_credential')}
end

def textual_generic_object_instances
def textual_generic_object_instances_old
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'),
h.update(:link => url_for_only_path(:action => 'generic_objects', :id => @record, :db => controller.controller_name, :type => 'tile'),
:title => _('Show Generic Object Instances for this Service'))
end
h
end

def textual_generic_object_instances
num = @record.number_of(:generic_objects)
h = {:label => _("Instances"), :value => num}
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

def credential(credential, label)
{:label => label, :value => credential.name}
end
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
update
wait_for_task
) +
compare_post + adv_search_post + exp_post + save_post + dialog_runner_post
compare_post + adv_search_post + exp_post + save_post
},

:cloud_object_store_object => {
Expand Down Expand Up @@ -2967,6 +2967,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:

0 comments on commit 6137d23

Please sign in to comment.