diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb index b7f377d3..6bfb91ba 100644 --- a/app/controllers/admin/dashboards_controller.rb +++ b/app/controllers/admin/dashboards_controller.rb @@ -5,6 +5,35 @@ class Admin::DashboardsController < ApplicationController # before_filter :is_admin? def index + @module_app_contents, @module_app_contents_total = get_module_app_count('bulletin', 'news_bulletin', 'page_context', 'web_link') + @recent_updated = get_recently_updated('bulletin', 'news_bulletin', 'page_context', 'web_link') + end + + protected + + def get_module_app_count(*args) + a = {} + total = 0 + args.each do |module_app| + module_app_class = module_app.classify.constantize + count = module_app_class.count + a.merge!(module_app => count) + total += count + end + [a.sort {|a,b| b[1]<=>a[1]}, total] + end + + def get_recently_updated(*args) + a = {} + args.each do |module_app| + module_app_class = module_app.classify.constantize + objects = module_app_class.order_by(:updated_at, :desc).limit(10) + objects.each do |object| + a.merge!(object => object.updated_at) + end + end + sorted_objects = a.sort {|a,b| b[1]<=>a[1]} + sorted_objects[0..9] end end diff --git a/app/helpers/admin/dashboard_helper.rb b/app/helpers/admin/dashboard_helper.rb new file mode 100644 index 00000000..4b750fb8 --- /dev/null +++ b/app/helpers/admin/dashboard_helper.rb @@ -0,0 +1,29 @@ +module Admin::DashboardHelper + + def get_link(title) + case title + when 'bulletin' + panel_announcement_back_end_bulletins_path + when 'news_bulletin' + panel_news_back_end_news_bulletins_path + when'page_context' + panel_page_content_back_end_page_contexts_path + when'web_link' + panel_web_resource_back_end_web_links_path + end + end + + def get_link_to_object(object) + case object._type.underscore + when 'bulletin' + panel_announcement_back_end_bulletin_path(object) + when 'news_bulletin' + panel_news_back_end_news_bulletin_path(object) + when'page_context' + panel_page_content_back_end_page_context_path(object) + when'web_link' + panel_web_resource_back_end_web_link_path(object) + end + end + +end \ No newline at end of file diff --git a/app/views/admin/dashboards/index.html.erb b/app/views/admin/dashboards/index.html.erb index e22d7dac..aee3e1ac 100644 --- a/app/views/admin/dashboards/index.html.erb +++ b/app/views/admin/dashboards/index.html.erb @@ -1,8 +1,8 @@
<%= t(:all_content) %>9,517
+<%= t(:all_content) %><%= @module_app_contents_total %>
公告 | -2,304 | -
新聞 | -783 | -
連結 | -45 | -
連結 | -62 | -
連結 | -52 | -
新聞 | -20 | -
公告 | -41 | -
公告 | -37 | -
公告 | -41 | -
公告 | -20 | -
<%= link_to t("dashboard.#{module_app_content[0]}"), get_link(module_app_content[0]) %> | +<%= module_app_content[1] %> | +
Title1 | -公告 | -
Title2 | -頁面 | -
Title3 | -頁面 | -
Title4 | -公告 | -
Title5 | -公告 | -
Title6 | -頁面 | -
Title7 | -頁面 | -
Title8 | -公告 | -
Title9 | -頁面 | -
Title10 | -公告 | -
<%= link_to ((object[0].title[I18n.locale] rescue nil) || (object[0].page.i18n_variable[I18n.locale] rescue nil)), get_link_to_object(object[0]) %> | +<%= link_to t("dashboard.#{object[0]._type.underscore}"), get_link(object[0]._type.underscore) %> | +