From 45288d8bfba82d2a413b8e398af99643d6cbd8ef Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 14 May 2014 10:59:36 +0800 Subject: [PATCH] moved sort and filters to OrbitAdminController --- app/controllers/orbit_admin_controller.rb | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/app/controllers/orbit_admin_controller.rb b/app/controllers/orbit_admin_controller.rb index c542d98..13317b4 100644 --- a/app/controllers/orbit_admin_controller.rb +++ b/app/controllers/orbit_admin_controller.rb @@ -6,4 +6,48 @@ class OrbitAdminController < ApplicationController before_action :authenticate_user 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