1.Remove category column when category is specified

2.Showing category if not in category browsing
3.Redirect to home and show error if app page is not available for user language
4.Showing no context to display if object has no language for it.
5.Browse new and announcement by unit is now applicable.
This commit is contained in:
Matthew K. Fu JuYuan 2012-08-07 19:21:54 +08:00 committed by Christophe Vilayphiou
parent b4c2dfe0ef
commit e8317e0a4b
21 changed files with 130 additions and 42 deletions

View File

@ -186,6 +186,7 @@ GEM
chinese_pinyin (>= 0.3.0)
redis (>= 2.1.1)
redis-namespace (~> 1.0.2)
remotipart (1.0.2)
resque (1.20.0)
multi_json (~> 1.0)
redis-namespace (~> 1.0.2)
@ -332,6 +333,7 @@ DEPENDENCIES
redis (>= 2.1.1)
redis-namespace (~> 1.0.2)
redis-search (= 0.7.1)
remotipart
resque
resque-restriction
resque-scheduler

View File

@ -1,9 +1,6 @@
class PagesController < ApplicationController
include ApplicationHelper
before_filter :get_item, :only => [:index_from_link, :show_from_link]
# caches_page :index
def index
@ -19,14 +16,15 @@ class PagesController < ApplicationController
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))
if @item && @item.is_published #&& (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
impressionist(@item)
case @item.class.to_s
when 'Page'
render_page
render_page unless save_from_no_lang_for_page
when 'Link'
redirect_to @item[:url]
redirect_to(@item[:url]) unless save_from_no_lang_for_page
end
else
render :file => "#{Rails.root}/public/404.html", :status => :not_found
@ -43,15 +41,17 @@ class PagesController < ApplicationController
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
uri = URI::escape(url + options)
redirect_to uri
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
redirect_to(uri)unless save_from_no_lang_for_page
end
def show_from_link
url = "/#{@item.path}?id=#{params[:id]}"
options = ''
options << "&preview=#{params[:preview]}" unless params[:preview].blank?
redirect_to url + options
redirect_to(url + options) unless save_from_no_lang_for_page
end
def load_orbit_bar
@ -66,12 +66,22 @@ class PagesController < ApplicationController
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item
elsif !params[:category_id].blank?
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''})
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],category: params[:category_id]).any_in(tag: [nil,'']).first
elsif !params[:tag_id].blank?
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => '', :tag => params[:tag_id]})
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],tag: params[:tag_id]).any_in(category: [nil,'']).first
end
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => '', :tag => ''}) unless @item
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item
#TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性
end
protected
def save_from_no_lang_for_page
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
flash[:notice] = t('sys.module_page_lang_not_support')
redirect_to '/'
return true
else
return false
end
end
end

View File

@ -23,6 +23,9 @@ class Item
before_destroy :destroy_children
after_rearrange :rebuild_path, :if => "parent_id_changed? || name_changed?"
def enabled_for_lang(lang)
enabled_for.include?(lang)
end
def self.find_by_name(item_name)
Item.first(:conditions => { :name => item_name, :is_published => true })

View File

@ -6,8 +6,8 @@ class Page < Item
field :content
field :app_frontend_url
field :theme_id, :type => BSON::ObjectId, :default => nil
field :category
field :tag
field :category, :default => ''
field :tag, :default => ''
field :view_count, :type => Integer, :default => 0
field :page_title, localize: true

View File

@ -31,12 +31,7 @@ class User
VALID_LOCALES.each do |loc|
locale = loc.to_sym
# debugger
# if(self.cache_dept.nil?)
# self.build_cache_dept key: "dept_cache_user_#{self.id}"
# end
dept_hash[locale] = sub_roles.collect{|sr| sr.title}.join(',')
# self.cache_dept[locale] = sub_roles.collect{|sr| sr.title}.join(',')
end
self.cache_dept = dept_hash
self.save!

View File

@ -12,6 +12,17 @@
<%= page_javascripts(@item).html_safe %>
</head>
<body>
<%= yield %>
<%= yield %>
<% if !flash.empty? %>
<div class="modal alert alert-error hide" id="myModal">
<p type="button" class="close" data-dismiss="modal">×</p>
<% flash.each do |key, msg| %>
<%= "<strong>#{msg}</strong><br/>".html_safe%>
<% end%>
</div>
<script>
$('#myModal').modal('show')
</script>
<% end -%>
</body>
</html>

View File

@ -298,7 +298,8 @@ en:
sys:
not_previewable: "Preview not support"
limit_of_upload_file_size: "Upload file must be less than: %{best_size}"
can_not_display_due_to_no_context: "Can not display due to no context for English"
module_page_lang_not_support: "We are sorry, this page is not available for English"
search:
not_found: "NOT FOUND"
domains: Google Search Domains
@ -307,3 +308,4 @@ en:
site_setting_help: Please Enter the search argument for Google search.
result_get: "Searched about ' %{search_word} ' Found %{item_num} items"
too_many: "Search about ' %{search_word} 'resulted more than %{exceed_num} items maybe try to search with more specific terms?"
unit_get: "Listed items created by :%{unit_name} Found %{item_num} items"

View File

@ -445,6 +445,8 @@ zh_tw:
result_get: "搜尋有關 ' %{search_word} ' 共搜尋到%{item_num}筆資料"
too_many: "搜尋有關 ' %{search_word} ' 尋找到超過 %{exceed_num} 筆資料,請嘗試加入更多關鍵字縮小搜尋範圍,以作更精確的搜尋"
result_get: "搜尋標題有關 ' %{search_word} ' 共搜尋到%{item_num}筆資料"
unit_get: "列出由:%{unit_name}發佈的資料,共有%{item_num}筆"
activerecord:
errors:
template: # ~ 2.3.5 backward compatible
@ -526,7 +528,8 @@ zh_tw:
sys:
not_previewable: "不支援預覽"
limit_of_upload_file_size: "上傳檔案大小限制: %{best_size}"
can_not_display_due_to_no_context: "因為沒有中文版本,所以無法顯示"
module_page_lang_not_support: "很抱歉,本頁沒有開放中文版本"
object_disable:
change_to_true: "設為停用"
change_to_false: "重新啓用"

View File

@ -8,7 +8,7 @@ defaults: &defaults
development:
<<: *defaults
database: prototype_r4_ldap0229
database: i18n_var
test:
<<: *defaults

View File

@ -180,7 +180,7 @@ module ParserCommon
if (content["main"] == "true" && !page.module_app.nil?)
ret << "<div id='appfrontend' class='dymanic_load' path='/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}"
ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(page.id.to_s)
ret << "?inner=true&page_id=#{page.id}&category_id=#{category}&tag_id=#{tag}&preview=#{params[:preview]}&page_main=#{params[:page_main]}&search_query=#{params[:search_query]}"
ret << "?inner=true&page_id=#{page.id}&category_id=#{category}&tag_id=#{tag}&preview=#{params[:preview]}&page_main=#{params[:page_main]}&search_query=#{params[:search_query]}&name=#{params[:name]}"
ret << "'></div>"
else
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil

View File

@ -83,4 +83,17 @@ namespace :data_migration do
puts("#{'='*10}Finished#{'='*10}")
end
task :make_bulletin_save_dept_data => :environment do
Bulletin.all.each{|bt| bt.save!}
end
task :extend_exsisted_app_module_for_dept_search => :environment do
app = ModuleApp.first({:conditions=>{:title => 'news'}})
app.app_pages << "index_by_unit" if !app.widgets.include?("index_by_unit")
app.save!
app = ModuleApp.first({:conditions=>{:title => 'Announcement'}})
app.app_pages << "index_by_unit" if !app.widgets.include?("index_by_unit")
app.save!
end
end

View File

@ -7,6 +7,11 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
# GET /bulletins
# GET /bulletins.xml
def index_bulletins_by_unit
@page = Page.find(params[:page_id])
@bulletins=Bulletin.all.available_for_lang(I18n.locale).can_display.where("cache_dept.#{I18n.locale.to_s.downcase}"=>params[:name]).page( params[:page_main]).per(15)
render :index
end
def index
@page = Page.find(params[:page_id])
@ -48,10 +53,14 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
if params[:preview] == "true"
preview_content
else
@bulletin = Bulletin.all.available_for_lang(I18n.locale).can_display.where(_id: params[:id]).first
unless @bulletin.disable?
impressionist(@bulletin)
get_categorys
@bulletin = Bulletin.all.can_display.where(_id: params[:id]).first
if !@bulletin.disable?
if @bulletin.enabled_for_lang(I18n.locale.to_s)
impressionist(@bulletin)
get_categorys
else
render :text => "<div class='alert alert-error'>#{t('sys.can_not_display_due_to_no_context')}</div>".html_safe
end
else
render :nothing => true, :status => 403
end

View File

@ -25,6 +25,8 @@ class Bulletin
field :postdate , :type => DateTime
field :deadline , :type => DateTime
# field :url
field :cache_dept,type: Hash
field :create_user_id
field :update_user_id, :class_name => "User"
@ -60,8 +62,9 @@ class Bulletin
validates :title, :at_least_one => true
before_save :check_deadline,:update_avliable_language
before_save :check_deadline,:update_status,:update_avliable_language
before_save :fetch_dept
after_save :save_bulletin_links
after_save :save_bulletin_files
@ -103,6 +106,11 @@ class Bulletin
self.save!
end
def enabled_for_lang(lang)
eval("self.available_for_#{lang}")
end
def publish_month
published_at.strftime("%B %Y")
end
@ -214,4 +222,8 @@ class Bulletin
end
end
def fetch_dept
self.cache_dept = (User.current.cache_dept rescue nil) || (User.find(self.create_user_id).cache_dept rescue nil)
end
end

View File

@ -7,10 +7,16 @@
<table class="table table-bordered">
<tr>
<th><%= t('announcement.bulletin.category') %></th>
<%= content_tag (:th) do %>
<%= t('announcement.bulletin.category') %>
<% end if (!params[:search_query].blank? or params[:category_id].blank?)-%>
<th><%= t('announcement.bulletin.title') %></th>
<th><%= t('announcement.bulletin.postdate') %></th>
</tr>
<% if !params[:name].blank?%>
<%= t("search.unit_get",:unit_name => params[:name],:item_num=>@bulletins.count) %>
<% end %>
<% if @bulletins.blank? and !params[:search_query].blank? %>
<%=render :partial => 'shared/search_not_found' %>
<% elsif !params[:search_query].blank? %>
@ -20,7 +26,9 @@
<% @bulletins.each do |post| %>
<tr class=<%= cycle('odd', '') %>>
<td><%= (post.bulletin_category.title rescue nil ) if !params[:search_query].blank? %></td>
<%= content_tag(:th) do%>
<td><%= (post.bulletin_category.title rescue nil ) %></td>
<% end if(!params[:search_query].blank? or params[:category_id].blank?) %>
<td><%= link_to post.title, panel_announcement_front_end_bulletin_path(post, :category_id => post.bulletin_category_id) %>
<%#= link_to post.title, panel_announcement_back_end_bulletin_path(post) %>
</td>

View File

@ -4,7 +4,7 @@
<div class="info1">
<span class="pull-right"><%= dislpay_view_count(@bulletin) %></span>
<span class="date"><%= display_date_time(@bulletin.postdate) %></span>
<span><%= User.find(@bulletin.create_user_id).cache_dept[I18n.locale.to_s] rescue nil %></span>
<span><%= link_to @bulletin.cache_dept[I18n.locale.to_s],panel_announcement_front_end_index_bulletins_by_unit_path(:name=>@bulletin.cache_dept[I18n.locale.to_s]) rescue nil %></span>
</div>
</div>
<div class="news_image">

View File

@ -34,6 +34,7 @@ Rails.application.routes.draw do
resources :tags
end
namespace :front_end do
match "index_by_unit" => "bulletins#index_bulletins_by_unit",:as => :index_bulletins_by_unit
resources :bulletins # do
# match "preview" => "bulletins#preview_content",:as => :get_preview_content
# end

View File

@ -8,6 +8,12 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
# GET /news_bulletins
# GET /news_bulletins.xml
def index_news_bulletins_by_unit
@page = Page.find(params[:page_id])
@news_bulletins=NewsBulletin.all.available_for_lang(I18n.locale).can_display.where("unit_list_for_anc_id"=>params[:name]).page( params[:page_main]).per(15).page( params[:page_main]).per(10)
render :index
end
def index
@page = Page.find(params[:page_id])
if !params[:search_query].blank?
@ -47,10 +53,14 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
preview_content
else
''
@news_bulletin = NewsBulletin.all.available_for_lang(I18n.locale).can_display.where(_id: params[:id]).first
unless @news_bulletin.disable?
impressionist(@news_bulletin)
get_categorys
@news_bulletin = NewsBulletin.all.can_display.where(_id: params[:id]).first
if !@news_bulletin.disable?
if @news_bulletin.enabled_for_lang(I18n.locale.to_s)
impressionist(@news_bulletin)
get_categorys
else
render :text => "<div class='alert alert-error'>#{t('sys.can_not_display_due_to_no_context')}</div>".html_safe
end
else
render :nothing => true, :status => 403
end

View File

@ -166,6 +166,10 @@ class NewsBulletin
end
end
def enabled_for_lang(lang)
eval("self.available_for_#{lang}")
end
def de_pending
self.is_pending = false
end

View File

@ -4,6 +4,10 @@
<h1 class="h1"><%= @page.title %></h1>
<% if !params[:name].blank?%>
<%= t("search.unit_get",:unit_name => UnitListForAnc.find(params[:name]).title,:item_num=>@news_bulletins.count) %>
<% end %>
<% if @news_bulletins.blank? and !params[:search_query].blank? %>
<%=render :partial => 'shared/search_not_found' %>
<% elsif !params[:search_query].blank? %>

View File

@ -6,7 +6,7 @@
<span class="date"><%= display_date(@news_bulletin.postdate) %></span>
<% unit = @news_bulletin.unit_list_for_anc.title rescue nil %>
<%= " | " if unit %>
<a href="" class="unit"><%= unit %></a>
<%= link_to unit, panel_news_front_end_index_news_bulletins_by_unit_path(:name=>@news_bulletin.unit_list_for_anc_id)%>
</div>
</div>
<div class="news_image">

View File

@ -34,6 +34,7 @@ Rails.application.routes.draw do
resources :tags
end
namespace :front_end do
match "index_by_unit" => "news_bulletins#index_news_bulletins_by_unit",:as => :index_news_bulletins_by_unit
resources :news_bulletins # do
# match "preview" => "news_bulletins#preview_content",:as => :get_preview_content
# end