修改资源排序

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 case order_by[0]
@orderBy = params[:sort].split(",")[0] when "filename"
@orderType = "asc" 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
end end
@containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
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
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