fix order and top

This commit is contained in:
nccu 2015-01-09 14:29:00 +08:00
parent d95d58ea72
commit 9033b2dfa3
3 changed files with 19 additions and 6 deletions

View File

@ -16,6 +16,19 @@ class Admin::NewsController < OrbitAdminController
@filter_fields = filter_fields(@categories, @tags) @filter_fields = filter_fields(@categories, @tags)
@table_fields = [:status, :category, :title, :start_date, :end_date, :image, "news.unit", :view_count] @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]) @news_bulletin = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil])
.order_by(sort) .order_by(sort)
.with_categories(filters("category")) .with_categories(filters("category"))

View File

@ -5,12 +5,12 @@ class NewsController < ApplicationController
news = nil news = nil
if params[:keywords] 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 = 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 news_count = news.count
keyword = "搜尋標題有關 ' " + params[:keywords] + " '" keyword = "搜尋標題有關 ' " + params[:keywords] + " '"
elsif params[:department] 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 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).is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil?
news_count = news.count news_count = news.count
@ -25,7 +25,7 @@ class NewsController < ApplicationController
elsif params[:unit] elsif params[:unit]
unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil 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 = NewsBulletin.where(:title.ne => "" ,:unit => unit).is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil?
news_count = news.count news_count = news.count
@ -37,7 +37,7 @@ class NewsController < ApplicationController
keyword = "列出由:" + keywords + "發佈的資料" keyword = "列出由:" + keywords + "發佈的資料"
end end
elsif params["category"] 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 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 => "").is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
news_count = news.count news_count = news.count
@ -50,7 +50,7 @@ class NewsController < ApplicationController
keyword = "搜尋有關 ' " + keywords + " '" keyword = "搜尋有關 ' " + keywords + " '"
end end
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? 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 page = Page.where(:module => "news").first rescue nil
ma = ModuleApp.find_by_key("news") rescue nil ma = ModuleApp.find_by_key("news") rescue nil

View File

@ -16,7 +16,7 @@
<td> <td>
<%= b.status_for_table %> <%= b.status_for_table %>
</td> </td>
<td><%= b.category.title %></td> <td><%= b.category.title rescue "" %></td>
<td> <td>
<% if b.expired? %> <% if b.expired? %>
<%= b.title %> <span class='label'><%= t(:expired) %></span> <%= b.title %> <span class='label'><%= t(:expired) %></span>