From 93f103094ea777dcf17440b48635e5a4881c3022 Mon Sep 17 00:00:00 2001 From: nccu Date: Tue, 24 Feb 2015 14:13:42 +0800 Subject: [PATCH] fix --- app/controllers/news_controller.rb | 12 ++++++------ app/models/news_bulletin.rb | 1 + app/views/admin/news/_index.html.erb | 21 +++++++++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) 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 @@ <%= b.category.title rescue "" %> <% if b.expired? %> - <% if !b.title_translations["zh_tw"].blank? %> - <%= b.title_translations["zh_tw"] %> <%= t(:expired) %>
- <% end %> - <% if !b.title_translations["en"].blank? %> - <%= b.title_translations["en"] %> <%= t(:expired) %> + <% if b.rejected %> + <% if !b.title_translations["zh_tw"].blank? %> + <%= b.title_translations["zh_tw"] %><%= t(:expired)+','+t(:rejected) %> : <%= b.rejection_reason rescue "" %>
+ <% end %> + <% if !b.title_translations["en"].blank? %> + <%= b.title_translations["en"] %><%= t(:expired)+','+t(:rejected) %> : <%= b.rejection_reason rescue "" %> + <% end %> + <% else %> + <% if !b.title_translations["zh_tw"].blank? %> + <%= b.title_translations["zh_tw"] %> <%= t(:expired) %>
+ <% end %> + <% if !b.title_translations["en"].blank? %> + <%= b.title_translations["en"] %> <%= t(:expired) %> + <% end %> <% end %> <% elsif b.rejected %> <% url = page_for_bulletin(b) %> @@ -56,7 +65,7 @@ <% if can_edit_or_delete?(b) %>
  • <%= t(:edit) %>
  • <%= t(:delete_) %>
  • - <% if !b.approved && user_can_approve? %> + <% if !b.approved && user_can_approve? && !b.expired? %>
  • " data-id="<%= b.id.to_s %>"><%= t("news.approve") %>
  • <% end %> <% end %>