moved sort and filters to OrbitAdminController

This commit is contained in:
manson 2014-05-14 10:59:36 +08:00
parent 64197e29da
commit 45288d8bfb
1 changed files with 44 additions and 0 deletions

View File

@ -6,4 +6,48 @@ class OrbitAdminController < ApplicationController
before_action :authenticate_user before_action :authenticate_user
layout "back_end" layout "back_end"
def sort
unless params[:sort].blank?
case params[:sort]
when "status"
@sort = [[:is_top, params[:order]],
[:is_hot, params[:order]],
[:is_hidden,params[:order]]]
when "category"
@sort = {:category_id=>params[:order]}
when "title"
@sort = {:title=>params[:order]}
when "start_date"
@sort = {:postdate=>params[:order]}
when "end_date"
@sort = {:deadline=>params[:order]}
when "last_modified"
@sort = {:update_user_id=>params[:order]}
end
else
@sort = {:created_at=>'desc'}
end
@sort
end
def filter_fields(categories, tags)
{
:status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}],
:category=>categories.map{|c| {:title=>c.title, :id=>c.id}},
:tags=>tags.map{|tag| {:title=>tag.name, :id=>tag.id}}
}
end
def filters(type)
case type
when "status"
params[:filters][:status].blank? ? [] : params[:filters][:status] rescue []
when "category"
params[:filters][:category].blank? ? [] : params[:filters][:category] rescue []
when "tag"
params[:filters][:tags].blank? ? [] : params[:filters][:tags] rescue []
end
end
end end