修复项目资源排序无效的BUG
This commit is contained in:
parent
dcde828e64
commit
b50dac6a36
|
@ -45,11 +45,45 @@ class FilesController < ApplicationController
|
||||||
'filename' => "#{Attachment.table_name}.filename",
|
'filename' => "#{Attachment.table_name}.filename",
|
||||||
'size' => "#{Attachment.table_name}.filesize",
|
'size' => "#{Attachment.table_name}.filesize",
|
||||||
'downloads' => "#{Attachment.table_name}.downloads"
|
'downloads' => "#{Attachment.table_name}.downloads"
|
||||||
|
sort = ""
|
||||||
|
|
||||||
if params[:project_id]
|
if params[:project_id]
|
||||||
@isproject = true
|
@isproject = true
|
||||||
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
|
|
||||||
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
if params[:sort]
|
||||||
|
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
|
||||||
|
|
||||||
|
@containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)]
|
||||||
|
@containers += @project.versions.includes(:attachments).reorder(sort).all.sort
|
||||||
|
|
||||||
show_attachments @containers
|
show_attachments @containers
|
||||||
|
|
||||||
|
@ -57,7 +91,6 @@ class FilesController < ApplicationController
|
||||||
elsif params[:course_id]
|
elsif params[:course_id]
|
||||||
@isproject = false
|
@isproject = false
|
||||||
|
|
||||||
sort = ""
|
|
||||||
if params[:sort]
|
if params[:sort]
|
||||||
params[:sort].split(",").each do |sort_type|
|
params[:sort].split(",").each do |sort_type|
|
||||||
order_by = sort_type.split(":")
|
order_by = sort_type.split(":")
|
||||||
|
|
Loading…
Reference in New Issue