diff --git a/app/controllers/admin/news_controller.rb b/app/controllers/admin/news_controller.rb index 1d40bb2..1d8de08 100644 --- a/app/controllers/admin/news_controller.rb +++ b/app/controllers/admin/news_controller.rb @@ -16,6 +16,19 @@ class Admin::NewsController < OrbitAdminController @filter_fields = filter_fields(@categories, @tags) @table_fields = [:status, :category, :title, :start_date, :end_date, :image, "news.unit", :view_count] + if !params[:sort].blank? + if params[:sort] == 'start_date' + sort = {:postdate=>params[:order]} + elsif params[:sort] == 'end_date' + sort = {:deadline=>params[:order]} + else + sort = {params[:sort].to_sym=>params[:order]} + end + else + sort = {:postdate=>"desc"} + end + + @news_bulletin = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil]) .order_by(sort) .with_categories(filters("category")) diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 79af157..aaf4a8e 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -5,12 +5,12 @@ class NewsController < ApplicationController news = nil if params[:keywords] - !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"} + !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_count = news.count keyword = "搜尋標題有關 ' " + params[:keywords] + " '" elsif params[:department] - !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"} + !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_count = news.count @@ -25,7 +25,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 = {:postdate=>"desc"} + !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_count = news.count @@ -37,7 +37,7 @@ class NewsController < ApplicationController keyword = "列出由:" + keywords + "發佈的資料" end elsif params["category"] - !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"} + !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_count = news.count @@ -50,7 +50,7 @@ class NewsController < ApplicationController keyword = "搜尋有關 ' " + keywords + " '" end end - !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"} + !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? page = Page.where(:module => "news").first rescue nil ma = ModuleApp.find_by_key("news") rescue nil diff --git a/app/views/admin/news/_index.html.erb b/app/views/admin/news/_index.html.erb index e2c39fb..ea66bfd 100644 --- a/app/views/admin/news/_index.html.erb +++ b/app/views/admin/news/_index.html.erb @@ -16,7 +16,7 @@