From cbf7ccc13ba90240f6bb5af39561dfeafdbb586a Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 7 Aug 2012 19:21:54 +0800 Subject: [PATCH] 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. --- Gemfile.lock | 2 ++ app/controllers/pages_controller.rb | 36 ++++++++++++------- app/models/item.rb | 5 ++- app/models/page.rb | 4 +-- app/models/user/user.rb | 5 --- app/views/layouts/page_layout.html.erb | 13 ++++++- config/locales/en.yml | 4 ++- config/locales/zh_tw.yml | 4 ++- config/mongoid.yml | 2 +- lib/parsers/parser_common.rb | 2 +- lib/tasks/data_migration.rake | 13 +++++++ .../front_end/bulletins_controller.rb | 19 +++++++--- .../announcement/app/models/bulletin.rb | 29 +++++++-------- .../front_end/bulletins/index.html.erb | 12 +++++-- .../front_end/bulletins/show.html.erb | 2 +- .../announcement/config/routes.rb | 1 + .../front_end/news_bulletins_controller.rb | 18 +++++++--- .../news/app/models/news_bulletin.rb | 4 +++ .../front_end/news_bulletins/index.html.erb | 4 +++ .../front_end/news_bulletins/show.html.erb | 2 +- vendor/built_in_modules/news/config/routes.rb | 1 + 21 files changed, 126 insertions(+), 56 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c7dcecaa2..04f4c69a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -179,6 +179,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) @@ -320,6 +321,7 @@ DEPENDENCIES redis (>= 2.1.1) redis-namespace (~> 1.0.2) redis-search (= 0.7.1) + remotipart resque resque-restriction resque-scheduler diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 4375ba1ab..053660a51 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -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 @@ -11,7 +8,7 @@ class PagesController < ApplicationController if @item impressionist(@item) - render_page + render_page else render :text => 'You need a home page' end @@ -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 + when '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 diff --git a/app/models/item.rb b/app/models/item.rb index f43421af9..4cc226748 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -23,7 +23,10 @@ class Item before_destroy :destroy_children after_rearrange :rebuild_path, :if => "parent_id_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 }) end diff --git a/app/models/page.rb b/app/models/page.rb index 20a512889..cba692d06 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -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 diff --git a/app/models/user/user.rb b/app/models/user/user.rb index f51d49f0f..4cb00bbbb 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -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! diff --git a/app/views/layouts/page_layout.html.erb b/app/views/layouts/page_layout.html.erb index 0a7240ef3..90deba2b6 100644 --- a/app/views/layouts/page_layout.html.erb +++ b/app/views/layouts/page_layout.html.erb @@ -12,6 +12,17 @@ <%= page_javascripts(@item).html_safe %> - <%= yield %> + <%= yield %> + <% if !flash.empty? %> + + + <% end -%> diff --git a/config/locales/en.yml b/config/locales/en.yml index 93fbcc108..2ff1163f3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 @@ -306,3 +307,4 @@ en: sitesearch: Google Site Search site_setting_help: Please Enter the search argument for Google search. result_get: "Searched about ' %{search_word} ' Found %{item_num} items" + unit_get: "Listed items created by :%{unit_name} Found %{item_num} items" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 79251f922..6276cc4ce 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -443,6 +443,7 @@ zh_tw: sitesearch: Google Site Search site_setting_help: 請輸入送交Google搜尋的參數 result_get: "搜尋標題有關 ' %{search_word} ' 共搜尋到%{item_num}筆資料" + unit_get: "列出由:%{unit_name}發佈的資料,共有%{item_num}筆" activerecord: errors: template: # ~ 2.3.5 backward compatible @@ -524,7 +525,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: "重新啓用" \ No newline at end of file diff --git a/config/mongoid.yml b/config/mongoid.yml index 0d68cb7a8..219e13728 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -8,7 +8,7 @@ defaults: &defaults development: <<: *defaults - database: prototype_r4_ldap0229 + database: i18n_var test: <<: *defaults diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index eca375a42..6a9390eae 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -180,7 +180,7 @@ module ParserCommon if (content["main"] == "true" && !page.module_app.nil?) ret << "
" else part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil diff --git a/lib/tasks/data_migration.rake b/lib/tasks/data_migration.rake index 54d8bd0f1..624cf39c3 100644 --- a/lib/tasks/data_migration.rake +++ b/lib/tasks/data_migration.rake @@ -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 \ No newline at end of file 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 685eaa248..6c3a292ea 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 @@ -7,7 +7,12 @@ 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]) if !params[:search_query].blank? @@ -44,10 +49,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 => "
#{t('sys.can_not_display_due_to_no_context')}
".html_safe + end else render :nothing => true, :status => 403 end diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index e70acf57b..08f0cbc68 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -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" @@ -61,7 +63,8 @@ class Bulletin validates :title, :at_least_one => true before_save :check_deadline,:update_status,:update_avliable_language - + + before_save :fetch_dept after_save :save_bulletin_links after_save :save_bulletin_files @@ -94,26 +97,14 @@ class Bulletin self.title_was["en"] end - # def s_text_en - # Nokogiri::HTML(self.text.en).text - # end - # def s_text_zh_tw - # Nokogiri::HTML(self.text.zh_tw).text - # end - - # scope :currently_available, lambda { |category, limit| - # # limit ||= 5 - # # { - # # debugger - # # a=1 - # :where => {:bulletin_category_id => bulletin_category_id, :disable => false}#, - # # :limit => limit - # # } - # } def de_pending self.is_pending = false end + def enabled_for_lang(lang) + eval("self.available_for_#{lang}") + end + def publish_month published_at.strftime("%B %Y") end @@ -240,4 +231,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 \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb index 1bb363d07..58d3c1096 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb @@ -7,10 +7,16 @@ - + <%= content_tag (:th) do %> + <%= t('announcement.bulletin.category') %> + <% end if (!params[:search_query].blank? or params[:category_id].blank?)-%> + <% 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? %> @@ -18,7 +24,9 @@ <% end %> <% @bulletins.each do |post| %> > - + <%= content_tag(:th) do%> + + <% end if(!params[:search_query].blank? or params[:category_id].blank?) %> 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 af1ca12c3..b6dbb177f 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 @@ -4,7 +4,7 @@
<%= dislpay_view_count(@bulletin) %> <%= display_date_time(@bulletin.postdate) %> - <%= User.find(@bulletin.create_user_id).cache_dept[I18n.locale.to_s] rescue nil %> + <%= 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 %>
diff --git a/vendor/built_in_modules/announcement/config/routes.rb b/vendor/built_in_modules/announcement/config/routes.rb index ce6c5ec34..0640a1f05 100644 --- a/vendor/built_in_modules/announcement/config/routes.rb +++ b/vendor/built_in_modules/announcement/config/routes.rb @@ -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 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 87826f021..2173254d8 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 @@ -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? @@ -42,10 +48,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 => "
#{t('sys.can_not_display_due_to_no_context')}
".html_safe + end else render :nothing => true, :status => 403 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 3fdabd56d..03f822818 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin.rb @@ -140,6 +140,10 @@ class NewsBulletin end + def enabled_for_lang(lang) + eval("self.available_for_#{lang}") + end + def de_pending self.is_pending = false end diff --git a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb index 23708c132..8b93b3526 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb @@ -4,6 +4,10 @@

<%= @page.title %>

+<% 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? %> 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 edd8a9e1a..239667df5 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 @@ -6,7 +6,7 @@ <%= display_date(@news_bulletin.postdate) %> <% unit = @news_bulletin.unit_list_for_anc.title rescue nil %> <%= " | " if unit %> - <%= unit %> + <%= link_to unit, panel_news_front_end_index_news_bulletins_by_unit_path(:name=>@news_bulletin.unit_list_for_anc_id)%>
diff --git a/vendor/built_in_modules/news/config/routes.rb b/vendor/built_in_modules/news/config/routes.rb index e78f28748..701136e5a 100644 --- a/vendor/built_in_modules/news/config/routes.rb +++ b/vendor/built_in_modules/news/config/routes.rb @@ -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
<%= t('announcement.bulletin.category') %><%= t('announcement.bulletin.title') %> <%= t('announcement.bulletin.postdate') %>
<%= (post.bulletin_category.title rescue nil ) if !params[:search_query].blank? %><%= (post.bulletin_category.title rescue nil ) %><%= 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) %>