diff --git a/lib/tasks/data_migration.rake b/lib/tasks/data_migration.rake index 842c327d5..5d5f54467 100644 --- a/lib/tasks/data_migration.rake +++ b/lib/tasks/data_migration.rake @@ -44,4 +44,19 @@ namespace :data_migration do sr.save! end + task :make_bulletins_and_news_has_language_flag => :environment do + [Bulletin,NewsBulletin].each do |bulletin| + puts "="*10 + bulletin.to_s + "="*10 + bulletin.all.each do |bt| + result = if (bt.save(:validate => false) rescue false ) + "OK" + else + 'Failed' + end + puts(bt.title+"----------#{result}") + end + end + puts("#{'='*10}Finished#{'='*10}") + 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 113c7f843..d970ee1c4 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 @@ -15,18 +15,18 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController search = Redis::Search.query("Bulletin", params[:search_query], :conditions =>search_cond,:limit=>Bulletin.all.count) search_result = search.collect{|t| t["id"]} - @bulletins = Bulletin.all.can_display.any_in(_id:search_result).page( params[:page_main]).per(15) + @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(15) else date_now = Time.now if !params[:category_id].blank? - @bulletins = Bulletin.all.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) + @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil elsif !params[:tag_id].blank? @tag = AnnouncementTag.find(params[:tag_id]) rescue nil @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag - @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) + @bulletins = @tag.bulletins.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) else - @bulletins = Bulletin.all.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) + @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) end end @@ -36,7 +36,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController if params[:preview] == "true" preview_content else - @bulletin = Bulletin.all.can_display.where(_id: params[:id]).first + @bulletin = Bulletin.all.available_for_lang(I18n.locale).can_display.where(_id: params[:id]).first unless @bulletin.disable? #impressionist(@bulletin) get_categorys diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb index 07870ae59..42339d634 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb @@ -11,14 +11,14 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController @title = params[:part_title] date_now = Time.now if !params[:category_id].blank? - @bulletins = Bulletin.all.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) + @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil elsif !params[:tag_id].blank? @tag = AnnouncementTag.find(params[:tag_id]) rescue nil @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag - @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) + @bulletins = @tag.bulletins.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) else - @bulletins = Bulletin.all.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) + @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) end get_categorys @@ -28,13 +28,13 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController def bulletins_and_web_links @tags = AnnouncementTag.any_in(key: ['students', 'alumni', 'employee', 'guest']).asc(:order) @selected_tag = AnnouncementTag.find(params[:id]) rescue @tags[0] - @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil + @bulletins = @selected_tag.get_visible_bulletins.available_for_lang(I18n.locale).can_display.page(params[:page]).per(5) rescue nil @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(5) rescue nil end def reload_bulletins @selected_tag = AnnouncementTag.find(params[:tag_id]) - @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil + @bulletins = @selected_tag.get_visible_bulletins.available_for_lang(I18n.locale).can_display.page(params[:page]).per(5) rescue nil end def reload_web_links diff --git a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb index 5de4a8260..a71b4965a 100644 --- a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb +++ b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb @@ -1,5 +1,10 @@ module Panel::Announcement::BackEnd::BulletinsHelper - + def show_form_status_field(bulletin) + by_bulletin = (!bulletin.is_expired? and bulletin.is_pending?) + by_user = ((bulletin.bulletin_category.authed_users('fact_check').include?(current_user) rescue nil) or is_manager? or is_admin?) + by_bulletin and by_user + end + def show_approval_link(bulletin) by_bulletin = (!bulletin.is_expired? and bulletin.is_pending?) by_user = ((bulletin.bulletin_category.authed_users('fact_check').include?(current_user) rescue nil) or is_manager? or is_admin?) @@ -37,4 +42,5 @@ module Panel::Announcement::BackEnd::BulletinsHelper end end + end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index 0241a478c..e6986466a 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -42,7 +42,8 @@ class Bulletin field :public, :type => Boolean, :default => true scope :can_display,where(is_checked: true) - + scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) } + mount_uploader :image, ImageUploader @@ -59,7 +60,7 @@ class Bulletin validates :title, :presence => true - before_save :check_deadline,:update_status + before_save :check_deadline,:update_status,:update_avliable_language after_save :save_bulletin_links after_save :save_bulletin_files @@ -75,14 +76,24 @@ class Bulletin # # [s_title,s_title_en,s_text_en,s_text_zh_tw].join(' ') # end + #alias_method + def s_title self.title_translations["zh_tw"] end + def s_title_was + self.title_was["zh_tw"] + end + def s_title_en self.title_translations["en"] end + def s_title_en_was + self.title_was["en"] + end + # def s_text_en # Nokogiri::HTML(self.text.en).text # end @@ -219,5 +230,14 @@ class Bulletin return true end + def update_avliable_language + VALID_LOCALES.each do |locale| + unless title[locale].blank? || subtitle[locale].blank? || text[locale].blank? + self["available_for_#{locale}".to_sym] = false + else + self["available_for_#{locale}".to_sym] = true + end + end + end end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index f58cfe2b5..47f24fe8c 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -4,42 +4,6 @@ <%= f.error_messages %>