From 7223e6c91c64a5e226d77212282e5e62544425f7 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 1 Sep 2015 15:03:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E7=94=A8=E5=8F=91=E9=80=81=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=97=B6=E5=88=B7=E6=96=B0=E8=B5=84=E6=BA=90=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=92=8C=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 35 +++++++++++++++---- app/views/users/_resources_list.html.erb | 6 ++-- .../users/add_exist_file_to_course.js.erb | 5 +++ .../users/add_exist_file_to_project.js.erb | 5 +++ app/views/users/user_resource.html.erb | 5 +-- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a88068be7..696b9f7da 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -405,7 +405,7 @@ class UsersController < ApplicationController render_403 return end - if(params[:type].nil? || params[:type] == "1") #全部 + if(params[:type].blank? || params[:type] == "1") #全部 user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") @@ -436,7 +436,7 @@ class UsersController < ApplicationController #引入资源列表根据关键词过滤 def user_ref_resource_search search = params[:search].to_s.strip.downcase - if(params[:type].nil? || params[:type] == "1") #全部 + if(params[:type].blank? || params[:type] == "1") #全部 user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询 @attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ " or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))) and (filename like '%#{search}%') ").order("created_on desc") @@ -1067,7 +1067,7 @@ class UsersController < ApplicationController #@user.save_attachments(params[:attachments],User.current) # Container_type为Principal Attachment.attach_filesex(@user, params[:attachments], params[:attachment_type]) - if(params[:type].nil? || params[:type] == "1") #全部 + if(params[:type].blank?|| params[:type] == "1") #全部 if User.current.id.to_i == params[:id].to_i user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ @@ -1129,7 +1129,7 @@ class UsersController < ApplicationController end end - if(params[:type].nil? || params[:type] == "1") #全部 + if(params[:type].blank? || params[:type] == "1") #全部 if User.current.id.to_i == params[:id].to_i user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ @@ -1268,6 +1268,18 @@ class UsersController < ApplicationController else @flag = false end + user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") + @type = params[:type] + @limit = 25 + @user = User.current + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,25 respond_to do |format| format.js end @@ -1324,7 +1336,18 @@ class UsersController < ApplicationController else @flag=true end - + user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") + @type = params[:type] + @limit = 25 + @user = User.current + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,25 respond_to do |format| format.js end @@ -1539,7 +1562,7 @@ class UsersController < ApplicationController render_403 return end - if(params[:type].nil? || params[:type] == "1") #全部 + if(params[:type].blank? || params[:type] == "1") #全部 if User.current.id.to_i == params[:id].to_i user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index 387b38936..ab86fc21d 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -1,8 +1,8 @@ <% if attachments.nil? || attachments.empty? %> -

- <%= l(:label_no_data) %> -

+ + + <% else %> <% attachments.each do |attach| %>