Skip to content

Commit

Permalink
Split Chargeback explorer into 3 explorers
Browse files Browse the repository at this point in the history
Removed Accordions from Chargeback Explorer, splitting that into 3 individual explorers with their third level subtabs under Overview/Chargeback, third level tabs are Reports/Rates/Assignments. These new subtabs still use old Product features "chargeback_explorer" that will be taken care of when explorers are converted into non-explorer style screens as this will also require migration at the time.
Made changes to remove functionality from new screens to show collapsible accordion on the top like other explorer style screen
Split spec tests into multiple files based upon new controller/explorer structure

Partially fixes #6996
  • Loading branch information
h-kataria committed May 8, 2020
1 parent f3e3979 commit 21918d8
Show file tree
Hide file tree
Showing 34 changed files with 1,642 additions and 1,350 deletions.
421 changes: 421 additions & 0 deletions app/controllers/chargeback_assignment_controller.rb

Large diffs are not rendered by default.

991 changes: 0 additions & 991 deletions app/controllers/chargeback_controller.rb

This file was deleted.

514 changes: 514 additions & 0 deletions app/controllers/chargeback_rate_controller.rb

Large diffs are not rendered by default.

239 changes: 239 additions & 0 deletions app/controllers/chargeback_report_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
class ChargebackReportController < ApplicationController
before_action :check_privileges
before_action :get_session_data
after_action :cleanup_action
after_action :set_session_data

include Mixins::SavedReportPaging
include Mixins::GenericSessionMixin
include Mixins::BreadcrumbsMixin

def self.table_name
@table_name ||= "chargeback_report"
end

def x_show
@explorer = true
end

def tree_select
self.x_active_tree = params[:tree] if params[:tree]
self.x_node = params[:id]
get_node_info(x_node)
replace_right_cell
end

def explorer
@breadcrumbs = []
@explorer = true
build_accordions_and_trees

@right_cell_text = _("All Saved Chargeback Reports")
render :layout => "application" unless request.xml_http_request?
end

def title
@title = _("Chargeback Reports")
end

private ############################

def features
[
{
:role => "chargeback_reports",
:name => :cb_reports,
:title => _("Reports")
}
].map { |hsh| ApplicationController::Feature.new_with_hash(hsh) }
end

# Build a Chargeback Reports explorer tree
def cb_rpts_build_tree
TreeBuilderChargebackReports.new("cb_reports_tree", @sb)
end

def cb_rpts_show_saved_report
@sb[:last_savedreports_id] = parse_nodetype_and_id(params[:id]).last if params[:id] && params[:id] != "cb_reports_accord"
cb_rpts_fetch_saved_report(@sb[:last_savedreports_id])
@sb[:parent_reports] = nil if @report.blank?
end

def cb_rpts_fetch_saved_report(id)
rr = MiqReportResult.for_user(current_user).find(id.to_s.split('-').last)
if rr.nil? # Saved report no longer exists
@report = nil
return
end
@right_cell_text ||= _("Saved Chargeback Report [%{name}]") % {:name => rr.name}
if !current_user.miq_group_ids.include?(rr.miq_group_id) && !report_admin_user?
add_flash(_("Report is not authorized for the logged in user"), :error)
@saved_reports = cb_rpts_get_all_reps(id.split('-')[1])
return
else
@report_result_id = session[:report_result_id] = rr.id
session[:report_result_runtime] = rr.last_run_on
if rr.status.downcase == "complete"
session[:rpt_task_id] = nil
if rr.valid_report_column?
if rr.contains_records?
@html = report_first_page(rr) # Get the first page of the results
if @report.graph.present?
@render_chart = true
@ght_type = "hybrid"
else
@ght_type = "tabular"
end
@report.extras ||= {} # Create extras hash
@report.extras[:to_html] ||= @html # Save the html report
else
add_flash(_("No records found for this report"), :warning)
end
else
@saved_reports = cb_rpts_get_all_reps(rr.miq_report_id.to_s)
rep = MiqReport.find(rr.miq_report_id)
if x_active_tree == :cb_reports_tree
self.x_node = "reports-#{rep.id}"
end
return
end
end
end
end

def get_node_info(node, show_list = true)
@show_list = show_list
node = valid_active_node(node)
@nodetype = node.split("-")[0]
nodes = x_node.split('_')
nodes_len = nodes.length

# On the root node
if x_node == "root"
cb_rpt_build_folder_nodes
@right_cell_div = "reports_list_div"
@right_cell_text = _("All Saved Chargeback Reports")
elsif nodes_len == 2
# On a saved report node
cb_rpts_show_saved_report
if @report
s = MiqReportResult.for_user(current_user).find(nodes.last.split('-').last)

@right_cell_div = "reports_list_div"
@right_cell_text = _("Saved Chargeback Report \"%{last_run_on}\"") % {:last_run_on => format_timezone(s.last_run_on, Time.zone, "gtl")}
else
add_flash(_("Selected Saved Chargeback Report no longer exists"), :warning)
self.x_node = nodes[0..1].join("_")
cb_rpts_build_tree # Rebuild tree
end
# On a saved reports parent node
else
# saved reports under report node on saved report accordion
@saved_reports = cb_rpts_get_all_reps(nodes[0].split('-')[1])
if @saved_reports.present?
@sb[:sel_saved_rep_id] = nodes[1]
@right_cell_div = "reports_list_div"
miq_report = MiqReport.for_user(current_user).find(@sb[:miq_report_id])
@right_cell_text = _("Saved Chargeback Reports \"%{report_name}\"") % {:report_name => miq_report.name}
@sb[:parent_reports] = nil if @sb[:saved_reports].present? # setting it to nil so saved reports can be displayed, unless all saved reports were deleted
else
add_flash(_("Selected Chargeback Report no longer exists"), :warning)
self.x_node = nodes[0]
@saved_reports = nil
cb_rpts_build_tree # Rebuild tree
end
end
{:view => @view, :pages => @pages}
end

def cb_rpt_build_folder_nodes
@parent_reports = {}

MiqReportResult.with_saved_chargeback_reports.select_distinct_results.each_with_index do |sr, sr_idx|
@parent_reports[sr.miq_report.name] = "#{sr.miq_report_id}-#{sr_idx}"
end
end

def cb_rpts_get_all_reps(nodeid)
return [] if nodeid.blank?

@sb[:miq_report_id] = nodeid
miq_report = MiqReport.for_user(current_user).find(@sb[:miq_report_id])
saved_reports = miq_report.miq_report_results.with_current_user_groups
.select("id, miq_report_id, name, last_run_on, report_source")
.order(:last_run_on => :desc)

@sb[:tree_typ] = "reports"
@right_cell_text = _("Report \"%{report_name}\"") % {:report_name => miq_report.name}
saved_reports
end


def replace_right_cell(options = {})
@explorer = true
c_tb = build_toolbar(center_toolbar_filename)

# Build a presenter to render the JS
presenter = ExplorerPresenter.new(:active_tree => x_active_tree)

# FIXME
# if params[:action].ends_with?("_delete")
# page << "miqTreeActivateNodeSilently('#{x_active_tree.to_s}', '<%= x_node %>');"
# end
# presenter[:select_node] = x_node if params[:action].ends_with?("_delete")
presenter[:osf_node] = x_node


if c_tb.present?
presenter.reload_toolbars(:center => c_tb)
presenter.show(:toolbar)
else
presenter.hide(:toolbar)
end
presenter.update(:main_div, r[:partial => 'reports_list'])
if @html
presenter.update(:paging_div, r[:partial => 'layouts/saved_report_paging_bar',
:locals => @sb[:pages]])
presenter.show(:paging_div)
else
presenter.hide(:paging_div)
end

presenter.hide(:form_buttons_div)
if x_active_tree == :cb_reports_tree && !@report
presenter.hide(:toolbar).remove_paging
else
presenter.show(:paging_div)
end

presenter[:record_id] = determine_record_id_for_presenter

presenter[:clear_gtl_list_grid] = @gtl_type && @gtl_type != 'list'

presenter[:right_cell_text] = @right_cell_text
presenter.update(:breadcrumbs, r[:partial => 'layouts/breadcrumbs'])

render :json => presenter.for_render
end

def get_session_data
super
@current_page = session[:chargeback_report_current_page]
end

def set_session_data
super
session[:chargeback_report_current_page] = @current_page
end

def breadcrumbs_options
{
:breadcrumbs => [
{:title => _("Overview")},
{:title => _("Chargeback")},
],
}
end

menu_section :chargeback
end
30 changes: 21 additions & 9 deletions app/helpers/application_helper/listnav.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,32 @@ def valid_html_id(id)
id
end

NO_ACCORDION = %w[chargeback_assignment
chargeback_rate
chargeback_report].to_set.freeze

# Create a collapsed panel based on a condition
def miq_accordion_panel(title, condition, id, &block)
id = valid_html_id(id)
content_tag(:div, :class => "panel panel-default") do
out = content_tag(:div, :class => "panel-heading") do
content_tag(:h4, :class => "panel-title") do
link_to(title, "##{id}",
'data-parent' => '#accordion',
'data-toggle' => 'collapse',
:class => condition ? '' : 'collapsed')
if NO_ACCORDION.include?(@layout)
content_tag(:div, :class => "panel panel-default") do
content_tag(:div, :id => id, :class => "panel-collapse collapse in") do
content_tag(:div, :class => "panel-body", &block)
end
end
out << content_tag(:div, :id => id, :class => "panel-collapse collapse #{condition ? 'in' : ''}") do
content_tag(:div, :class => "panel-body", &block)
else
content_tag(:div, :class => "panel panel-default") do
out = content_tag(:div, :class => "panel-heading") do
content_tag(:h4, :class => "panel-title") do
link_to(title, "##{id}",
'data-parent' => '#accordion',
'data-toggle' => 'collapse',
:class => condition ? '' : 'collapsed')
end
end
out << content_tag(:div, :id => id, :class => "panel-collapse collapse #{condition ? 'in' : ''}") do
content_tag(:div, :class => "panel-body", &block)
end
end
end
end
Expand Down
27 changes: 15 additions & 12 deletions app/helpers/application_helper/toolbar_chooser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ def center_toolbar_filename_explorer
center_toolbar_filename_containers
elsif %i[sandt_tree svccat_tree stcat_tree svcs_tree ot_tree].include?(x_active_tree)
center_toolbar_filename_services
elsif @layout == "chargeback"
center_toolbar_filename_chargeback
elsif @layout == "chargeback_rate"
center_toolbar_filename_chargeback_rate
elsif @layout == "chargeback_report"
center_toolbar_filename_chargeback_report
elsif @layout == "miq_ae_tools"
super_admin_user? ? "miq_ae_tools_simulate_center_tb" : nil
elsif @layout == "miq_policy"
Expand Down Expand Up @@ -210,15 +212,14 @@ def center_toolbar_filename_containers
x_node == 'root' ? 'containers_center_tb' : 'container_center_tb'
end

def center_toolbar_filename_chargeback
if @report && x_active_tree == :cb_reports_tree
return "chargeback_center_tb"
elsif x_active_tree == :cb_rates_tree && x_node != "root"
if %w[Compute Storage].include?(x_node.split('-').last)
return "chargebacks_center_tb"
else
return "chargeback_center_tb"
end
def center_toolbar_filename_chargeback_report
return "chargeback_center_tb" if @report
nil
end

def center_toolbar_filename_chargeback_rate
if x_node != "root"
return %w[Compute Storage].include?(x_node.split('-').last) ? "chargebacks_center_tb" : "chargeback_center_tb"
end
nil
end
Expand Down Expand Up @@ -592,7 +593,9 @@ def inventory_group_center_tb
end
end

NO_GTL_VIEW_BUTTONS = %w[chargeback
NO_GTL_VIEW_BUTTONS = %w[chargeback_assignment
chargeback_rate
chargeback_report
generic_object
generic_object_definition
miq_ae_class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ChargebackHelper
module ChargebackRateHelper
def rate_detail_group(rd_group)
rd_groups = {
'cpu' => _('CPU'),
Expand Down
10 changes: 9 additions & 1 deletion app/presenters/menu/default_menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def overview_menu_section
# Menu::Item.new('usage', N_('Usage'), 'usage', {:feature => 'usage'}, '/report/usage/'), # / Hiding usage for now - release 5.2
Settings.product.consumption ? consumption_menu_section : nil,
Menu::Item.new('miq_capacity_utilization', N_('Utilization'), 'utilization', {:feature => 'utilization'}, '/utilization'),
Menu::Item.new('chargeback', N_('Chargeback'), 'chargeback', {:feature => 'chargeback', :any => true}, '/chargeback/explorer'),
chargeback_menu_section,
Menu::Item.new('optimization', N_('Optimization'), 'optimization', {:feature => 'optimization'}, '/optimization'),
].compact)
end
Expand All @@ -46,6 +46,14 @@ def services_menu_section
])
end

def chargeback_menu_section
Menu::Section.new(:chargeback, N_("Chargeback"), 'fa fa-plus', [
Menu::Item.new('chargeback_report', N_('Reports'), 'chargeback_reports', {:feature => 'chargeback_reports', :any => true}, '/chargeback_report/explorer'),
Menu::Item.new('chargeback_rate', N_('Rates'), 'chargeback_rates', {:feature => 'chargeback_rates', :any => true}, '/chargeback_rate/explorer'),
Menu::Item.new('chargeback_assignment', N_('Assignments'), 'chargeback_assignments', {:feature => 'chargeback_assignments'}, '/chargeback_assignment/explorer'),
])
end

def clouds_menu_section
Menu::Section.new(:clo, N_("Clouds"), 'fa fa-plus', [
Menu::Item.new('ems_cloud', N_('Providers'), 'ems_cloud', {:feature => 'ems_cloud_show_list'}, '/ems_cloud/show_list'),
Expand Down
11 changes: 0 additions & 11 deletions app/views/chargeback/explorer.html.haml

This file was deleted.

3 changes: 3 additions & 0 deletions app/views/chargeback_assignment/explorer.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-# These are the initial divs that will go inside center_cell_div
#main_div
= render :partial => "assignments_tabs"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions app/views/chargeback_rate/explorer.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-# These are the initial divs that will go inside center_cell_div
#main_div
= render :partial => "rates_tabs"
3 changes: 3 additions & 0 deletions app/views/chargeback_report/explorer.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-# These are the initial divs that will go inside center_cell_div
#main_div
= render :partial => "reports_list"
Loading

0 comments on commit 21918d8

Please sign in to comment.