don't dislay web links if no eng. lists in widget is now sorted.
This commit is contained in:
parent
625801c0e9
commit
acebec8904
|
@ -65,4 +65,22 @@ namespace :data_migration do
|
||||||
puts("#{'='*10}Finished#{'='*10}")
|
puts("#{'='*10}Finished#{'='*10}")
|
||||||
end
|
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
|
end
|
|
@ -28,18 +28,18 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController
|
||||||
def bulletins_and_web_links
|
def bulletins_and_web_links
|
||||||
@tags = AnnouncementTag.any_in(key: ['students', 'alumni', 'employee', 'guest']).asc(:order)
|
@tags = AnnouncementTag.any_in(key: ['students', 'alumni', 'employee', 'guest']).asc(:order)
|
||||||
@selected_tag = AnnouncementTag.find(params[:id]) rescue @tags[0]
|
@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
|
@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.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
|
end
|
||||||
|
|
||||||
def reload_bulletins
|
def reload_bulletins
|
||||||
@selected_tag = AnnouncementTag.find(params[:tag_id])
|
@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
|
end
|
||||||
|
|
||||||
def reload_web_links
|
def reload_web_links
|
||||||
@selected_tag = AnnouncementTag.find(params[:tag_id])
|
@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
|
end
|
||||||
|
|
||||||
def bulletins_side_bar
|
def bulletins_side_bar
|
||||||
|
|
|
@ -5,7 +5,7 @@ class AnnouncementTag < Tag
|
||||||
|
|
||||||
def get_visible_bulletins(sort = :title)
|
def get_visible_bulletins(sort = :title)
|
||||||
date_now = Time.now
|
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
|
end
|
||||||
|
|
||||||
def bulletins
|
def bulletins
|
||||||
|
|
|
@ -28,18 +28,18 @@ class Panel::News::Widget::NewsBulletinsController < OrbitWidgetController
|
||||||
def news_bulletins_and_web_links
|
def news_bulletins_and_web_links
|
||||||
@tags = NewsTag.all
|
@tags = NewsTag.all
|
||||||
@selected_tag = NewsTag.find(params[:id]) rescue @tags[0]
|
@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
|
@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.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
|
end
|
||||||
|
|
||||||
def reload_news_bulletins
|
def reload_news_bulletins
|
||||||
@selected_tag = NewsTag.find(params[:tag_id])
|
@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
|
end
|
||||||
|
|
||||||
def reload_web_links
|
def reload_web_links
|
||||||
@selected_tag = NewsTag.find(params[:tag_id])
|
@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
|
end
|
||||||
|
|
||||||
def news_bulletins_side_bar
|
def news_bulletins_side_bar
|
||||||
|
|
|
@ -10,14 +10,14 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if !params[:category_id].blank?
|
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
|
@current_category = WebLinkCategory.from_id(params[:category_id]) rescue nil
|
||||||
elsif !params[:tag_id].blank?
|
elsif !params[:tag_id].blank?
|
||||||
@tag = WebResourceTag.find(params[:tag_id]) rescue nil
|
@tag = WebResourceTag.find(params[:tag_id]) rescue nil
|
||||||
@tag = WebResourceTag.where(key: params[:tag_id])[0] unless @tag
|
@tag = WebResourceTag.where(key: params[:tag_id])[0] unless @tag
|
||||||
@web_links = @tag.web_links.desc( :is_top, :postdate).page( params[:page]).per(10)
|
@web_links = @tag.web_links.desc( :is_top, :postdate).page( params[:page]).per(10)
|
||||||
else
|
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
|
||||||
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_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
|
# get_categorys
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload_web_links
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ class WebLink
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
include Mongoid::MultiParameterAttributes
|
include Mongoid::MultiParameterAttributes
|
||||||
|
|
||||||
|
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||||
|
|
||||||
field :title, localize: true
|
field :title, localize: true
|
||||||
field :context, localize: true
|
field :context, localize: true
|
||||||
|
@ -21,6 +22,8 @@ class WebLink
|
||||||
|
|
||||||
belongs_to :web_link_category
|
belongs_to :web_link_category
|
||||||
|
|
||||||
|
before_save :update_avliable_language
|
||||||
|
|
||||||
validates :title, :at_least_one => true
|
validates :title, :at_least_one => true
|
||||||
|
|
||||||
def self.search( category_id = nil )
|
def self.search( category_id = nil )
|
||||||
|
@ -40,7 +43,7 @@ class WebLink
|
||||||
|
|
||||||
def self.widget_datas
|
def self.widget_datas
|
||||||
|
|
||||||
where( :is_hidden => false ).desc(:is_top, :title)
|
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -52,4 +55,14 @@ class WebLink
|
||||||
tags.order_by(I18n.locale, :asc)
|
tags.order_by(I18n.locale, :asc)
|
||||||
end
|
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
|
end
|
Reference in New Issue