From bbbf13084e95a93c3ce83409b1176e719ae0e528 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 4 Mar 2016 16:05:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=90=9C=E7=B4=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E9=A1=B5=E9=9D=A2=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 84 +++++++++++++------ .../users/_import_resource_info.html.erb | 20 ++--- .../users/import_resources_search.js.erb | 25 ++++++ config/routes.rb | 1 + 4 files changed, 93 insertions(+), 37 deletions(-) create mode 100644 app/views/users/import_resources_search.js.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cddcd5f50..eb35d32d4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2358,27 +2358,55 @@ class UsersController < ApplicationController end end + def import_resources_search + search = "%#{params[:search].strip.downcase}%" + # 别人的资源库是没有权限去看的 + if User.current.id.to_i != params[:id].to_i + render_403 + return + end + user_course_ids = User.current.courses.map { |c| c.id} + user_project_ids = User.current.projects.map {|p| p.id} + # user_org_ids = User.current.organizations.map {|o| o.id} + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + user_course_ids = User.current.courses.map { |c| c.id} + user_project_ids = User.current.projects.map {|p| p.id} + # user_org_ids = User.current.organizations.map {|o| o.id} + @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','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 is_publish = 1 and container_id is not null)" + + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc") + elsif params[:type] == "6" # 公共资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) + end + @type = params[:type] + @limit = 10 + @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,10 + respond_to do |format| + format.js + format.html {render :layout => 'new_base'} + end + end + # 内容导入到对象中 def import_into_container - # attachments = Attachment.where("id in (#{params[:checkbox1].join(',')})") - # if params[:mul_type] == "Project" - # - # elsif params[:mul_type] == "Course" - # Attachment.create(:container_id => params[:mul_id], :container_type => "Course", :name => attachment.name) - # elsif params[:mul_type] == "SubfieldFile" - # end - + send_ids = params[:checkbox1] + # mul_id为当前课程id、项目id、组织id的多种形态 + mul_id = params[:mul_id] + if params[:mul_type] == "Course" + mul_container = Course.find(mul_id) + elsif params[:mul_type] == "Project" + mul_container = Project.find(mul_id) + elsif params[:mul_type] == "SubfieldFile" + mul_container = OrgSubfield.find(mul_id) + end unless params[:checkbox1].blank? - send_ids = params[:checkbox1] - # mul_id为当前课程id、项目id、组织id的多种形态 - mul_id = params[:mul_id] - if params[:mul_type] == "Course" - mul_container = Course.find(mul_id) - elsif params[:mul_type] == "Project" - mul_container = Project.find(mul_id) - elsif params[:mul_type] == "SubfieldFile" - mul_container = OrgSubfield.find(mul_id) - end send_ids.each do |send_id| ori = Attachment.find_by_id(send_id) # 如果该附件已经存课程中,则只更新附件创建时间 @@ -2408,11 +2436,11 @@ class UsersController < ApplicationController respond_to do |format| format.html { if params[:mul_type] == "Course" - redirect_to course_files_url(mul_container) + redirect_to course_files_url(mul_container) unless mul_container.nil? elsif params[:mul_type] == "Project" - redirect_to project_files_url(mul_container) + redirect_to project_files_url(mul_container) unless mul_container.nil? elsif params[:mul_type] == "SubfieldFile" - redirect_to org_subfield_files_url(mul_container) + redirect_to org_subfield_files_url(mul_container) unless mul_container.nil? end } end @@ -2421,12 +2449,13 @@ class UsersController < ApplicationController # 根据资源关键字进行搜索 def resource_search search = "%#{params[:search].strip.downcase}%" + user_course_ids = User.current.courses.map { |c| c.id} + user_project_ids = User.current.projects.map {|p| p.id} + # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部 if User.current.id.to_i == params[:id].to_i - user_course_ids = User.current.courses.map { |c| c.id} - user_project_ids = User.current.projects.map {|p| p.id} - # user_org_ids = User.current.organizations.map {|o| o.id} - @attachments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + + @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','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 is_publish = 1 and container_id is not null)" + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc") else @@ -2466,8 +2495,9 @@ class UsersController < ApplicationController end elsif params[:type] == "6" #全部资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = Attachment.where("((is_public =1 and is_publish = 1 and container_id is not null)" + - "or (author_id = #{params[:id]} and is_publish = 0)) and (filename like :p) ", :p => search).order("created_on desc") + @attachments = Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc") end @type = params[:type] @limit = 25 diff --git a/app/views/users/_import_resource_info.html.erb b/app/views/users/_import_resource_info.html.erb index f022e017e..7b613a962 100644 --- a/app/views/users/_import_resource_info.html.erb +++ b/app/views/users/_import_resource_info.html.erb @@ -1,8 +1,8 @@