diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 120dffb..2f84d33 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -6,13 +6,13 @@ class NewsController < ApplicationController if params[:keywords] !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} - news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil? + news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil? news_count = ",共有" + news.count.to_s + "筆資料" keyword = "搜尋標題有關 ' " + params[:keywords] + " '" elsif params[:department] !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} dept = Department.find_by(:uid => params["department"].split("-").last) rescue nil - news = NewsBulletin.where(:title.ne => "" ,:department => dept).is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil? + news = NewsBulletin.where(:title.ne => "" ,:department => dept).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil? news_count = ",共有" + news.count.to_s + "筆資料" keywords = params[:department].split("-") @@ -26,7 +26,7 @@ class NewsController < ApplicationController elsif params[:unit] unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} - news = NewsBulletin.where(:title.ne => "" ,:unit => unit).is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil? + news = NewsBulletin.where(:title.ne => "" ,:unit => unit).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil? news_count = ",共有" + news.count.to_s + "筆資料" keywords = params[:unit].split("-") @@ -39,7 +39,7 @@ class NewsController < ApplicationController elsif params["category"] !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} category = Category.find_by(:uid => params["category"].split("-").last) rescue nil - news = NewsBulletin.all.where(:title.ne => "").is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil? + news = NewsBulletin.all.where(:title.ne => "").can_display_postdate.is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil? news_count = ",共有" + news.count.to_s + "筆資料" keywords = params[:category].split("-") @@ -51,7 +51,7 @@ class NewsController < ApplicationController end end !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} - news = NewsBulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(sort).filter_by_categories.filter_by_tags(OrbitHelper.params['tags']) if news.nil? + news = NewsBulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).can_display_postdate.is_approved.order_by(sort).filter_by_categories.filter_by_tags(OrbitHelper.params['tags']) if news.nil? page = Page.where(:module => "news").first rescue nil ma = ModuleApp.find_by_key("news") rescue nil categories = ma.categories.enabled.collect do |cat| @@ -60,13 +60,13 @@ class NewsController < ApplicationController "category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}" } end + anns = news.collect do |a| if a.image_description.nil? image_description = "裝飾性圖片" else image_description = a.image_description end - statuses = a.statuses_with_classname.collect do |status| { "status" => status["name"], diff --git a/app/models/news_bulletin.rb b/app/models/news_bulletin.rb index 2d884b2..052059e 100644 --- a/app/models/news_bulletin.rb +++ b/app/models/news_bulletin.rb @@ -46,6 +46,7 @@ class NewsBulletin before_destroy :destroy_email scope :can_display, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])} + scope :can_display_postdate, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])} scope :is_approved, ->{where(:approved => true)} def update_user diff --git a/app/views/admin/news/_index.html.erb b/app/views/admin/news/_index.html.erb index eaf4533..d79e57e 100644 --- a/app/views/admin/news/_index.html.erb +++ b/app/views/admin/news/_index.html.erb @@ -19,11 +19,20 @@