修改资源排序

competition
sw 11 years ago
parent 97f8aedd13
commit a77b07a99b

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

Loading…
Cancel
Save