don't dislay web links if no eng. lists in widget is now sorted.

This commit is contained in:
Matthew K. Fu JuYuan 2012-08-01 15:24:55 +08:00
parent 625801c0e9
commit acebec8904
6 changed files with 46 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -5,6 +5,7 @@ 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