From acebec8904478ea636ab14df379189769925ef45 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 1 Aug 2012 15:24:55 +0800 Subject: [PATCH] don't dislay web links if no eng. lists in widget is now sorted. --- lib/tasks/data_migration.rake | 18 ++++++++++++++++++ .../widget/bulletins_controller.rb | 8 ++++---- .../app/models/announcement_tag.rb | 2 +- .../news/widget/news_bulletins_controller.rb | 8 ++++---- .../widget/web_links_controller.rb | 8 ++++---- .../web_resource/app/models/web_link.rb | 17 +++++++++++++++-- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/lib/tasks/data_migration.rake b/lib/tasks/data_migration.rake index cba9a1c6f..54d8bd0f1 100644 --- a/lib/tasks/data_migration.rake +++ b/lib/tasks/data_migration.rake @@ -65,4 +65,22 @@ namespace :data_migration do puts("#{'='*10}Finished#{'='*10}") end + task :make_web_link_has_language_flag => :environment do + a=[] + i=0 + WebLink.all.each do |wl| + result = if (wl.save(:validate => false) rescue false ) + "OK" + else + a << wl.id + 'Failed' + end + i += 1 + puts((wl.title.to_s rescue '') + "----------#{result}") + end + p a + p i + puts("#{'='*10}Finished#{'='*10}") + end + end \ No newline at end of file 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 42339d634..152844fa2 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 @@ -28,18 +28,18 @@ 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.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 + @bulletins = @selected_tag.get_visible_bulletins(:postdate).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(:created_at).available_for_lang(I18n.locale).page(params[:page]).per(5) rescue nil end def reload_bulletins @selected_tag = AnnouncementTag.find(params[:tag_id]) - @bulletins = @selected_tag.get_visible_bulletins.available_for_lang(I18n.locale).can_display.page(params[:page]).per(5) rescue nil + @bulletins = @selected_tag.get_visible_bulletins(:postdate).available_for_lang(I18n.locale).can_display.page(params[:page]).per(5) rescue nil end def reload_web_links @selected_tag = AnnouncementTag.find(params[:tag_id]) - @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(5) rescue nil + @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links(:created_at).available_for_lang(I18n.locale).page(params[:page]).per(5) rescue nil end def bulletins_side_bar diff --git a/vendor/built_in_modules/announcement/app/models/announcement_tag.rb b/vendor/built_in_modules/announcement/app/models/announcement_tag.rb index 594c221d4..a23e74bf5 100644 --- a/vendor/built_in_modules/announcement/app/models/announcement_tag.rb +++ b/vendor/built_in_modules/announcement/app/models/announcement_tag.rb @@ -5,7 +5,7 @@ class AnnouncementTag < Tag def get_visible_bulletins(sort = :title) date_now = Time.now - self.bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort) + self.bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort) end def bulletins diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/widget/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/widget/news_bulletins_controller.rb index bb35dc85c..e4040ec07 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/widget/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/widget/news_bulletins_controller.rb @@ -28,18 +28,18 @@ class Panel::News::Widget::NewsBulletinsController < OrbitWidgetController def news_bulletins_and_web_links @tags = NewsTag.all @selected_tag = NewsTag.find(params[:id]) rescue @tags[0] - @news_bulletins = @selected_tag.get_visible_news_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 + @news_bulletins = @selected_tag.get_visible_news_bulletins(:postdate).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(:created_at).page(params[:page]).per(5) rescue nil end def reload_news_bulletins @selected_tag = NewsTag.find(params[:tag_id]) - @news_bulletins = @selected_tag.get_visible_news_bulletins.available_for_lang(I18n.locale).can_display.page(params[:page]).per(5) rescue nil + @news_bulletins = @selected_tag.get_visible_news_bulletins(:postdate).available_for_lang(I18n.locale).can_display.page(params[:page]).per(5) rescue nil end def reload_web_links @selected_tag = NewsTag.find(params[:tag_id]) - @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(5) rescue nil + @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links(:created_at).page(params[:page]).per(5) rescue nil end def news_bulletins_side_bar diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb index a9fe23d8c..0ba014067 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb @@ -10,14 +10,14 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController def index if !params[:category_id].blank? - @web_links = WebLink.where(:web_link_category => params[:category_id]).desc( :is_top, :postdate).page( params[:page]).per(10) + @web_links = WebLink.where(:web_link_category => params[:category_id]).available_for_lang(I18n.locale).desc( :is_top, :postdate).page( params[:page]).per(10) @current_category = WebLinkCategory.from_id(params[:category_id]) rescue nil elsif !params[:tag_id].blank? @tag = WebResourceTag.find(params[:tag_id]) rescue nil @tag = WebResourceTag.where(key: params[:tag_id])[0] unless @tag @web_links = @tag.web_links.desc( :is_top, :postdate).page( params[:page]).per(10) else - @web_links = WebLink.all.desc( :is_top, :postdate).page( params[:page]).per(10) + @web_links = WebLink.available_for_lang(I18n.locale).desc( :is_top, :postdate).page( params[:page]).per(10) end end @@ -30,7 +30,7 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController # @web_link = WebLink.where( :is_hidden => false ).desc(:is_top, :title).first - @web_links = WebLink.widget_datas.page(params[:page]).per(5) + @web_links = WebLink.widget_datas.available_for_lang(I18n.locale).page(params[:page]).per(5) # get_categorys @@ -40,7 +40,7 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController end def reload_web_links - @web_links = WebLink.widget_datas.page(params[:page]).per(5) + @web_links = WebLink.widget_datas.available_for_lang(I18n.locale).page(params[:page]).per(5) end diff --git a/vendor/built_in_modules/web_resource/app/models/web_link.rb b/vendor/built_in_modules/web_resource/app/models/web_link.rb index 8e0216f23..ada9acfe1 100644 --- a/vendor/built_in_modules/web_resource/app/models/web_link.rb +++ b/vendor/built_in_modules/web_resource/app/models/web_link.rb @@ -5,7 +5,8 @@ class WebLink include Mongoid::Timestamps include Mongoid::MultiParameterAttributes - + scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) } + field :title, localize: true field :context, localize: true @@ -21,6 +22,8 @@ class WebLink belongs_to :web_link_category + before_save :update_avliable_language + validates :title, :at_least_one => true def self.search( category_id = nil ) @@ -40,7 +43,7 @@ class WebLink def self.widget_datas - where( :is_hidden => false ).desc(:is_top, :title) + where( :is_hidden => false ).desc(:is_top, :created_at) end @@ -52,4 +55,14 @@ class WebLink tags.order_by(I18n.locale, :asc) end + def update_avliable_language + VALID_LOCALES.each do |locale| + if (title_translations[locale].blank? rescue true) + 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