diff --git a/Gemfile.lock b/Gemfile.lock index 96f07221a..463946c37 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 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 c20eadde2..ae086c7d3 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? || 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 }) 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 75dbd2901..ae73e59d0 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 7a85ddff2..a3e295ff0 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 @@ -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" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index d1a157730..28bc5e1dc 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -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: "重新啓用" \ 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 ac524859d..0adc848b9 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? @@ -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 => "
#{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 1cda9cb4f..f4cf9ae33 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" @@ -59,9 +61,10 @@ class Bulletin accepts_nested_attributes_for :bulletin_links, :allow_destroy => true 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 \ 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 421a347a9..9ba18b9c9 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? %> @@ -20,7 +26,9 @@ <% @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 c8cc6bea0..a26f92006 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 1d3bb4077..e2cdf2892 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? @@ -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 => "
#{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 8d93dfc4d..578714c6d 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin.rb @@ -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 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 c1788d13d..3324928c7 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 a1d4097b7..7366127af 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) %>