修改资源排序

This commit is contained in:
sw 2014-08-27 17:53:57 +08:00
parent 97f8aedd13
commit a77b07a99b
1 changed files with 31 additions and 22 deletions

View File

@ -57,36 +57,45 @@ class FilesController < ApplicationController
elsif params[:course_id]
@isproject = false
sort = ""
if params[:sort]
if params[:sort].include?":"
@orderBy = params[:sort].split(":")[0]
@orderType = params[:sort].split(":")[1].split(",")[0]
else
@orderBy = params[:sort].split(",")[0]
@orderType = "asc"
params[:sort].split(",").each do |sort_type|
order_by = sort_type.split(":")
case order_by[0]
when "filename"
attribute = "filename"
when "size"
attribute = "filesize"
when "attach_type"
attribute = "attachtype"
when "content_type"
attribute = "created_on"
when "field_file_dense"
attribute = "is_public"
when "downloads"
attribute = "downloads"
when "created_on"
attribute = "created_on"
end
if order_by.count == 1
sort += "#{Attachment.table_name}.#{attribute} desc "
elsif order_by.count == 2
sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} "
end
if sort_type != params[:sort].split(",").last
sort += ","
end
end
end
if @orderBy=="size"
@orderBy="filesize"
elsif @orderBy=="field_file_dense"
@orderBy="is_public"
elsif @orderBy=="attach_type"
@orderBy="attachtype"
elsif @orderBy=="content_type"
@orderBy="attachtype"
end
if @orderBy
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.#{@orderBy} #{@orderType}").find(@course.id)]
else
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on desc").find(@course.id)]
end
@containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
show_attachments @containers
render :layout => 'base_courses'
end
end
def new