Do not show news/anc if no context.

This commit is contained in:
Matthew K. Fu JuYuan 2012-07-31 18:22:40 +08:00
parent 7e3b59c09a
commit b989f458d3
11 changed files with 102 additions and 72 deletions

View File

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

View File

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

View File

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

View File

@ -1,4 +1,9 @@
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?)
@ -37,4 +42,5 @@ module Panel::Announcement::BackEnd::BulletinsHelper
end
end
end

View File

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

View File

@ -4,42 +4,6 @@
<%= f.error_messages %>
<div id="sub-wiget">
<div id="widget-picture" class="widget-box">
<div class="widget-action clear">
<a class="action"><i title="Upload pictures" class="icon-exclamation-sign icon-white tip"></i></a>
</div>
<h3 class="widget-title"><i class="icons-picture icons-white"></i>Picture</h3>
<div class="widget-content clear">
<div class="control-group">
<!-- <img class="pull-left upload-picture" src="/assets/default-img.png" /> -->
<div class="upload-picture">
<!--請程式務必將圖片尺寸加入到行內裡-->
<% if @bulletin.image %>
<%= image_tag @bulletin.image rescue ''%>
<% else %>
<img class="pull-left upload-picture" src="/assets/default-img.png" />
<% end %>
</div>
<div class="controls file-upload input-prepend">
<label class="control-label add-on btn" for="input-upload">
<%= t(:browse) %>
<%= f.file_field :image, :id => "input-upload", :class => 'upload', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %>
</label>
<span id='fu' class="file-name"></span>
<br>
<input name='fu' class="input-medium" type="text">
<br>
<% if @bulletin.image.file %>
<%= f.check_box :remove_image %>
<%= t('announcement.刪除已上傳檔案') %>
<% end %>
</div>
</div>
</div>
</div>
<div id="widget-date" class="widget-box widget-size-300">
<div class="widget-action clear">
@ -62,6 +26,7 @@
</div>
</div>
<% if show_form_status_field(@bulletin)%>
<div id="widget-status" class="widget-box widget-size-300">
<div class="widget-action clear">
<a class="action"><i title="Setting the announcement state" class="icon-exclamation-sign icon-white tip"></i></a>
@ -84,7 +49,7 @@
</div>
</div>
</div>
<% end %>
<div id="widget-tags" class="widget-box widget-size-300">
<div class="widget-action clear">
<a class="action"><i title="Setting" class="icon-cog icon-white tip"></i></a>

View File

@ -14,7 +14,7 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
search_cond.merge!({:news_bulletin_category_id => "#{params[:category_id]}" }) if !params[:category_id].blank?
search = Redis::Search.query("NewsBulletin", params[:search_query], :conditions =>search_cond,:limit=>NewsBulletin.all.count)
search_result = search.collect{|t| t["id"]}
@news_bulletins = NewsBulletin.all.can_display.any_in(_id:search_result).page( params[:page_main]).per(10)
@news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(10)
else
date_now = Time.now
if !params[:tag_id].blank?
@ -24,11 +24,11 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
end
if !params[:category_id].blank?
@news_bulletins = NewsBulletin.all.can_display.where(:news_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(10)
@news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.where(:news_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(10)
elsif !params[:tag_id].blank?
@news_bulletins = tmp.news_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(10) rescue nil
@news_bulletins = tmp.news_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(10) rescue nil
else
@news_bulletins = NewsBulletin.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(10)
@news_bulletins = NewsBulletin.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(10)
end
end
get_categorys
@ -41,7 +41,7 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
if params[:preview] == "true"
preview_content
else
@news_bulletin = NewsBulletin.all.can_display.where(_id: params[:id]).first
@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

View File

@ -13,14 +13,14 @@ class Panel::News::Widget::NewsBulletinsController < OrbitWidgetController
@title = params[:part_title]
date_now = Time.now
if !params[:category_id].blank?
@news_bulletins = NewsBulletin.all.can_display.where(:news_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(5)
@news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.where(:news_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(5)
@current_category = NewsBulletinCategory.from_id(params[:category_id]) rescue nil
elsif !params[:tag_id].blank?
@tag = NewsTag.find(params[:tag_id]) rescue nil
@tag = NewsTag.where(key: params[:tag_id])[0] unless @tag
@news_bulletins = @tag.news_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(5) rescue nil
@news_bulletins = @tag.news_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(5) rescue nil
else
@news_bulletins = NewsBulletin.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(5)
@news_bulletins = NewsBulletin.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(5)
end
end
@ -28,13 +28,13 @@ 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.can_display.page(params[:page]).per(5) rescue nil
@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
end
def reload_news_bulletins
@selected_tag = NewsTag.find(params[:tag_id])
@news_bulletins = @selected_tag.get_visible_news_bulletins.can_display.page(params[:page]).per(5) rescue nil
@news_bulletins = @selected_tag.get_visible_news_bulletins.available_for_lang(I18n.locale).can_display.page(params[:page]).per(5) rescue nil
end
def reload_web_links
@ -53,11 +53,11 @@ class Panel::News::Widget::NewsBulletinsController < OrbitWidgetController
def home_banner
if !params[:category_id].blank?
@news_bulletins = NewsBulletin.all.can_display.where(:news_bulletin_category_id => params[:category_id]).widget_datas.limit(9)
@news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.where(:news_bulletin_category_id => params[:category_id]).widget_datas.limit(9)
elsif !params[:tag_id].blank?
@news_bulletins = NewsTag.find(params[:tag_id]).news_bulletins.can_display.widget_datas.limit(9) rescue nil
@news_bulletins = NewsTag.find(params[:tag_id]).news_bulletins.available_for_lang(I18n.locale).can_display.widget_datas.limit(9) rescue nil
else
@news_bulletins = NewsBulletin.all.can_display.widget_datas.limit(9)
@news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.widget_datas.limit(9)
end
get_categorys

View File

@ -1,4 +1,9 @@
module Panel::News::BackEnd::NewsBulletinsHelper
def news_show_form_status_field(news_bulletin)
by_news_bulletin = (!news_bulletin.is_expired? and news_bulletin.is_pending?)
by_user = (news_bulletin.news_bulletin_category.authed_users('fact_check').include?(current_user) or is_manager? or is_admin?)
by_news_bulletin and by_user
end
def news_show_approval_link(news_bulletin)
by_news_bulletin = (!news_bulletin.is_expired? and news_bulletin.is_pending?)

View File

@ -44,6 +44,7 @@ class NewsBulletin
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
@ -60,7 +61,7 @@ class NewsBulletin
validates_presence_of :title
before_save :update_status
before_save :update_status,:update_avliable_language
after_save :save_news_bulletin_links
after_save :save_news_bulletin_files
@ -100,13 +101,21 @@ class NewsBulletin
# # [s_title,s_title_en,s_text_en,s_text_zh_tw].join(' ')
# end
def s_title
self.title_translations["zh_tw"]
def s_title
self.title_translations["zh_tw"]
end
def s_title_was
self.title_was["zh_tw"]
end
def s_title_en
def s_title_en
self.title_translations["en"]
end
end
def s_title_en_was
self.title_was["en"]
end
# def s_text_en
# Nokogiri::HTML(self.text.en).text
@ -194,6 +203,15 @@ class NewsBulletin
end
protected
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
def update_status
if !self.is_pending

View File

@ -62,6 +62,7 @@
</div>
</div>
<% if news_show_form_status_field( @news_bulletin)%>
<div id="widget-status" class="widget-box widget-size-300">
<div class="widget-action clear">
<a class="action"><i title="Setting the news state" class="icon-exclamation-sign icon-white tip"></i></a>
@ -84,7 +85,7 @@
</div>
</div>
</div>
<% end %>
<div id="widget-tags" class="widget-box widget-size-300">
<div class="widget-action clear">
<a class="action"><i title="Setting" class="icon-cog icon-white tip"></i></a>