This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/admin/dashboards_controller.rb

54 lines
1.5 KiB
Ruby
Raw Normal View History

class Admin::DashboardsController < ApplicationController
layout "new_admin"
before_filter :authenticate_user!
# before_filter :is_admin?
def index
2012-05-08 21:53:07 +00:00
@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')
2012-05-15 13:26:09 +00:00
@most_visited = get_most_visited('bulletin', 'news_bulletin', 'page_context')
2012-05-08 21:53:07 +00:00
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
2012-05-15 13:26:09 +00:00
def get_most_visited(*args)
a = {}
args.each do |module_app|
module_app_class = module_app.classify.constantize
objects = module_app_class.order_by(:view_count, :desc).limit(10)
objects.each do |object|
a.merge!(object => object.view_count) if object.view_count > 0
end
end
sorted_objects = a.sort {|a,b| b[1]<=>a[1]}
sorted_objects[0..9]
end
end