diff --git a/Gemfile b/Gemfile
index c24754c6..7e63e353 100644
--- a/Gemfile
+++ b/Gemfile
@@ -31,6 +31,8 @@ gem 'sprockets'
gem 'tinymce-rails'
gem 'therubyracer' if RUBY_PLATFORM.downcase.include?("linux")
+gem "impressionist", :require => "impressionist", :path => "vendor/impressionist"
+
# Gems used only for assets and not required
# in production environments by default.
group :assets do
diff --git a/Gemfile.lock b/Gemfile.lock
index 0dfca3b6..f6bc8bfd 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -7,6 +7,13 @@ GIT
activesupport (>= 3.0.0)
railties (>= 3.0.0)
+PATH
+ remote: vendor/impressionist
+ specs:
+ impressionist (1.1.1)
+ httpclient (~> 2.2)
+ nokogiri (~> 1.5)
+
GEM
remote: http://rubygems.org/
specs:
@@ -92,6 +99,7 @@ GEM
hike (1.2.1)
hoe (2.16.1)
rake (~> 0.8)
+ httpclient (2.2.5)
i18n (0.6.0)
jquery-rails (1.0.19)
railties (~> 3.0)
@@ -273,6 +281,7 @@ DEPENDENCIES
exception_notification
execjs
factory_girl_rails
+ impressionist!
jquery-rails
jquery-ui-rails
kaminari!
diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb
index 6bfb91ba..50bbd1aa 100644
--- a/app/controllers/admin/dashboards_controller.rb
+++ b/app/controllers/admin/dashboards_controller.rb
@@ -7,6 +7,7 @@ class Admin::DashboardsController < ApplicationController
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')
+ @most_visited = get_most_visited('bulletin', 'news_bulletin', 'page_context')
end
protected
@@ -35,5 +36,18 @@ class Admin::DashboardsController < ApplicationController
sorted_objects = a.sort {|a,b| b[1]<=>a[1]}
sorted_objects[0..9]
end
+
+ 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
diff --git a/app/controllers/admin/object_auths_new_interface_controller.rb b/app/controllers/admin/object_auths_new_interface_controller.rb
index 6c33ff71..6018413b 100644
--- a/app/controllers/admin/object_auths_new_interface_controller.rb
+++ b/app/controllers/admin/object_auths_new_interface_controller.rb
@@ -1,9 +1,7 @@
class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController
include OrbitCoreLib::PermissionUnility
- layout "new_admin"
- before_filter :force_order
- layout "new_admin"
+ before_filter :force_order
def setting
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index 52c39c01..8758563e 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -7,6 +7,7 @@ class PagesController < ApplicationController
def index
@item = Page.find_by_name('home')
if @item
+ impressionist(@item)
render_page
else
render :text => 'You need a home page'
@@ -14,18 +15,19 @@ class PagesController < ApplicationController
end
def show
- #begin
- @item = Item.first(:conditions => {:path => params[:page_name]})
- if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
- case @item._type
- when 'Page'
- render_page
- when 'Link'
- redirect_to @item[:url]
- end
- else
- render :file => "#{Rails.root}/public/404.html", :status => :not_found
- end
+ #begin
+ @item = Item.first(:conditions => {:path => params[:page_name]})
+ if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
+ impressionist(@item)
+ case @item._type
+ when 'Page'
+ render_page
+ when 'Link'
+ redirect_to @item[:url]
+ end
+ else
+ render :file => "#{Rails.root}/public/404.html", :status => :not_found
+ end
#rescue
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
#end
@@ -55,11 +57,7 @@ class PagesController < ApplicationController
def get_item
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
- # if params[:category_id]
- # @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id]})
- # else
- @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action]})
- # end
+ @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action]})
end
end
diff --git a/app/helpers/admin/dashboard_helper.rb b/app/helpers/admin/dashboard_helper.rb
index 4b750fb8..f69185f3 100644
--- a/app/helpers/admin/dashboard_helper.rb
+++ b/app/helpers/admin/dashboard_helper.rb
@@ -3,26 +3,26 @@ module Admin::DashboardHelper
def get_link(title)
case title
when 'bulletin'
- panel_announcement_back_end_bulletins_path
+ panel_announcement_front_end_bulletins_path
when 'news_bulletin'
- panel_news_back_end_news_bulletins_path
+ panel_news_front_end_news_bulletins_path
when'page_context'
- panel_page_content_back_end_page_contexts_path
+ panel_page_content_front_end_page_contexts_path
when'web_link'
- panel_web_resource_back_end_web_links_path
+ panel_web_resource_front_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)
+ panel_announcement_front_end_bulletin_path(object)
when 'news_bulletin'
- panel_news_back_end_news_bulletin_path(object)
+ panel_news_front_end_news_bulletin_path(object)
when'page_context'
- panel_page_content_back_end_page_context_path(object)
+ panel_page_content_front_end_page_context_path(object)
when'web_link'
- panel_web_resource_back_end_web_link_path(object)
+ panel_web_resource_front_end_web_link_path(object)
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d04d8c59..5f693965 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -96,7 +96,6 @@ module ApplicationHelper
end
def visible_for_controllers(*controller_names)
- puts controller_names
(controller_names.include?(controller.controller_name) || controller_names.include?(request.fullpath)) ? '' : 'hide'
end
@@ -173,4 +172,28 @@ module ApplicationHelper
locale.to_sym == I18n.locale ? 'active in': ''
end
+ def dislpay_view_count(object)
+ "#{t(:view_count)}: #{object.view_count}"
+ end
+
+ def display_visitors(options={})
+ Impression.where(options).distinct(:session_hash).count
+ end
+
+ def display_visitors_today
+ display_visitors(created_at: {'$gte' => Date.today.beginning_of_day, '$lte' => Date.today.end_of_day})
+ end
+
+ def display_visitors_this_week
+ display_visitors(created_at: {'$gte' => Date.today.beginning_of_week, '$lte' => Date.today.end_of_week})
+ end
+
+ def display_visitors_this_month
+ display_visitors(created_at: {'$gte' => Date.today.beginning_of_month, '$lte' => Date.today.end_of_month})
+ end
+
+ def display_visitors_this_year
+ display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year})
+ end
+
end
diff --git a/app/models/page.rb b/app/models/page.rb
index 4bcb49a6..970df4cf 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -1,10 +1,14 @@
class Page < Item
+ include Impressionist::Impressionable
+
+ is_impressionable :counter_cache => { :column_name => :view_count }
field :content
field :app_frontend_url
field :theme_id, :type => BSON::ObjectId, :default => nil
field :category
field :tag
+ field :view_count, :type => Integer, :default => 0
belongs_to :design
belongs_to :module_app
diff --git a/app/views/admin/dashboards/index.html.erb b/app/views/admin/dashboards/index.html.erb
index ee0bc920..e81287ac 100644
--- a/app/views/admin/dashboards/index.html.erb
+++ b/app/views/admin/dashboards/index.html.erb
@@ -380,49 +380,7 @@
-
-
-
-
<%= t(:total_visitors) %>438,913
-
-
-
- <%= t(:item) %> |
- <%= t(:data) %> |
-
-
-
-
-
-
+
-->
+
+
+
+
<%= t(:traffic) %>
+
+
<%= t(:total_visitors) %><%= display_visitors %>
+
+
+
+ <%= t(:item) %> |
+ <%= t(:data) %> |
+
+
+
+
+
+
+
<%= t(:recent_update) %>
@@ -517,4 +525,43 @@
+
+
+
+
+
+
+
+ <%= t(:title) %> |
+ <%= t(:module) %> |
+ <%= t(:hits) %> |
+
+
+
+
+
+
\ No newline at end of file
diff --git a/config/initializers/impression.rb b/config/initializers/impression.rb
new file mode 100644
index 00000000..4b57f34a
--- /dev/null
+++ b/config/initializers/impression.rb
@@ -0,0 +1,6 @@
+# Use this hook to configure impressionist parameters
+Impressionist.setup do |config|
+ # Define ORM. Could be :active_record (default) and :mongo_mapper
+ # config.orm = :active_record
+ config.orm = :mongoid
+end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 374b3b33..3e2ffe8e 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -42,6 +42,7 @@ en:
sure?: Are you sure?
update: Update
view: View
+ view_count: View count
yes_: "Yes"
all_content: All Content
@@ -67,6 +68,11 @@ en:
total_visitors: Total Visitors
traffic: Traffic
+ visitors_today: Today's visitors
+ visitors_this_week: This week's visitors
+ visitors_this_month: This month's visitors
+ visitors_this_year: This year's visitors
+
admin:
access:
denied:
diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml
index 7c2ac289..9a1a9952 100644
--- a/config/locales/zh_tw.yml
+++ b/config/locales/zh_tw.yml
@@ -36,11 +36,12 @@ zh_tw:
sure?: 您肯定嗎?
update: 更新
view: 檢視
+ view_count: 查看次數
yes_: "Yes"
- all_content: 全部內容有:
- all_file: 全部檔案有:
- all_member: 成員總數:
+ all_content: 全部內容有
+ all_file: 全部檔案有
+ all_member: 成員總數
content: 內容
data: 數據
file: 檔案
@@ -58,9 +59,14 @@ zh_tw:
site_name: 網站名稱
statistics: 統計
title: 標題
- total_visitors: 造訪次數:
+ total_visitors: 造訪次數
traffic: 流量
+ visitors_today: 今日造訪
+ visitors_this_week: 本星期造訪
+ visitors_this_month: 本月造訪
+ visitors_this_year: 今年造訪
+
admin:
access:
denied:
diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb
index 56cbb312..f21c1a38 100644
--- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb
+++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb
@@ -29,6 +29,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
preview_content
else
@bulletin = Bulletin.can_display.where(_id: params[:id]).first
+ impressionist(@bulletin)
get_categorys
end
diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb
index 43f29344..8098f9a7 100644
--- a/vendor/built_in_modules/announcement/app/models/bulletin.rb
+++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb
@@ -4,6 +4,9 @@ class Bulletin
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
+ include Impressionist::Impressionable
+
+ is_impressionable :counter_cache => { :column_name => :view_count }
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :subtitle, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
@@ -23,6 +26,7 @@ class Bulletin
field :is_pending, :type => Boolean, :default => true
field :is_rejected, :type => Boolean, :default => false
+ field :view_count, :type => Integer, :default => 0
field :not_checked_reason
diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb
index eabacca9..37373ae9 100644
--- a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb
+++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb
@@ -5,6 +5,7 @@
<%= @bulletin.postdate %>
|
<%= User.find(@bulletin.create_user_id).sub_roles.collect{|t| t.key}.join(" ") rescue '' %>
+ <%= dislpay_view_count(@bulletin) %>
diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb
index 57ff9e0a..50b9c266 100644
--- a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb
+++ b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb
@@ -30,6 +30,7 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
preview_content
else
@news_bulletin = NewsBulletin.can_display.where(_id: params[:id]).first
+ impressionist(@news_bulletin)
get_categorys
end
end
diff --git a/vendor/built_in_modules/news/app/models/news_bulletin.rb b/vendor/built_in_modules/news/app/models/news_bulletin.rb
index 538180dc..e6e7d9fc 100644
--- a/vendor/built_in_modules/news/app/models/news_bulletin.rb
+++ b/vendor/built_in_modules/news/app/models/news_bulletin.rb
@@ -3,7 +3,10 @@
class NewsBulletin
include Mongoid::Document
include Mongoid::Timestamps
- include Mongoid::MultiParameterAttributes
+ include Mongoid::MultiParameterAttributes
+ include Impressionist::Impressionable
+
+ is_impressionable :counter_cache => { :column_name => :view_count }
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :subtitle, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
@@ -23,6 +26,7 @@ class NewsBulletin
field :is_pending, :type => Boolean, :default => true
field :is_rejected, :type => Boolean, :default => false
+ field :view_count, :type => Integer, :default => 0
field :not_checked_reason
diff --git a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb
index cc63cd86..8959c6ae 100644
--- a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb
+++ b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb
@@ -5,6 +5,7 @@
<%= @news_bulletin.postdate %>
|
<%= @news_bulletin.unit_list_for_anc.title[I18n.locale] rescue '' %>
+
<%= dislpay_view_count(@news_bulletin) %>
diff --git a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb
index b8842169..e1e98c76 100644
--- a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb
+++ b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb
@@ -6,10 +6,10 @@ class Panel::PageContent::FrontEnd::PageContextsController < OrbitWidgetControll
end
def index
-
- # @page_context = PageContext.where("page_id" => params[:page_id], :archived => false)
- @page_context = PageContext.first(conditions: { page_id: params[:page_id], :archived => false })
-
+ # @page_context = PageContext.where("page_id" => params[:page_id], :archived => false)
+ @page_context = PageContext.first(conditions: { page_id: params[:page_id], :archived => false })
+ impressionist(@page_context)
+
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @page_contexts }
diff --git a/vendor/built_in_modules/page_content/app/models/page_context.rb b/vendor/built_in_modules/page_content/app/models/page_context.rb
index dfbfd4a9..be60db27 100644
--- a/vendor/built_in_modules/page_content/app/models/page_context.rb
+++ b/vendor/built_in_modules/page_content/app/models/page_context.rb
@@ -4,15 +4,17 @@ class PageContext
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
-
+ include Impressionist::Impressionable
include OrbitCoreLib::ObjectAuthable
-
+ is_impressionable :counter_cache => { :column_name => :view_count }
+
has_one :context, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
field :create_user_id
field :update_user_id
field :version, :type => Integer , :default => 0
+ field :view_count, :type => Integer, :default => 0
field :archived, :type => Boolean, :default => false
# field :current, :type => Boolean, :default => false
diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb
index 4f196d59..a27a56e7 100644
--- a/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb
+++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb
@@ -6,3 +6,5 @@
<%= @page_context.page.i18n_variable[I18n.locale] rescue nil %>
<%= @page_context.context[I18n.locale].html_safe rescue nil %>
+
+
<%= dislpay_view_count(@page_context) %>