From a3b8c9ccf080f61a1382460aa4143441d57523ff Mon Sep 17 00:00:00 2001 From: Martin Povolny Date: Wed, 22 Feb 2017 21:29:50 +0100 Subject: [PATCH] Move #show_dashboard support to mixins. --- app/controllers/ems_common.rb | 21 +------------------ .../mixins/dashboard_view_mixin.rb | 8 +++++++ app/controllers/mixins/generic_show_mixin.rb | 16 +++++++++++--- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/app/controllers/ems_common.rb b/app/controllers/ems_common.rb index a35695f49023..fe3bbfb548f6 100644 --- a/app/controllers/ems_common.rb +++ b/app/controllers/ems_common.rb @@ -17,7 +17,7 @@ def textual_group_list end def show_props - drop_breadcrumb(:name => @ems.name + _(" (Properties)"), :url => show_link(@ems, :display => "props")) + drop_breadcrumb(:name => @ems.name + _(" (Properties)"), :url => show_link(@ems, :display => "props")) end def show_ems_folders @@ -35,19 +35,6 @@ def show_ems_folders self.x_active_tree = :vat_tree end - def show_dashboard - @showtype = "dashboard" - @lastaction = "show_dashboard" - drop_breadcrumb(:name => @ems.name + _(" (Dashboard)"), :url => show_link(@ems)) - @sb[:summary_mode] = 'dashboard' unless @sb[:summary_mode] == 'dashboard' - render :action => "show_dashboard" - end - - def show_main - @sb[:summary_mode] = 'textual' unless @sb[:summary_mode] == 'textual' - super - end - def show_ad_hoc_metrics @showtype = "ad_hoc_metrics" @lastaction = "show_ad_hoc_metrics" @@ -1141,12 +1128,6 @@ def permission_prefix self.class.permission_prefix end - def show_link(ems, options = {}) - url_for(options.merge(:controller => @table_name, - :action => "show", - :id => ems.id)) - end - def show_list_link(ems, options = {}) url_for(options.merge(:controller => @table_name, :action => "show_list", diff --git a/app/controllers/mixins/dashboard_view_mixin.rb b/app/controllers/mixins/dashboard_view_mixin.rb index a1b1e9894fcc..eca53563601a 100644 --- a/app/controllers/mixins/dashboard_view_mixin.rb +++ b/app/controllers/mixins/dashboard_view_mixin.rb @@ -7,5 +7,13 @@ def dashboard_view (@settings.fetch_path(:views, :summary_mode) || "dashboard") == 'dashboard' end end + + def show_dashboard + @showtype = "dashboard" + @lastaction = "show_dashboard" + drop_breadcrumb(:name => @record.name + _(" (Dashboard)"), :url => show_link(@record)) + @sb[:summary_mode] = 'dashboard' unless @sb[:summary_mode] == 'dashboard' + render :action => "show_dashboard" + end end end diff --git a/app/controllers/mixins/generic_show_mixin.rb b/app/controllers/mixins/generic_show_mixin.rb index ebf61b03fe96..b1b26f6704d2 100644 --- a/app/controllers/mixins/generic_show_mixin.rb +++ b/app/controllers/mixins/generic_show_mixin.rb @@ -32,18 +32,28 @@ def show_download end def show_main + # remember dashboard mode if dashboard is supported for this controller + @sb[:summary_mode] = 'textual' if respond_to?(:dashboard_view) + get_tagdata(@record) if @record.try(:taggings) drop_breadcrumb({:name => breadcrumb_name(nil), :url => "/#{controller_name}/show_list?page=#{@current_page}&refresh=y"}, true) - show_url = restful? ? "/#{controller_name}/" : "/#{controller_name}/show/" - drop_breadcrumb(:name => _("%{name} (Summary)") % {:name => @record.name}, - :url => "#{show_url}#{@record.id}") + :url => show_link(@record)) @showtype = "main" end + def show_link(record, options = {}) + opts = options.merge( + :controller => self.class.table_name, + :id => record.id, + :action => restful? ? :index : :show + ) + url_for(opts) + end + def gtl_url restful? ? '/' : '/show' end