2012-08-23 08:05:14 +00:00
|
|
|
class Admin::DashboardsController < OrbitBackendController
|
2013-07-02 08:46:44 +00:00
|
|
|
|
2012-08-23 08:05:14 +00:00
|
|
|
#before_filter :set_current_user
|
|
|
|
#before_filter :authenticate_user!, :except => [:index]
|
2012-04-29 19:14:15 +00:00
|
|
|
# before_filter :is_admin?
|
2013-07-02 08:46:44 +00:00
|
|
|
|
|
|
|
layout "basic_back_end"
|
2012-02-13 05:02:52 +00:00
|
|
|
|
|
|
|
def index
|
2013-04-23 10:48:18 +00:00
|
|
|
check_backend_openness
|
|
|
|
@module_app_contents, @module_app_contents_total = get_module_app_count('bulletin', 'page_context', 'web_link')
|
|
|
|
@recent_updated = get_recently_updated('bulletin', 'page_context', 'web_link')
|
2012-11-22 01:30:25 +00:00
|
|
|
@most_visited = get_most_visited('bulletin', 'page_context')
|
2012-05-08 21:53:07 +00:00
|
|
|
end
|
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
def reload_all_content
|
|
|
|
@module_app_contents, @module_app_contents_total = get_module_app_count('bulletin', 'page_context', 'web_link')
|
|
|
|
respond_to do |format|
|
|
|
|
format.js { render 'reload', locals: {div_id: 'all_content'} }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload_most_visited
|
|
|
|
@most_visited = get_most_visited('bulletin', 'page_context')
|
|
|
|
respond_to do |format|
|
|
|
|
format.js { render 'reload', locals: {div_id: 'most_visited'} }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload_recent_update
|
|
|
|
@recent_updated = get_recently_updated('bulletin', 'page_context', 'web_link')
|
|
|
|
respond_to do |format|
|
|
|
|
format.js { render 'reload', locals: {div_id: 'recent_update'} }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-08 21:53:07 +00:00
|
|
|
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
|
2013-07-02 08:46:44 +00:00
|
|
|
[Kaminari.paginate_array(a.sort {|a,b| b[1]<=>a[1]}).page(params[:page]).per(5), total]
|
2012-05-08 21:53:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_recently_updated(*args)
|
|
|
|
a = {}
|
|
|
|
args.each do |module_app|
|
|
|
|
module_app_class = module_app.classify.constantize
|
2013-07-02 08:46:44 +00:00
|
|
|
objects = module_app_class.order_by(:updated_at, :desc).limit(20)
|
2012-05-08 21:53:07 +00:00
|
|
|
objects.each do |object|
|
2012-05-18 06:13:11 +00:00
|
|
|
a.merge!(object => object.updated_at) unless (object.archived rescue nil)
|
2012-05-08 21:53:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
sorted_objects = a.sort {|a,b| b[1]<=>a[1]}
|
2013-07-02 08:46:44 +00:00
|
|
|
sorted_objects[0..19]
|
|
|
|
Kaminari.paginate_array(sorted_objects).page(params[:page]).per(5)
|
2012-02-13 05:02:52 +00:00
|
|
|
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
|
2013-07-02 08:46:44 +00:00
|
|
|
objects = module_app_class.order_by(:view_count, :desc).limit(20)
|
2012-05-15 13:26:09 +00:00
|
|
|
objects.each do |object|
|
2012-05-18 06:13:11 +00:00
|
|
|
a.merge!(object => object.view_count) if object.view_count > 0 && (!object.archived rescue true)
|
2012-05-15 13:26:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
sorted_objects = a.sort {|a,b| b[1]<=>a[1]}
|
2013-07-02 08:46:44 +00:00
|
|
|
sorted_objects[0..19]
|
|
|
|
Kaminari.paginate_array(sorted_objects).page(params[:page]).per(5)
|
2012-05-15 13:26:09 +00:00
|
|
|
end
|
2012-02-13 05:02:52 +00:00
|
|
|
|
|
|
|
end
|