From 2b03263fb7787bebcf98835f827923f681ece350 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Wed, 9 May 2012 05:53:07 +0800 Subject: [PATCH] Dashboard partial implementation --- .../admin/dashboards_controller.rb | 29 +++++ app/helpers/admin/dashboard_helper.rb | 29 +++++ app/views/admin/dashboards/index.html.erb | 110 ++++-------------- config/locales/en.yml | 8 +- config/locales/zh_tw.yml | 6 + 5 files changed, 91 insertions(+), 91 deletions(-) create mode 100644 app/helpers/admin/dashboard_helper.rb 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(:content) %>

-
-

<%= t(:all_content) %>9,517

+

<%= t(:content) %>

+
+

<%= t(:all_content) %><%= @module_app_contents_total %>

@@ -23,46 +23,12 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + <% @module_app_contents.each do |module_app_content| %> + + + + + <% end %>
公告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] %>
@@ -70,7 +36,7 @@
-
+

<%= t(:referral_in_links) %>

@@ -283,7 +249,7 @@
-
+ @@ -515,11 +480,10 @@ - + -->
@@ -540,46 +504,12 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + <% @recent_updated.each do |object| %> + + + + + <% end %>
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) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 8384d519..8be24e7f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -242,7 +242,13 @@ en: info: User information panel: User panel role: User role - + + dashboard: + bulletin: Announcement + news_bulletin: News + page_context: Page + web_link: Link + panel: modal: diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 6170e3d5..3365cef2 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -238,6 +238,12 @@ zh_tw: panel: 用戶面板 role: 用戶身份 + dashboard: + bulletin: 公告 + news_bulletin: 新聞 + page_context: 頁面 + web_link: 鏈接 + panel: