From b50dac6a3621c5aec10c33e66c487f24da29a85c Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 29 Aug 2014 10:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A1=B9=E7=9B=AE=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=8E=92=E5=BA=8F=E6=97=A0=E6=95=88=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 39 ++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 031f78277..ef6e20644 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -45,11 +45,45 @@ class FilesController < ApplicationController 'filename' => "#{Attachment.table_name}.filename", 'size' => "#{Attachment.table_name}.filesize", 'downloads' => "#{Attachment.table_name}.downloads" + sort = "" if params[:project_id] @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 @@ -57,7 +91,6 @@ class FilesController < ApplicationController elsif params[:course_id] @isproject = false - sort = "" if params[:sort] params[:sort].split(",").each do |sort_type| order_by = sort_type.split(":")