From b3fea3e229192b340fbcc4865e5c0bc5b8cb84c0 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 2 Mar 2016 11:30:19 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 179 +++++++++---------- app/views/users/_user_resource_info.html.erb | 57 ++++++ app/views/users/user_resource.html.erb | 136 +++++--------- 3 files changed, 186 insertions(+), 186 deletions(-) create mode 100644 app/views/users/_user_resource_info.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ddb650193..803dd49d3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -684,21 +684,23 @@ class UsersController < ApplicationController 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} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} 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(',')}))").order("created_on desc") - elsif params[:type] == "2" #课程资源 - user_course_ids = User.current.courses.map { |c| c.id} - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) ").order("created_on desc") - elsif params[:type] == "3" #项目资源 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project'").order("created_on desc") + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + elsif params[:type] == "2" # 课程资源 + @attachments = get_course_resources(params[:id], user_course_ids) + elsif params[:type] == "3" # 项目资源 + @attachments = get_project_resources(params[:id], user_project_ids) elsif params[:type] == "4" #附件 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") + @attachments = get_attch_resources params[:id] elsif params[:type] == "5" #用户资源 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal'").order("created_on desc") - elsif params[:type] == "6" #公共资源 - Attachment.where("(is_public =1 and is_publish = 1 and container_id is not null)" + "or (author_id = #{params[:id]} and is_publish = 0)").order("created_on desc") + @attachments = get_principal_resources params[:id] + elsif params[:type] == "6" # 公共资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) end @type = params[:type] @limit = 7 @@ -1407,50 +1409,27 @@ class UsersController < ApplicationController # 上传用户资源 def user_resource_create + 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} @user = User.find(params[:id]) #@user.save_attachments(params[:attachments],User.current) # Container_type为Principal Attachment.attach_filesex(@user, params[:attachments], params[:attachment_type]) - 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','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(',')}))").order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 " + - "and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " + - "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") - end - elsif params[:type] == "2" #课程资源 - 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 = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) ").order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and container_type = 'Course')"+ - "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") - end - elsif params[:type] == "3" #项目资源 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project'").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' ").order("created_on desc") - end + if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + elsif params[:type] == "2" # 课程资源 + @attachments = get_course_resources(params[:id], user_course_ids) + elsif params[:type] == "3" # 项目资源 + @attachments = get_project_resources(params[:id], user_project_ids) elsif params[:type] == "4" #附件 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") - end - elsif params[:type] == "5" #附件 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type ='Principal'").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type ='Principal'").order("created_on desc") - end + @attachments = get_attch_resources params[:id] + elsif params[:type] == "5" #用户资源 + @attachments = get_principal_resources params[:id] 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)").order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) end @type = params[:type] || 1 @limit = 25 @@ -1474,45 +1453,23 @@ class UsersController < ApplicationController Attachment.where("author_id = #{User.current.id}").delete(id) end 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].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} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} 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(',')}))").order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 " + - "and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " + - "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") - end - elsif params[:type] == "2" #课程资源 - 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 = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) ").order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and container_type = 'Course')"+ - "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") - end - elsif params[:type] == "3" #项目资源 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project'").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' ").order("created_on desc") - end + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + elsif params[:type] == "2" # 课程资源 + @attachments = get_course_resources(params[:id], user_course_ids) + elsif params[:type] == "3" # 项目资源 + @attachments = get_project_resources(params[:id], user_project_ids) elsif params[:type] == "4" #附件 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") - end + @attachments = get_attch_resources params[:id] elsif params[:type] == "5" #用户资源 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type ='Principal'").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type ='Principal'").order("created_on desc") - end + @attachments = get_principal_resources params[:id] + elsif params[:type] == "6" # 公共资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) end @type = params[:type] @limit = 25 @@ -2175,6 +2132,40 @@ class UsersController < ApplicationController end end + # 获取公共资源 + def get_public_resources user_course_ids, user_project_ids + 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)" ).order("created_on desc") + end + + # 获取我的资源 + def get_my_resources author_id, user_course_ids, user_project_ids + 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')) "+ + "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)" ).order("created_on desc") + end + + # 获取我的课程资源 + def get_course_resources author_id, user_course_ids + attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + end + + # 获取我的项目资源 + def get_project_resources author_id, user_project_ids + attchments = Attachment.where("author_id = #{author_id} and container_type = 'Project'").order("created_on desc") + end + + # 获取我上传的附件 + def get_attch_resources author_id + attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") + end + + # 获取我的用户类型资源 + def get_principal_resources author_id + attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc") + end + # 资源库 分为全部 课程资源 项目资源 附件 def user_resource # 别人的资源库是没有权限去看的 @@ -2184,23 +2175,21 @@ class UsersController < ApplicationController 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.projects.map {|p| p.id} + # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_publish = 1 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)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1)" ).order("created_on desc") + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) elsif params[:type] == "2" # 课程资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + @attachments = get_course_resources(params[:id], user_course_ids) elsif params[:type] == "3" # 项目资源 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project'").order("created_on desc") + @attachments = get_project_resources(params[:id], user_project_ids) elsif params[:type] == "4" #附件 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") + @attachments = get_attch_resources params[:id] elsif params[:type] == "5" #用户资源 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal'").order("created_on desc") + @attachments = get_principal_resources params[:id] elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = Attachment.where(" ").order("created_on desc") + @attachments = get_public_resources(user_course_ids, user_project_ids) end @type = params[:type] @limit = 25 diff --git a/app/views/users/_user_resource_info.html.erb b/app/views/users/_user_resource_info.html.erb new file mode 100644 index 000000000..9c682f9c8 --- /dev/null +++ b/app/views/users/_user_resource_info.html.erb @@ -0,0 +1,57 @@ +
+ +
+ <%= render :partial => 'resource_search_form',:locals => {:user => @user, :type => @type} %> +
+
为您找到<%= @atta_count %>个资源
+
+
+ +
+
+
+ <%= render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments} %> +
+
+
+
+ +
+ 全选 + 删除 +
+
选择 0 个资源
+
+ 发送 +
+
+
+
+
+
+ +
+ +
+ + + + \ No newline at end of file diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 9175bc1c4..ec1a57852 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -11,12 +11,12 @@ function remote_get_resources(user_id,type){ } - $(document).ready(function(){ - $(".resource-switch").click(function(){ - $(".resource-switch").children().removeClass("resource-tab-active"); - $(this).children().addClass("resource-tab-active"); - }); - }); +// $(document).ready(function(){ + // $(".resource-switch").click(function(){ + // $(".resource-switch").children().removeClass("resource-tab-active"); + // $(this).children().addClass("resource-tab-active"); + // }); + // }); function remote_search(){ $("#resource_search_form").submit(); } @@ -31,6 +31,14 @@ $('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); } + function show_public_resource(){ + $("#resource_remote").html('<%= escape_javascript( render :partial => 'user_resource_info' ,:locals => { :tpye => 6}) %>'); + } + + function show_public_resource(){ + $("#resource_remote").html('<%= escape_javascript( render :partial => 'user_resource_info' ,:locals => { :tpye => 1}) %>'); + } + function closeModal() { hideModal($(".uploadBoxContainer")); @@ -62,98 +70,44 @@ } -
-
-
-
    -
  • 公共资源
  • -
  • <%=link_to "我的资源", {:controller => 'users', :action => 'user_resource', :id => User.current.id, :type => 1, :remote => true}, :class => "resource-tab" %>
  • -
  •  
  • -
  • -
      -
    • -
        -
      • - <%= link_to '全部' ,user_resource_user_path(:id => @user.id, :type => 1), :remote => true, :method => 'get', :class => 'resourcesTypeAll resourcesGrey' %> -
      • -
      • - <%= link_to '课程资源' ,user_resource_user_path(:id => @user.id, :type => 2), :remote => true, :method => 'get', :class=> 'homepagePostTypeAssignment postTypeGrey' %> -
      • -
      • - <%= link_to '项目资源' ,user_resource_user_path(:id => @user.id, :type => 3), :remote => true, :method => 'get', :class => 'homepagePostTypeQuiz postTypeGrey' %> -
      • -
      • - <%= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5),:remote=>true,:method => 'get', :class=>'resourcesTypeUser resourcesGrey' %> -
      • -
      • - <%= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4),:remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %> -
      • -
      +
      +
        +
      • 公共资源
      • +
      • 我的资源
      • +
      •  
      • +
      • +
          +
        • +
            +
          • + <%= link_to '全部' ,user_resource_user_path(:id => @user.id, :type => 1), :remote => true, :method => 'get', :class => 'resourcesTypeAll resourcesGrey' %> +
          • +
          • + <%= link_to '课程资源' ,user_resource_user_path(:id => @user.id, :type => 2), :remote => true, :method => 'get', :class=> 'homepagePostTypeAssignment postTypeGrey' %> +
          • +
          • + <%= link_to '项目资源' ,user_resource_user_path(:id => @user.id, :type => 3), :remote => true, :method => 'get', :class => 'homepagePostTypeQuiz postTypeGrey' %> +
          • +
          • + <%= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5),:remote=>true,:method => 'get', :class=>'resourcesTypeUser resourcesGrey' %> +
          • +
          • + <%= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4),:remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %>
        • -
        -
        -
        - -
        - <%= render :partial => 'resource_search_form',:locals => {:user => @user, :type => @type} %> -
        -
        为您找到<%= @atta_count %>个资源
        -
        -
        -
          -
        • -
        • 资源名称
        • -
        • 上传时间
        • -
        • 上传者
        • -
        • 类别
        • -
        • 大小
        • -
        • 资源来源
        • -
        -
        -
        -
        - <%= render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments} %> -
        -
        -
        -
        - -
        - 全选 - 删除 -
        -
        选择 0 个资源
        -
        - 发送 -
        -
        -
        -
        -
        -
        -
          - <%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %> -
        -
        -
      +
    • +
      +
    +
    +
    + <%= render :partial => 'user_resource_info' %>
- - - - + + +
选用资源库中的资源
+
+ 公共资源 + 我的资源 + <%= form_tag( url_for(:controller => 'users', :action => 'resource_search', :id => User.current.id), + :remote => true , :method => 'get', :id => 'resource_search_form') do %> + + <%= hidden_field_tag(:type,type.nil? ? 1 : type) %> + <% end %> +
-
-
- <%= form_tag( url_for(:controller => 'users', :action => 'resource_search', :id => User.current.id), - :remote => true , :method => 'get', :class => 'resourcesSearchloadBox mt10', :id => 'resource_search_form') do %> - - <%= hidden_field_tag(:type,type.nil? ? 1 : type) %> - <%= submit_tag '', :class => 'homepageSearchIcon', :onfocus => 'this.blur();', :style => 'border-style:none' %> - - <% end %> -
+
+
    + +
  • 类别
  • +
  • 大小
  • +
  • 上传者
  • +
  • 上传时间
  • +
+ <% @attachments.each do |attach| %> +
    + +
  • <%= get_resource_type(attach.container_type)%>
  • +
  • <%= number_to_human_size(attach.filesize) %>
  • +
  • <%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %>
  • +
  • <%= format_date(attach.created_on) %>
  • +
+ <% end %>
-
-
    -
  • -
  • 资源名称
  • -
  • 上传时间
  • -
  • 上传者
  • -
  • 类别
  • -
  • 大小
  • -
  • 资源来源
  • -
-
-
-
- <% @attachments.each do |attach| %> -
    -
  • - - -
  • - -
  • <%= format_date(attach.created_on) %>
  • -
  • <%= attach.id %>
  • - -
  • <%= attach.author_id %>
  • -
  • <%= get_resource_type(attach.container_type)%>
  • -
  • <%= attach.id %>
  • -
  • <%= number_to_human_size(attach.filesize) %>
  • -
  • <%= attach.id %>
  • - -
  • <%= attach.id %>
  • -
-
- <% end %> -
-
-
-
- -
- 全选 - 删除 -
-
选择 0 个资源
-
- 发送 -
-
-
-
-
-
+ + + +
    <%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>
- -
- - - - -
-
- - - -
-
选用资源库中的资源
-
- 公共资源 - 我的资源 - <%= form_tag( url_for(:controller => 'users', :action => 'resource_search', :id => User.current.id), - :remote => true , :method => 'get', :class => 'resourcesSearchloadBox mt10', :id => 'resource_search_form') do %> - - <%= hidden_field_tag(:type,type.nil? ? 1 : type) %> - <%= submit_tag '', :class => 'homepageSearchIcon', :onfocus => 'this.blur();', :style => 'border-style:none' %> - - <% end %> -
-
- - - - -
    - -
  • 类别
  • -
  • 大小
  • -
  • 上传者
  • -
  • 上传时间
  • -
- - <% @attachments.each do |attach| %> -
    -
  • - - -
  • - - - - - -
  • <%= get_resource_type(attach.container_type)%>
  • - -
  • <%= number_to_human_size(attach.filesize) %>
  • - - -
  • <%= format_date(attach.created_on) %>
  • -
-
- <% end %> -
    - -
  • 课程资源
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
    - -
  • 项目资源
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
    - -
  • 附件
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
    - -
  • 课程资源
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
    - -
  • 课程资源
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
    - -
  • 课程资源
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
    - -
  • 课程资源
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
    - -
  • 课程资源
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
    - -
  • 课程资源
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
    - -
  • 课程资源
  • -
  • 123.0KB
  • -
  • 尹刚
  • -
  • 2016-01-21
  • -
-
- - -
- - - - - - - -
-
-
- - diff --git a/app/views/users/import_resources.js.erb b/app/views/users/import_resources.js.erb index ce5362bcb..e3f640931 100644 --- a/app/views/users/import_resources.js.erb +++ b/app/views/users/import_resources.js.erb @@ -1,8 +1,12 @@ $('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1} ) %>'); showModal('ajax-modal', '615px'); $('#ajax-modal').siblings().remove(); -$('#ajax-modal').before(""); -$('#ajax-modal').parent().css("top","10%").css("left","36%").css("border","3px solid #269ac9"); +$('#ajax-modal').before(""); +<% if params[:project] %> +$('#ajax-modal').parent().css("top","10%").css("left","34%").css("border","3px solid #269ac9"); +<% else %> +$('#ajax-modal').parent().css("top","20%").css("left","42%").css("border","3px solid #269ac9"); +<% end %> $('#ajax-modal').parent().addClass("popbox_polls"); diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index 3840fd892..a0bca31b0 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -1263,3 +1263,25 @@ div.disable_link {background-color: #c1c1c1 !important;} .mh18 {max-height: 18px;} .relatePWrap{max-height: 210px;overflow:hidden;}/*160114课程推荐*/ .courseR {width:220px; padding:10px; background-color:#ffffff; margin-top:10px;} + +/*导入题库样式*/ +.popupWrap {border:3px solid #269ac9; padding:15px; background-color:#ffffff; position:relative; z-index:1000;} +.subjectList {width:585px;} +.subjectDetail {width:385px;} +a.subjectChoose {padding:8px 20px; background-color:#f1f1f1; color:#888888;} +a.chooseActive {background-color:#269ac9; color:#ffffff;} +.subjectBanner {width:585px; height:40px; background-color:#f1f1f1; border-top:1px solid #eaeaea; color:#7a7a7a; font-size:14px;} +.subjectBanner li {height:40px; line-height:40px; vertical-align:middle;} +.subjectName {width:270px; padding-left:10px; padding-right:10px;} +.subjectPublisher {width:80px; text-align:center;} +.subjectDate {width:80px; text-align:center;} +.subjectRow {width:585px; height:40px; color:#7a7a7a; font-size:12px;} +.subjectRow li {height:40px; line-height:40px; vertical-align:middle;} +.subjectSearch {border:1px solid #dddddd; height:32px; width:250px;} +.subjectInfo {width:385px; background-color:#f1f1f1; border:1px solid #dddddd; height:32px; line-height:32px; vertical-align:middle; text-align:center; color:#7a7a7a;} +.subjectWrap {border:1px solid #dddddd; border-top:none; padding:10px; width:365px; height:460px; overflow-y:auto;} +.subjectIntro {color:#585858; line-height:18px; font-size:12px;} +.subjectContent {color:#888888; line-height:18px; font-size:12px;} +.popupClose {background:url(../images/resource_icon_list.png) 0px -40px no-repeat; width:20px; height:20px; display:inline-block; position: absolute; z-index: 1000; right:10px; top:5px;} +.subjectType {width:70px; text-align:center;} +.subjectCount {width:65px; text-align:center;} diff --git a/public/stylesheets/org.css b/public/stylesheets/org.css index aa2d0be18..eaabcafa6 100644 --- a/public/stylesheets/org.css +++ b/public/stylesheets/org.css @@ -117,4 +117,33 @@ div.flash {margin-top :0px !important} .maxh360 {max-height: 810px;} .lh18 { line-height: 18px;} -a.link_file_a2{ background:url(../images/pic_file.png) 0 -15px no-repeat; padding-left: 20px;} \ No newline at end of file +a.link_file_a2{ background:url(../images/pic_file.png) 0 -15px no-repeat; padding-left: 20px;} +/*导入题库样式*/ +.popupWrap {border:3px solid #269ac9; padding:15px; background-color:#ffffff; position:relative; z-index:1000;} +.subjectList {width:585px;} +.subjectDetail {width:385px;} +a.subjectChoose {padding:8px 20px; background-color:#f1f1f1; color:#888888;} +a.chooseActive {background-color:#269ac9; color:#ffffff;} +.subjectBanner {width:585px; height:40px; background-color:#f1f1f1; border-top:1px solid #eaeaea; color:#7a7a7a; font-size:14px;} +.subjectBanner li {height:40px; line-height:40px; vertical-align:middle;} +.subjectName {width:270px; padding-left:10px; padding-right:10px;} +.subjectPublisher {width:80px; text-align:center;} +.subjectDate {width:80px; text-align:center;} +.subjectRow {width:585px; height:40px; color:#7a7a7a; font-size:12px;} +.subjectRow li {height:40px; line-height:40px; vertical-align:middle;} +.subjectSearch {border:1px solid #dddddd; height:32px; width:250px;} +.subjectInfo {width:385px; background-color:#f1f1f1; border:1px solid #dddddd; height:32px; line-height:32px; vertical-align:middle; text-align:center; color:#7a7a7a;} +.subjectWrap {border:1px solid #dddddd; border-top:none; padding:10px; width:365px; height:460px; overflow-y:auto;} +.subjectIntro {color:#585858; line-height:18px; font-size:12px;} +.subjectContent {color:#888888; line-height:18px; font-size:12px;} +.popupClose {background:url(../images/resource_icon_list.png) 0px -40px no-repeat; width:20px; height:20px; display:inline-block; position: absolute; z-index: 1000; right:10px; top:5px;} +.subjectType {width:70px; text-align:center;} +.subjectCount {width:65px; text-align:center;} +a.blue-btn { + padding: 4px 7px; + color: #FFF; + border: none; + background-color: #269ac9; + cursor: pointer; + text-align: center; +} \ No newline at end of file diff --git a/public/stylesheets/project.css b/public/stylesheets/project.css index 1dc5556d3..7e1ae654f 100644 --- a/public/stylesheets/project.css +++ b/public/stylesheets/project.css @@ -1177,4 +1177,26 @@ div.disable_link {background-color: #c1c1c1 !important;} .number-line-old {background-color:#ffdddd; border-color:#f1c0c0;} .code-line-new {background-color:#eaffea;} .number-line-new {background-color:#dbffdb; border-color:#c1e9c1;} -.branch-label {padding-right: 5px; border-radius:2px; color:#888888; display:inline-block; background-color:#f8fafc;} +.branch-label {padding-right: 5px; border-radius:2px; color:#888888; display:inline-block; background-color:#f8fafc;} + +/*导入题库样式*/ +.popupWrap {border:3px solid #269ac9; padding:15px; background-color:#ffffff; position:relative; z-index:1000;} +.subjectList {width:585px;} +.subjectDetail {width:385px;} +a.subjectChoose {padding:8px 20px; background-color:#f1f1f1; color:#888888;} +a.chooseActive {background-color:#269ac9; color:#ffffff;} +.subjectBanner {width:585px; height:40px; background-color:#f1f1f1; border-top:1px solid #eaeaea; color:#7a7a7a; font-size:14px;} +.subjectBanner li {height:40px; line-height:40px; vertical-align:middle;} +.subjectName {width:270px; padding-left:10px; padding-right:10px;} +.subjectPublisher {width:80px; text-align:center;} +.subjectDate {width:80px; text-align:center;} +.subjectRow {width:585px; height:40px; color:#7a7a7a; font-size:12px;} +.subjectRow li {height:40px; line-height:40px; vertical-align:middle;} +.subjectSearch {border:1px solid #dddddd; height:32px; width:250px;} +.subjectInfo {width:385px; background-color:#f1f1f1; border:1px solid #dddddd; height:32px; line-height:32px; vertical-align:middle; text-align:center; color:#7a7a7a;} +.subjectWrap {border:1px solid #dddddd; border-top:none; padding:10px; width:365px; height:460px; overflow-y:auto;} +.subjectIntro {color:#585858; line-height:18px; font-size:12px;} +.subjectContent {color:#888888; line-height:18px; font-size:12px;} +.popupClose {background:url(../images/resource_icon_list.png) 0px -40px no-repeat; width:20px; height:20px; display:inline-block; position: absolute; z-index: 1000; right:10px; top:5px;} +.subjectType {width:70px; text-align:center;} +.subjectCount {width:65px; text-align:center;} From 5fd36c0e788fabde178aec6c4bd5f7088fd6620d Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 3 Mar 2016 17:15:47 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E3=80=81=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E3=80=81=E7=BB=84=E7=BB=87=E8=B5=84=E6=BA=90=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 63 +++++++++++++++++++ app/views/files/_course_file.html.erb | 2 +- app/views/files/_project_file.html.erb | 2 +- app/views/files/_subfield_files.html.erb | 2 +- .../users/_import_resource_info.html.erb | 13 +++- app/views/users/import_into_container.js.erb | 3 + app/views/users/import_resources.js.erb | 10 ++- config/routes.rb | 1 + 8 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 app/views/users/import_into_container.js.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 67d47dc26..d94615791 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2236,6 +2236,69 @@ class UsersController < ApplicationController 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 + + 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) + # 如果该附件已经存课程中,则只更新附件创建时间 + mul_container.attachments.each do |att| + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end + end + next if @exist + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = mul_container + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + attach_copied_obj.save + @save_message = attach_copied_obj.errors.full_messages + end + end + if params[:mul_type] == "Course" + respond_to do |format| + redirect_to course_files_url(mul_container) + end + elsif params[:mul_type] == "Project" + respond_to do |format| + redirect_to project_files_url(mul_container) + end + elsif params[:mul_type] == "SubfieldFile" + respond_to do |format| + redirect_to org_subfield_files_url(mul_container) + end + end + + end + # 根据资源关键字进行搜索 def resource_search search = "%#{params[:search].strip.downcase}%" diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 545680505..4a62c94aa 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -94,7 +94,7 @@ <%= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %> <% if is_course_teacher(User.current,@course) || (@course.publish_resource==1 && User.current.member_of_course?(@course) ) %> - <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course => true), :class => "blue-btn fr mr5", :remote => true) %> + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %> <% end %> <% end %> diff --git a/app/views/files/_project_file.html.erb b/app/views/files/_project_file.html.erb index 0725d9270..98b9ad514 100644 --- a/app/views/files/_project_file.html.erb +++ b/app/views/files/_project_file.html.erb @@ -66,7 +66,7 @@ <% if User.current.member_of?(@project) %> - <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :project => true), :class => "blue-btn fr mr5", :remote => true) %> + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :project_id => @project.id), :class => "blue-btn fr mr5", :remote => true) %> <% end %> <% end %> diff --git a/app/views/files/_subfield_files.html.erb b/app/views/files/_subfield_files.html.erb index 3e98b2ee5..2a8756c47 100644 --- a/app/views/files/_subfield_files.html.erb +++ b/app/views/files/_subfield_files.html.erb @@ -42,7 +42,7 @@ <%= submit_tag "栏目内搜索", :class => "blueBtn mr5 fl",:style => 'width:72px;',:name => "inorg_subfield",:id => "inorg_subfield", :onmouseover => "presscss('inorg_subfield')",:onmouseout =>"buttoncss()" %> <%= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> - <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :subfield_file => true), :class => "blue-btn fr mr5", :remote => true) %> + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :subfield_file_id => @org_subfield.id), :class => "blue-btn fr mr5", :remote => true) %> <%#= link_to "上传资源",subfield_upload_file_org_subfield_files_path(@org_subfield.id, :in_org => 1),:method => "post",:class=>"blueBtn fr mr5",:remote => true %> <% end %>
diff --git a/app/views/users/_import_resource_info.html.erb b/app/views/users/_import_resource_info.html.erb index dd82e9485..270f0956b 100644 --- a/app/views/users/_import_resource_info.html.erb +++ b/app/views/users/_import_resource_info.html.erb @@ -20,6 +20,7 @@ <% end %>
+
    @@ -28,7 +29,11 @@
  • 上传者
  • 上传时间
- <% @attachments.each do |attach| %> + <%= form_tag( url_for({:controller => 'users', :action => 'import_into_container', + :mul_id => params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id], + :mul_type => params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"}), + :remote => true , :method => 'post', :id => 'resource_import_container_form') do %> + <% @attachments.each do |attach| %>
  • <%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %>
  • <%= format_date(attach.created_on) %>
+ <% end %> <% end %>
- - + + +
    <%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %> diff --git a/app/views/users/import_into_container.js.erb b/app/views/users/import_into_container.js.erb new file mode 100644 index 000000000..c977d99da --- /dev/null +++ b/app/views/users/import_into_container.js.erb @@ -0,0 +1,3 @@ +<% if @flag == true%> +alert("发送成功") +<% end %> \ No newline at end of file diff --git a/app/views/users/import_resources.js.erb b/app/views/users/import_resources.js.erb index e3f640931..b37079444 100644 --- a/app/views/users/import_resources.js.erb +++ b/app/views/users/import_resources.js.erb @@ -1,8 +1,14 @@ -$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1} ) %>'); +<% if params[:project_id] %> +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :project_id => params[:project_id]} ) %>'); +<% elsif params[:course_id] %> +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :course_id => params[:course_id]} ) %>'); +<% elsif params[:subfield_file_id] %> +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :subfield_file_id => params[:subfield_file_id]} ) %>'); +<% end %> showModal('ajax-modal', '615px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before(""); -<% if params[:project] %> +<% if params[:project_id] %> $('#ajax-modal').parent().css("top","10%").css("left","34%").css("border","3px solid #269ac9"); <% else %> $('#ajax-modal').parent().css("top","20%").css("left","42%").css("border","3px solid #269ac9"); diff --git a/config/routes.rb b/config/routes.rb index e6de40fc5..1cb6df18e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -536,6 +536,7 @@ RedmineApp::Application.routes.draw do get 'edit_brief_introduction' get "user_resource" get "import_resources" + post "import_into_container" get "resource_search" post "user_resource_create" post "user_resource_delete" From 8815e99db53ec19f7d1734bc937c21f26280f350 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 3 Mar 2016 17:25:52 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E8=B5=84=E6=BA=90=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 23 ++++++++----------- .../users/_import_resource_info.html.erb | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d94615791..0bbdacff8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2283,20 +2283,17 @@ class UsersController < ApplicationController @save_message = attach_copied_obj.errors.full_messages end end - if params[:mul_type] == "Course" - respond_to do |format| - redirect_to course_files_url(mul_container) - end - elsif params[:mul_type] == "Project" - respond_to do |format| - redirect_to project_files_url(mul_container) - end - elsif params[:mul_type] == "SubfieldFile" - respond_to do |format| - redirect_to org_subfield_files_url(mul_container) - end + respond_to do |format| + format.html { + if params[:mul_type] == "Course" + redirect_to course_files_url(mul_container) + elsif params[:mul_type] == "Project" + redirect_to project_files_url(mul_container) + elsif params[:mul_type] == "SubfieldFile" + redirect_to org_subfield_files_url(mul_container) + end + } end - end # 根据资源关键字进行搜索 diff --git a/app/views/users/_import_resource_info.html.erb b/app/views/users/_import_resource_info.html.erb index 270f0956b..a28d9d534 100644 --- a/app/views/users/_import_resource_info.html.erb +++ b/app/views/users/_import_resource_info.html.erb @@ -32,7 +32,7 @@ <%= form_tag( url_for({:controller => 'users', :action => 'import_into_container', :mul_id => params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id], :mul_type => params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"}), - :remote => true , :method => 'post', :id => 'resource_import_container_form') do %> + :method => 'post', :id => 'resource_import_container_form') do %> <% @attachments.each do |attach| %>
diff --git a/app/views/projects/member.html.erb b/app/views/projects/member.html.erb index e6760d3b3..21ce71b47 100644 --- a/app/views/projects/member.html.erb +++ b/app/views/projects/member.html.erb @@ -1,5 +1,10 @@
-

<%= @subPage_title %>

+

<%= @subPage_title%>

+ <% if is_project_manager?(User.current, @project) %> + + <%=link_to "成员管理", :controller => 'projects', :action => 'settings', :id => @project.id, :tab => 'members' %> + + <% end %>
<%= error_messages_for 'member' %> diff --git a/app/views/projects/settings.html.erb b/app/views/projects/settings.html.erb index 76258b9e9..9eae5d65b 100644 --- a/app/views/projects/settings.html.erb +++ b/app/views/projects/settings.html.erb @@ -1,17 +1,17 @@
选用资源库中的资源
- 公共资源 - 我的资源 + <% if !params[:course_id].nil? %> + 公共资源 + 我的资源 + <% elsif !params[:project_id].nil? %> + 公共资源 + 我的资源 + <% elsif !params[:subfield_file_id].nil? %> + 公共资源 + 我的资源 + <% end %> <%= form_tag( url_for(:controller => 'users', :action => 'resource_search', :id => User.current.id), :remote => true , :method => 'get', :id => 'resource_search_form') do %> From ba9b22fbe180b72419cf48faf10aa53c104be975 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 3 Mar 2016 23:56:06 +0800 Subject: [PATCH 15/17] =?UTF-8?q?=E5=85=AC=E5=85=B1=E8=B5=84=E6=BA=90?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E9=99=A4=E3=80=81=E9=87=8D=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_resources_list.html.erb | 7 +------ app/views/users/user_resource.html.erb | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index b9b74760a..4e429a640 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -13,19 +13,14 @@ <%= link_to truncate(attach.filename, :length => 30), download_named_attachment_path(attach.id, attach.filename), :title => attach.filename, :class => 'resourcesBlack' %>
  • <%= format_date(attach.created_on) %>
  • -
  • <%= attach.author_id %>
  • <%= attach.quotes.nil? ? 0 : attach.quotes %>
  • -
  • <%= attach.author_id %>
  • <%= attach.downloads %>
  • <%= attach.author_id %>
  • <%= number_to_human_size(attach.filesize) %>
  • -
  • <%= attach.author_id %>
  • -
  • <%= attach.author_id %>
  • <%= get_resource_type(attach.container_type)%>
  • -
  • <%= attach.author_id %>
  • -
  • <%= attach.author_id %>
  • +
  • <%= attach.id %>
  • <% end %> diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 69122aaba..88e8e7140 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -73,7 +73,7 @@
    • - 公共资源 + 公共资源
    • 我的资源 From e9c9112b38493522c2598e7bfb4f57580ee58665 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 4 Mar 2016 00:41:41 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E5=85=AC=E5=85=B1=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 58 ++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0bbdacff8..1c24d3395 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2296,21 +2296,54 @@ class UsersController < ApplicationController end end + # 公共资源搜索结果 + def get_resource_search_public user_course_ids, user_project_ids + @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") + + # @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") + end + + # 我的资源 搜索结果 + def get_resource_search_my author_id, user_course_ids, user_project_ids + @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')) "+ + "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") + + # @attachments = Attachment.where("((author_id = #{params[:id]} 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 (filename like :p) ",:p=>search).order("created_on desc") + end + + # 课程搜索结果 + def get_resource_search_course author_id + @attachments = Attachment.where("(author_id = #{author_id} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("created_on desc") + end + + # 项目资源搜索结果 + def get_resource_search_project author_id + @attachments = Attachment.where("author_id = #{author_id} and container_type = 'Project' and (filename like :p)",:p=>search).order("created_on desc") + end + + # 附件 + def get_resource_search_attach author_id + @attachments = Attachment.where("author_id = #{author_id} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc") + end + + # 个人 + def get_resource_search_principal author_id + @attachments = Attachment.where("author_id = #{author_id} and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc") + end + # 根据资源关键字进行搜索 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} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询 - @attachments = Attachment.where("((author_id = #{params[:id]} 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 (filename like :p) ",:p=>search).order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 - @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type in" + - " ('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon'))"+ - " or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) )" + - " and (filename like :p) ",:p=>search).order("created_on desc") - end + @attachments = get_resource_search_my(params[:id], user_course_ids, user_project_ids) elsif params[:type] == "2" #课程资源 if User.current.id.to_i == params[:id].to_i user_course_ids = User.current.courses.map { |c| c.id} @@ -2341,8 +2374,7 @@ 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 = get_resource_search_public(params[:id], user_course_ids, user_project_ids) end @type = params[:type] @limit = 25 From 5ab9e3b5b7c71a6312b3cebb57e102bde5e88f3a Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 4 Mar 2016 09:29:20 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=90=9C=E7=B4=A2=20?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=95=99=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 192 ++++++++++-------------- app/views/layouts/base_courses.html.erb | 3 + 2 files changed, 83 insertions(+), 112 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1c24d3395..10fec7c1b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -106,7 +106,7 @@ class UsersController < ApplicationController redirect_to signin_url return elsif @user != User.current && !User.current.admin? - return render_403 + return render_403 end # 初始化/更新 点击按钮时间 # 24小时内显示系统消息 @@ -570,7 +570,7 @@ class UsersController < ApplicationController student_work.save flash[:notice] = l(:notice_successful_create) redirect_to student_work_index_url(:homework => params[:homework]) - else + else render_403 end end @@ -775,7 +775,7 @@ class UsersController < ApplicationController def store_selected_resource session[:seleted_resource_ids] = [] if session[:seleted_resource_ids].nil? if params[:save] == 'y' - session[:seleted_resource_ids] << params[:res_id] + session[:seleted_resource_ids] << params[:res_id] else session[:seleted_resource_ids].delete( params[:res_id]) end @@ -1081,12 +1081,12 @@ class UsersController < ApplicationController else blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) end else - # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) + # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ @@ -1733,30 +1733,30 @@ class UsersController < ApplicationController end ori = Attachment.find_by_id(send_id) unless subfield_id.nil? - attach_copied_obj = ori.copy - @exist = false - OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from - att.created_on = Time.now - att.save - @exist = true - break - end + attach_copied_obj = ori.copy + @exist = false + OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break end - if @exist == false #如果不存在该资源 - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 - attach_copied_obj.container = OrgSubfield.find(subfield_id) - attach_copied_obj.created_on = Time.now - attach_copied_obj.author_id = User.current.id - attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 1 - end - if attach_copied_obj.save - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) - end + end + if @exist == false #如果不存在该资源 + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = OrgSubfield.find(subfield_id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 1 end + if attach_copied_obj.save + ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + end + end end elsif params[:send_ids].present? send_ids = params[:send_ids].split(" ") @@ -1768,30 +1768,30 @@ class UsersController < ApplicationController ori = Attachment.find_by_id(send_id) unless subfield_id.nil? - next if ori.blank? - @exist = false - OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from - att.created_on = Time.now - att.save - @exist = true - break - end - end - next if @exist - attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 - attach_copied_obj.container = OrgSubfield.find(subfield_id) - attach_copied_obj.created_on = Time.now - attach_copied_obj.author_id = User.current.id - attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 1 - end - if attach_copied_obj.save - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + next if ori.blank? + @exist = false + OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break end + end + next if @exist + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = OrgSubfield.find(subfield_id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 1 + end + if attach_copied_obj.save + ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + end end end else @@ -1826,8 +1826,8 @@ class UsersController < ApplicationController end news.attachments.each do |attach| course_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, - :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, - :is_public => attach.is_public, :quotes => 0) + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) end end end @@ -1846,8 +1846,8 @@ class UsersController < ApplicationController end news.attachments.each do |attach| message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, - :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, - :is_public => attach.is_public, :quotes => 0) + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) end end end @@ -1863,8 +1863,8 @@ class UsersController < ApplicationController end news.attachments.each do |attach| org_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, - :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, - :is_public => attach.is_public, :quotes => 0) + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) end OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'News', :org_act_id => org_news.id, :user_id => User.current.id) end @@ -2135,15 +2135,15 @@ class UsersController < ApplicationController # 获取公共资源 def get_public_resources user_course_ids, user_project_ids 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)" ).order("created_on desc") + "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)" ).order("created_on desc") end # 获取我的资源 def get_my_resources author_id, user_course_ids, user_project_ids 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')) "+ - "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)" ).order("created_on desc") + "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)" ).order("created_on desc") end # 获取我的课程资源 @@ -2261,12 +2261,12 @@ class UsersController < ApplicationController ori = Attachment.find_by_id(send_id) # 如果该附件已经存课程中,则只更新附件创建时间 mul_container.attachments.each do |att| - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from - att.created_on = Time.now - att.save - @exist = true - break - end + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end end next if @exist attach_copied_obj = ori.copy @@ -2296,54 +2296,21 @@ class UsersController < ApplicationController end end - # 公共资源搜索结果 - def get_resource_search_public user_course_ids, user_project_ids - @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") - - # @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") - end - - # 我的资源 搜索结果 - def get_resource_search_my author_id, user_course_ids, user_project_ids - @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')) "+ - "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") - - # @attachments = Attachment.where("((author_id = #{params[:id]} 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 (filename like :p) ",:p=>search).order("created_on desc") - end - - # 课程搜索结果 - def get_resource_search_course author_id - @attachments = Attachment.where("(author_id = #{author_id} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("created_on desc") - end - - # 项目资源搜索结果 - def get_resource_search_project author_id - @attachments = Attachment.where("author_id = #{author_id} and container_type = 'Project' and (filename like :p)",:p=>search).order("created_on desc") - end - - # 附件 - def get_resource_search_attach author_id - @attachments = Attachment.where("author_id = #{author_id} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc") - end - - # 个人 - def get_resource_search_principal author_id - @attachments = Attachment.where("author_id = #{author_id} and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc") - end - # 根据资源关键字进行搜索 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') #全部 - @attachments = get_resource_search_my(params[:id], user_course_ids, user_project_ids) + 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','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 (filename like :p) ",:p=>search).order("created_on desc") + else + user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 + @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type in" + + " ('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon'))"+ + " or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) )" + + " and (filename like :p) ",:p=>search).order("created_on desc") + end elsif params[:type] == "2" #课程资源 if User.current.id.to_i == params[:id].to_i user_course_ids = User.current.courses.map { |c| c.id} @@ -2374,7 +2341,8 @@ class UsersController < ApplicationController end elsif params[:type] == "6" #全部资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_resource_search_public(params[:id], user_course_ids, user_project_ids) + @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") end @type = params[:type] @limit = 25 diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 8dfda10bd..fa59fbed9 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -162,6 +162,9 @@ <% unless contributor_score.journal_num == 0 %> 课程留言:<%= contributor_score.journal_num %>
      <% end %> + <% unless contributor_score.homework_journal_num == 0 %> + 作业留言:<%= contributor_score.homework_journal_num %>
      + <% end %> <% unless contributor_score.news_reply_num == 0 %> 课程通知:<%= contributor_score.news_reply_num %>
      <% end %>