Skip to content

Commit

Permalink
Merge pull request #2466 from mzazrivec/get_rid_of_static_ui_lookup_i…
Browse files Browse the repository at this point in the history
…n_report_controller

ReportController: get rid of ui_lookup() with static string argument
  • Loading branch information
himdel authored Oct 20, 2017
2 parents a26b01e + 7d2ef00 commit 0329d07
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 58 deletions.
27 changes: 13 additions & 14 deletions app/controllers/report_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def explorer
x_node_set("root", :roles_tree) if params[:load_edit_err] && tree_exists?(:roles_tree)
@flash_array = @sb[:flash_msg] unless @sb[:flash_msg].blank?
get_node_info
@right_cell_text ||= _("All %{reports}") % {:reports => ui_lookup(:models => "MiqReport")}
@right_cell_text ||= _("All Reports")
@sb[:rep_tree_build_time] = Time.now.utc
@sb[:active_tab] = "report_info"
@right_cell_text.gsub!(/'/, "'") # Need to escape single quote in title to load in right cell
Expand Down Expand Up @@ -462,7 +462,7 @@ def reports_get_node_info
nodes = x_node.split('-')

if nodes.length == 2
@right_cell_text ||= _("%{typ} %{model}") % {:typ => @sb[:rpt_menu][nodes[1].to_i][0], :model => ui_lookup(:models => "MiqReport")}
@right_cell_text ||= _("%{typ} Reports") % {:typ => @sb[:rpt_menu][nodes[1].to_i][0]}

elsif nodes.length == 4 && @sb[:rpt_menu][nodes[1].to_i].present?
@sb[:rep_details] = {}
Expand All @@ -482,7 +482,7 @@ def reports_get_node_info
end
end

@right_cell_text ||= _("%{typ} %{model}") % {:typ => @sb[:rpt_menu][nodes[1].to_i][1][nodes[3].to_i][0], :model => ui_lookup(:models => "MiqReport")}
@right_cell_text ||= _("%{typ} Reports") % {:typ => @sb[:rpt_menu][nodes[1].to_i][1][nodes[3].to_i][0]}

elsif nodes.length == 4 && @sb[:rpt_menu][nodes[1].to_i].nil?
x_node_set("root", x_active_tree)
Expand All @@ -502,7 +502,7 @@ def reports_get_node_info
end

@right_cell_div ||= "report_list"
@right_cell_text ||= _("All %{models}") % {:models => ui_lookup(:models => "MiqReport")}
@right_cell_text ||= _("All Reports")
end

# Get all info for the node about to be displayed
Expand Down Expand Up @@ -709,25 +709,24 @@ def replace_right_cell(options = {}) # :replace_trees key can be an array of tr
if @in_a_form
presenter[:build_calendar] = true
@right_cell_text = @schedule.id ?
_("Editing %{model} \"%{name}\"") % {:name => @schedule.name, :model => ui_lookup(:model => "MiqSchedule")} :
_("Adding a new %{model}") % {:model => ui_lookup(:model => "MiqSchedule")}
_("Editing Schedule \"%{name}\"") % {:name => @schedule.name} :
_("Adding a new Schedule")
end
else
if @in_a_form
@right_cell_text = if @rpt.id
_("Editing %{model} \"%{name}\"") % {:name => @rpt.name,
:model => ui_lookup(:model => "MiqReport")}
_("Editing Report \"%{name}\"") % {:name => @rpt.name}
else
_("Adding a new %{model}") % {:model => ui_lookup(:model => "MiqReport")}
_("Adding a new Report")
end
end
end
when :schedules_tree
if @in_a_form
presenter[:build_calendar] = true
@right_cell_text = @schedule.id ?
_("Editing %{model} \"%{name}\"") % {:name => @schedule.name, :model => ui_lookup(:model => 'MiqSchedule')} :
_("Adding a new %{model}") % {:model => ui_lookup(:model => 'MiqSchedule')}
_("Editing Schedule \"%{name}\"") % {:name => @schedule.name} :
_("Adding a new Schedule")
end
when :widgets_tree
if @in_a_form
Expand All @@ -741,8 +740,8 @@ def replace_right_cell(options = {}) # :replace_trees key can be an array of tr
presenter[:init_dashboard] = true
end
@right_cell_text = @widget.id ?
_("Editing %{model} \"%{name}\"") % {:name => @widget.name, :model => ui_lookup(:model => 'MiqWidget')} :
_("Adding a new %{model}") % {:model => ui_lookup(:model => 'MiqWidget')}
_("Editing Widget \"%{name}\"") % {:name => @widget.name} :
_("Adding a new Widget")
end
end
elsif nodetype == "g"
Expand Down Expand Up @@ -853,7 +852,7 @@ def replace_right_cell(options = {}) # :replace_trees key can be an array of tr
end

if x_active_tree == :roles_tree && x_node != "root"
@right_cell_text = _("Editing %{model} \"%{name}\"") % {:name => session[:role_choice], :model => ui_lookup(:model => "MiqGroup")}
@right_cell_text = _("Editing EVM Group \"%{name}\"") % {:name => session[:role_choice]}
end
presenter[:right_cell_text] = @right_cell_text

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/report_controller/dashboards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def db_get_node_info
# All groups node is selected
@miq_groups = Rbac.filtered(MiqGroup.non_tenant_groups_in_my_region)
@right_cell_div = "db_list"
@right_cell_text = _("All %{models}") % {:models => ui_lookup(:models => "MiqGroup")}
@right_cell_text = _("All EVM Groups")
elsif @sb[:nodes].length == 3 && @sb[:nodes][1] == "g_g"
g = MiqGroup.find(from_cid(@sb[:nodes].last))
@right_cell_text = _("Dashboards for \"%{name}\"") % {:name => g.description}
Expand Down
10 changes: 4 additions & 6 deletions app/controllers/report_controller/menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,7 @@ def menu_get_all
roles.sort_by { |a| a.name.downcase }.each do |r|
@sb[:menu][r.id] = r.name
end
@right_cell_text = title == "My #{ui_lookup(:model => "MiqGroup")}" ?
title :
_("All %{models}") % {:models => ui_lookup(:models => "MiqGroup")}
@right_cell_text = title
@right_cell_div = "role_list"
@menu_roles_tree = nil
end
Expand All @@ -657,15 +655,15 @@ def get_menu(_nodeid)
# build menu for selected role
get_tree_data
@right_cell_div = "role_list"
@right_cell_text = _("Editing %{model} \"%{name}\"") % {:name => session[:role_choice], :model => ui_lookup(:model => "MiqGroup")}
@right_cell_text = _("Editing EVM Group \"%{name}\"") % {:name => session[:role_choice]}
end

def get_group_roles
if super_admin_user?
roles = MiqGroup.non_tenant_groups
title = "All #{ui_lookup(:models => "MiqGroup")}"
title = _("All EVM Groups")
else
title = "My #{ui_lookup(:model => "MiqGroup")}"
title = _("My EVM Group")
roles = [current_user.current_group]
end
return roles, title
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/report_controller/reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def miq_report_save
savedreports = view.table.data
r = savedreports.first
@right_cell_div = "report_list"
@right_cell_text ||= _("%{model} \"%{name}\"") % {:name => r.name, :model => "Saved Report"}
add_flash(_("%{model} \"%{name}\" was saved") % {:model => ui_lookup(:model => "MiqReport"), :name => r.name})
@right_cell_text ||= _("Saved Report \"%{name}\"") % {:name => r.name}
add_flash(_("Report \"%{name}\" was saved") % {:name => r.name})
replace_right_cell(:replace_trees => [:reports, :savedreports])
end

Expand Down Expand Up @@ -87,18 +87,18 @@ def miq_report_delete
render_flash(_("Report cannot be deleted if it's being used by one or more Widgets"), :error)
else
begin
raise StandardError, "Default %{model} \"%{name}\" cannot be deleted" % {:model => ui_lookup(:model => "MiqReport"), :name => rpt.name} if rpt.rpt_type == "Default"
raise StandardError, "Default Report \"%{name}\" cannot be deleted" % {:name => rpt.name} if rpt.rpt_type == "Default"
rpt_name = rpt.name
audit = {:event => "report_record_delete", :message => "[#{rpt_name}] Record deleted", :target_id => rpt.id, :target_class => "MiqReport", :userid => session[:userid]}
rpt.destroy
rescue => bang
add_flash(_("%{model} \"%{name}\": Error during 'miq_report_delete': %{message}") %
{:model => ui_lookup(:model => "MiqReport"), :name => rpt_name, :message => bang.message}, :error)
add_flash(_("Report \"%{name}\": Error during 'miq_report_delete': %{message}") %
{:name => rpt_name, :message => bang.message}, :error)
javascript_flash
return
else
AuditEvent.success(audit)
add_flash(_("%{model} \"%{name}\": Delete successful") % {:model => ui_lookup(:model => "MiqReport"), :name => rpt_name})
add_flash(_("Report \"%{name}\": Delete successful") % {:name => rpt_name})
end
params[:id] = nil
nodes = x_node.split('_')
Expand Down Expand Up @@ -186,7 +186,7 @@ def get_all_reps(nodeid = nil)
end

@sb[:tree_typ] = "reports"
@right_cell_text = _("%{model} \"%{name}\"") % {:name => @miq_report.name, :model => ui_lookup(:model => "MiqReport")}
@right_cell_text = _("Report \"%{name}\"") % {:name => @miq_report.name}
end

def rep_change_tab
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/report_controller/reports/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def miq_report_edit
case params[:button]
when "cancel"
@edit[:rpt_id] ?
add_flash(_("Edit of %{model} \"%{name}\" was cancelled by the user") % {:model => ui_lookup(:model => "MiqReport"), :name => @edit[:rpt_title]}) :
add_flash(_("Add of new %{model} was cancelled by the user") % {:model => ui_lookup(:model => "MiqReport")})
add_flash(_("Edit of Report \"%{name}\" was cancelled by the user") % {:name => @edit[:rpt_title]}) :
add_flash(_("Add of new Report was cancelled by the user"))
@edit = session[:edit] = nil # clean out the saved info
replace_right_cell
when "add", "save"
Expand Down Expand Up @@ -92,8 +92,8 @@ def miq_report_edit
menu_repname_update(@edit[:current][:name], @edit[:new][:name]) if @edit[:current][:name] != @edit[:new][:name]
AuditEvent.success(build_saved_audit(@rpt, @edit))
@edit[:rpt_id] ?
add_flash(_("%{model} \"%{name}\" was saved") % {:model => ui_lookup(:model => "MiqReport"), :name => @rpt.name}) :
add_flash(_("%{model} \"%{name}\" was added") % {:model => ui_lookup(:model => "MiqReport"), :name => @rpt.name})
add_flash(_("Report \"%{name}\" was saved") % {:name => @rpt.name}) :
add_flash(_("Report \"%{name}\" was added") % {:name => @rpt.name})
# only do this for new reports
unless @edit[:rpt_id]
self.x_node = "xx-#{@sb[:rpt_menu].length}_xx-#{@sb[:rpt_menu].length}-0"
Expand Down
32 changes: 15 additions & 17 deletions app/controllers/report_controller/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def schedule_get_all
session[:schedule_sortdir] = @sortdir

@sb[:tree_typ] = "schedules"
@right_cell_text = _("All %{models}") % {:models => ui_lookup(:models => "MiqSchedule")}
@right_cell_text = _("All Schedules")
@right_cell_div = "schedule_list"
end

Expand Down Expand Up @@ -79,16 +79,16 @@ def miq_report_schedule_delete
if MiqSchedule.exists?(from_cid(params[:id]))
scheds.push(from_cid(params[:id]))
else
add_flash(_("%{model} no longer exists") % {:model => ui_lookup(:model => "MiqSchedule")}, :error)
add_flash(_("Schedule no longer exists"), :error)
end
end
single_name = scheds.first.name if scheds.length == 1
process_schedules(scheds, "destroy") unless scheds.empty?
unless flash_errors?
if single_name
add_flash(_("%{schedule} %{name} was deleted") % {:schedule => ui_lookup(:model => "MiqSchedule"), :name => single_name}, :success, true)
add_flash(_("Schedule %{name} was deleted") % {:name => single_name}, :success, true)
else
add_flash(_("The selected %{schedules} were deleted") % {:schedules => ui_lookup(:models => "MiqSchedule")}, :success, true)
add_flash(_("The selected Schedules were deleted"), :success, true)
end
end
self.x_node = "root"
Expand Down Expand Up @@ -125,21 +125,19 @@ def miq_report_schedule_run_now
def schedule_toggle(enable)
assert_privileges("miq_report_schedule_#{enable ? 'enable' : 'disable'}")
msg1, msg2 = if enable
[_("No %{schedules} were selected to be enabled"),
_("The selected %{schedules} were enabled")]
[_("No Report Schedules were selected to be enabled"),
_("The selected Report Schedules were enabled")]
else
[_("No %{schedules} were selected to be disabled"),
_("The selected %{schedules} were disabled")]
[_("No Report Schedules were selected to be disabled"),
_("The selected Report Schedules were disabled")]
end
scheds = find_records_with_rbac(MiqSchedule, checked_or_params)
if scheds.empty?
add_flash(msg1 % {:schedules => "#{ui_lookup(:model => "MiqReport")} #{ui_lookup(:models => "MiqSchedule")}"},
:error)
add_flash(msg1, :error)
javascript_flash
end
schedule_enable_disable(scheds, enable) unless scheds.empty?
add_flash(msg2 % {:schedules => "#{ui_lookup(:model => "MiqReport")} #{ui_lookup(:models => "MiqSchedule")}"},
:info, true) unless flash_errors?
add_flash(msg2, :info, true) unless flash_errors?
schedule_get_all
replace_right_cell
end
Expand Down Expand Up @@ -212,9 +210,9 @@ def schedule_edit
when "cancel"
@schedule = MiqSchedule.find_by_id(session[:edit][:sched_id]) if session[:edit] && session[:edit][:sched_id]
if !@schedule || @schedule.id.blank?
add_flash(_("Add of new %{model} was cancelled by the user") % {:model => ui_lookup(:model => "MiqSchedule")})
add_flash(_("Add of new Schedule was cancelled by the user"))
else
add_flash(_("Edit of %{model} \"%{name}\" was cancelled by the user") % {:model => ui_lookup(:model => "MiqSchedule"), :name => @schedule.name})
add_flash(_("Edit of Schedule \"%{name}\" was cancelled by the user") % {:name => @schedule.name})
end
@schedule = nil
@edit = session[:edit] = nil # clean out the saved info
Expand All @@ -233,8 +231,8 @@ def schedule_edit
if schedule.valid? && !flash_errors? && schedule.save
AuditEvent.success(build_saved_audit(schedule, @edit))
@edit[:sched_id] ?
add_flash(_("%{model} \"%{name}\" was saved") % {:model => ui_lookup(:model => "MiqSchedule"), :name => schedule.name}) :
add_flash(_("%{model} \"%{name}\" was added") % {:model => ui_lookup(:model => "MiqSchedule"), :name => schedule.name})
add_flash(_("Schedule \"%{name}\" was saved") % {:name => schedule.name}) :
add_flash(_("Schedule \"%{name}\" was added") % {:name => schedule.name})
params[:id] = schedule.id.to_s # reset id in params for show
@edit = session[:edit] = nil # clean out the saved info

Expand Down Expand Up @@ -486,7 +484,7 @@ def build_schedules_tree
def get_schedule(nodeid)
@record = @schedule = MiqSchedule.find(from_cid(nodeid.split('__').last).to_i)
show_schedule
@right_cell_text = _("%{model} \"%{name}\"") % {:name => @schedule.name, :model => ui_lookup(:model => "MiqSchedule")}
@right_cell_text = _("Schedule \"%{name}\"") % {:name => @schedule.name}
@right_cell_div = "schedule_list"
end
end
16 changes: 7 additions & 9 deletions app/controllers/report_controller/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def widget_edit
when "cancel"
@widget = MiqWidget.find_by_id(session[:edit][:widget_id]) if session[:edit] && session[:edit][:widget_id]
if !@widget || @widget.id.blank?
add_flash(_("Add of new %{model} was cancelled by the user") % {:model => ui_lookup(:model => "MiqWidget")})
add_flash(_("Add of new Widget was cancelled by the user"))
else
add_flash(_("Edit of %{model} \"%{name}\" was cancelled by the user") % {:model => ui_lookup(:model => "MiqWidget"), :name => @widget.name})
add_flash(_("Edit of Widget \"%{name}\" was cancelled by the user") % {:name => @widget.name})
end
get_node_info
@widget = nil
Expand All @@ -90,8 +90,7 @@ def widget_edit
widget_set_record_vars(@widget)
if widget_validate_entries && @widget.save_with_shortcuts(@edit[:new][:shortcuts].to_a)
AuditEvent.success(build_saved_audit(@widget, @edit))
add_flash(_("%{model} \"%{name}\" was saved") % {:model => ui_lookup(:model => "MiqWidget"),
:name => @widget.title})
add_flash(_("Widget \"%{name}\" was saved") % {:name => @widget.title})
params[:id] = @widget.id.to_s # reset id in params for show
# Build the filter expression and attach widget to schedule filter
exp = {}
Expand Down Expand Up @@ -124,8 +123,7 @@ def widget_delete
assert_privileges("widget_delete")
widgets = find_checked_items
if !params[:id].nil? && MiqWidget.find_by_id(params[:id]).nil?
add_flash(_("%{model} no longer exists") % {:model => ui_lookup(:models => "MiqWidget")},
:error)
add_flash(_("Widget no longer exists"), :error)
else
widgets.push(params[:id]) if params[:id]
end
Expand Down Expand Up @@ -279,19 +277,19 @@ def widget_get_node_info
@sb[:nodes] = x_node.split('-')
if @sb[:nodes].length == 1
get_all_widgets
@right_cell_text = _("All %{models}") % {:models => ui_lookup(:models => "MiqWidget")}
@right_cell_text = _("All Widgets")
@right_cell_div = "widget_list"
elsif @sb[:nodes].length == 2
# If a folder node is selected
get_all_widgets(WIDGET_CONTENT_TYPE[@sb[:nodes][1]])
@right_cell_div = "widget_list"
@right_cell_text = _("%{typ} %{model}") % {:typ => _(SINGULAR_WIDGET_TYPES[@sb[:nodes][1]]), :model => ui_lookup(:models => "MiqWidget")}
@right_cell_text = _("%{typ} Widgets") % {:typ => _(SINGULAR_WIDGET_TYPES[@sb[:nodes][1]])}
else
@record = @widget = MiqWidget.find_by_id(from_cid(@sb[:nodes].last))
@widget_running = true if ["running", "queued"].include?(@widget.status.downcase)
typ = WIDGET_CONTENT_TYPE.invert[@widget.content_type]
content_type = _(SINGULAR_WIDGET_TYPES[typ])
@right_cell_text = _("%{typ} %{model} \"%{name}\"") % {:typ => content_type, :name => @widget.title, :model => ui_lookup(:model => "MiqWidget")}
@right_cell_text = _("%{typ} Widget \"%{name}\"") % {:typ => content_type, :name => @widget.title}
@right_cell_div = "widget_list"
@sb[:wtype] = WIDGET_CONTENT_TYPE.invert[@widget.content_type]
@sb[:col_order] = []
Expand Down

0 comments on commit 0329d07

Please sign in to comment.