Add impressionist

This commit is contained in:
Christophe Vilayphiou 2012-05-15 21:26:09 +08:00
parent 53a0fbddf0
commit e54f4409fb
21 changed files with 212 additions and 83 deletions

View File

@ -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

View File

@ -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!

View File

@ -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
@ -36,4 +37,17 @@ class Admin::DashboardsController < ApplicationController
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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -380,49 +380,7 @@
</div>
</div>
</div>
<div class="item element">
<h3><i class="icons-"></i><a href=""><%= t(:traffic) %></a></h3>
<div class="detail w-a h-a">
<p class="totle"><span><%= t(:total_visitors) %></span>438,913</p>
<table class="table table-striped">
<thead>
<tr>
<th><%= t(:item) %></th>
<th class="span2"><%= t(:data) %></th>
</tr>
</thead>
</table>
<div class="detal-list my_scroll">
<div class="scrollbar">
<div class="track">
<div class="thumb">
<div class="end"></div>
</div>
</div>
</div>
<div class="viewport">
<div class="overview">
<table class="table table-striped">
<tbody>
<tr>
<td>Visitors Today</td>
<td>2,304</td>
</tr>
<tr>
<td>Visitors This Month</td>
<td>783</td>
</tr>
<tr>
<td>Visitor This Tear</td>
<td>45</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="item element">
<h3><i class="icons-"></i><a href=""><%= t(:site_info) %></a></h3>
<div class="detail noStatistics w-b h-a">
@ -481,6 +439,56 @@
</div>
</div>
</div> -->
<div class="item element">
<h3><i class="icons-"></i><%= t(:traffic) %></h3>
<div class="detail w-a h-a">
<p class="totle"><span><%= t(:total_visitors) %></span><%= display_visitors %></p>
<table class="table table-striped">
<thead>
<tr>
<th><%= t(:item) %></th>
<th class="span2"><%= t(:data) %></th>
</tr>
</thead>
</table>
<div class="detal-list my_scroll">
<div class="scrollbar">
<div class="track">
<div class="thumb">
<div class="end"></div>
</div>
</div>
</div>
<div class="viewport">
<div class="overview">
<table class="table table-striped">
<tbody>
<tr>
<td><%= t(:visitors_today) %></td>
<td><%= display_visitors_today %></td>
</tr>
<tr>
<td><%= t(:visitors_this_week) %></td>
<td><%= display_visitors_this_week %></td>
</tr>
<tr>
<td><%= t(:visitors_this_month) %></td>
<td><%= display_visitors_this_month %></td>
</tr>
<tr>
<td><%= t(:visitors_this_year) %></td>
<td><%= display_visitors_this_year %></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="item element">
<h3><i class="icons-"></i><%= t(:recent_update) %></h3>
<div class="detail noStatistics w-b h-a">
@ -517,4 +525,43 @@
</div>
</div>
</div>
<div class="item element">
<h3><i class="icons-"></i><a href=""><%= t(:most_visited_page) %></a></h3>
<div class="detail noStatistics w-b h-a">
<table class="table table-striped">
<thead>
<tr>
<th><%= t(:title) %></th>
<th class="span2"><%= t(:module) %></th>
<th class="span2"><%= t(:hits) %></th>
</tr>
</thead>
</table>
<div class="detal-list my_scroll">
<div class="scrollbar">
<div class="track">
<div class="thumb">
<div class="end"></div>
</div>
</div>
</div>
<div class="viewport">
<div class="overview">
<table class="table table-striped">
<tbody>
<% @most_visited.each do |object| %>
<tr>
<td><%= link_to ((object[0].title[I18n.locale] rescue nil) || (object[0].page.i18n_variable[I18n.locale] rescue nil)), get_link_to_object(object[0]) %></td>
<td class="span2"><%= link_to t("dashboard.#{object[0]._type.underscore}"), get_link(object[0]._type.underscore) %></td>
<td class="span2"><%= object[1] %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -5,6 +5,7 @@
<span class="date"><%= @bulletin.postdate %></span>
&nbsp;|&nbsp;
<a href="" class="unit"><%= User.find(@bulletin.create_user_id).sub_roles.collect{|t| t.key}.join(" ") rescue '' %></a>
<span><%= dislpay_view_count(@bulletin) %></span>
</div>
</div>
<div class="news_image">

View File

@ -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

View File

@ -4,6 +4,9 @@ class NewsBulletin
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 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

View File

@ -5,6 +5,7 @@
<span class="date"><%= @news_bulletin.postdate %></span>
&nbsp;|&nbsp;
<a href="" class="unit"><%= @news_bulletin.unit_list_for_anc.title[I18n.locale] rescue '' %></a>
<span><%= dislpay_view_count(@news_bulletin) %></span>
</div>
</div>
<div class="news_image">

View File

@ -6,9 +6,9 @@ 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

View File

@ -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

View File

@ -6,3 +6,5 @@
<h1 class="h1"><%= @page_context.page.i18n_variable[I18n.locale] rescue nil %></h1>
<div class="page_content"><%= @page_context.context[I18n.locale].html_safe rescue nil %></div>
<div><%= dislpay_view_count(@page_context) %></div>