diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7fe146926..682d79424 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -817,18 +817,18 @@ class UsersController < ApplicationController # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") #全部 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end @type = params[:type] @limit = 7 @@ -938,12 +938,7 @@ class UsersController < ApplicationController return end # 自己访问自己的页面才更新消息状态 - if User.current == @user - journals_messages = UserFeedbackMessage.where("user_id =? and journals_for_message_type =? and viewed =?", User.current.id, "JournalsForMessage", 0) - journals_messages.each do |journals_message| - journals_message.update_attributes(:viewed => true) - end - end + UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true) # end @page = params[:page] ? params[:page].to_i + 1 : 0 if params[:type].present? @@ -1551,37 +1546,37 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == 2 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:status] == "5" - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) end elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids) + @attachments = get_course_resources_public( user_course_ids, params[:order]) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids) + @attachments = get_project_resources_public(user_project_ids, params[:order]) elsif params[:status] == "4" - @attachments = get_attch_resources_public + @attachments = get_attch_resources_public params[:order] elsif params[:status] == "5" - @attachments = get_principal_resources_public + @attachments = get_principal_resources_public params[:order] else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end end @status = params[:status] @@ -1613,37 +1608,37 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == 2 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:status] == "5" - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) end elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids) + @attachments = get_course_resources_public( user_course_ids, params[:order]) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids) + @attachments = get_project_resources_public(user_project_ids, params[:order]) elsif params[:status] == "4" - @attachments = get_attch_resources_public + @attachments = get_attch_resources_public params[:order] elsif params[:status] == "5" - @attachments = get_principal_resources_public + @attachments = get_principal_resources_public params[:order] else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end end @status = params[:status] @@ -2331,61 +2326,70 @@ class UsersController < ApplicationController end # 获取公共资源 - def get_public_resources user_course_ids, user_project_ids + def get_public_resources user_course_ids, user_project_ids, order 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 = '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("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end # 获取我的资源 - def get_my_resources author_id, user_course_ids, user_project_ids + def get_my_resources author_id, user_course_ids, user_project_ids, order, score 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 = '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("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + end + + # 获取我的资源查询结果 + def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search) + @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("#{order.nil? ? 'created_on' : order} #{score}") 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") + def get_course_resources author_id, user_course_ids, order + 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("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end # 获取公共资源课程 - def get_course_resources_public user_course_ids - attchments = Attachment.where("(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") + def get_course_resources_public user_course_ids, order + attchments = Attachment.where("(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("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end # 获取我的项目资源 - def get_project_resources author_id, user_project_ids - attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Project') or (container_type = 'Course' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + def get_project_resources author_id, user_project_ids, order + attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end # 获取公共资源的项目资源 - def get_project_resources_public user_project_ids - attchments = Attachment.where("(container_type = 'Project') 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") + def get_project_resources_public user_project_ids, order + attchments = Attachment.where("(container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") 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") + def get_attch_resources author_id, order + attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end # 获取公共资源中我上传的附件 - def get_attch_resources_public - attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") + def get_attch_resources_public order + attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end # 获取我的用户类型资源 - def get_principal_resources author_id - attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc") + def get_principal_resources author_id, order + attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end # 获取我的用户类型资源 - def get_principal_resources_public - attchments = Attachment.where("container_type = 'Principal'").order("created_on desc") + def get_principal_resources_public order + attchments = Attachment.where("container_type = 'Principal'").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end # 资源库 分为全部 课程资源 项目资源 附件 def user_resource + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" # 别人的资源库是没有权限去看的 if User.current.id.to_i != params[:id].to_i render_403 @@ -2397,37 +2401,37 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, @order) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, @order) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], @order elsif params[:status] == "5" - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], @order else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids) + @attachments = get_course_resources_public( user_course_ids, params[:order]) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids) + @attachments = get_project_resources_public(user_project_ids, params[:order]) elsif params[:status] == "4" - @attachments = get_attch_resources_public + @attachments = get_attch_resources_public params[:order] elsif params[:status] == "5" - @attachments = get_principal_resources_public + @attachments = get_principal_resources_public params[:order] else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end end @status = params[:status] @@ -2457,10 +2461,10 @@ class UsersController < ApplicationController # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end @type = params[:type] @limit = 10 @@ -2493,10 +2497,10 @@ class UsersController < ApplicationController # 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") + "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("#{params[:order].nil? ? 'created_on' : params[:order]} desc") elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end @type = params[:type] @limit = 10 @@ -2566,57 +2570,74 @@ class UsersController < ApplicationController # 根据资源关键字进行搜索 def resource_search - search = "%#{params[:search].strip.downcase}%" + @order, @b_sort = params[:order] || "created_on", params[:sort] || "desc" + @score = @b_sort == "desc" ? "asc" : "desc" + @user = User.current + switch_search = params[:search].nil? ? " " : params[:search] + search = "%#{switch_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 - - @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") + if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部 + if params[:status] == "2" + @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(',')})) and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "3" + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "4" + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "5" + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") 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") + # 公共资源库:所有公开资源或者我上传的私有资源 + get_my_resources_search(@user.id, user_course_ids, user_project_ids, @order, @score, search) 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(',')})) and (filename like :p) ",:p=>search).order("created_on desc") + @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(',')})) and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") 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(',')})) )"+ - " and (filename like :p) ",:p=>search).order("created_on desc") + " and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end - elsif params[:type] == "3" #项目资源 + 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' and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like :p) ",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end - elsif params[:type] == "4" #附件 + 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('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end - elsif params[:type] == "5" #用户资源 + 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' and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + end + elsif params[:type] == "6" # 全部资源 + if params[:status] == "2" + @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(',')})) and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "3" + @attachments = Attachment.where("container_type = 'Project' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "4" + @attachments = Attachment.where("container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "5" + @attachments = Attachment.where("container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + else + # 公共资源库:所有公开资源或者我上传的私有资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @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("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end - elsif params[:type] == "6" #全部资源 - # 公共资源库:所有公开资源或者我上传的私有资源 - @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 + @status = params[:status] + @type = params[:type] @type = params[:type] @limit = 25 @is_remote = true diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 44b919121..bdd34d80d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -62,7 +62,7 @@ module UsersHelper when 'Course' result = current_time_and_term_resource content when 'Project' - result = content.name + result = content.name + "(" + content.id.to_s + ")" when 'Issue' result = content.subject when 'Message' diff --git a/app/views/users/_user_resource_info.html.erb b/app/views/users/_user_resource_info.html.erb index 6eddf1e05..bea78130a 100644 --- a/app/views/users/_user_resource_info.html.erb +++ b/app/views/users/_user_resource_info.html.erb @@ -1,21 +1,11 @@
上传资源
- <%= render :partial => 'users/resource_search_form',:locals => {:user => @user, :type => @type} %> + <%= render :partial => 'users/resource_search_form',:locals => {:user => @user, :type => @type, :order => @order, :sort => @score, :status => @status} %>
- +<%= render :partial => 'users/user_resource_tip_list', :locals => { :type => @type, :status => @status} %>
@@ -23,7 +13,6 @@
-
diff --git a/app/views/users/_user_resource_tip_list.html.erb b/app/views/users/_user_resource_tip_list.html.erb new file mode 100644 index 000000000..5d5876ac8 --- /dev/null +++ b/app/views/users/_user_resource_tip_list.html.erb @@ -0,0 +1,33 @@ +
    +
  • +
  • 资源名称
  • +
  • + <%= link_to "上传时间", resource_search_user_path(:type => @type, :status => @status, :sort => @score, :order => "created_on", :search => " "), :class => "fl", :remote => true %> + <% if @order == "created_on" %> + <%= link_to "", user_resource_user_path(:type => @type, :status => @status, :sort => @score, :order => "created_on", :search => " "), :class => "#{@score == 'desc' ? 'st_up' : 'st_down'} mt16", :remote => true %> + <% end %> +
  • +
  • + <%= link_to "引用数", resource_search_user_path(:type => @type, :status => @status, :sort => @score, :order => "quotes"), :class => "fl", :remote => true %> + <% if @order == "quotes" %> + <%= link_to "", user_resource_user_path(:type => @type, :status => @status, :sort => @score, :order => "quotes"), :class => "#{@score == 'desc' ? 'st_up' : 'st_down'} mt16", :remote => true %> + <% end %> +
  • +
  • + <%= link_to "下载数", resource_search_user_path(:type => @type, :status => @status, :sort => @score, :order => "downloads"), :class => "fl", :remote => true %> + <% if @order == "downloads" %> + <%= link_to "", user_resource_user_path(:type => @type, :status => @status, :sort => @score, :order => "downloads"), :class => "#{@score == 'desc' ? 'st_up' : 'st_down'} mt16", :remote => true %> + <% end %> +
  • +
  • +
    + <%= link_to "大小", resource_search_user_path(:type => @type, :status => @status, :sort => @score, :order => "filesize"), :class => "fl", :remote => true %> + <% if @order == "filesize" %> + <%= link_to "", user_resource_user_path(:type => @type, :status => @status, :sort => @score, :order => "filesize"), :class => "#{@score == 'desc' ? 'st_up' : 'st_down'} mt16", :remote => true %> + <% end %> +
    +
  • +
  • 上传者
  • +
  • 类别
  • +
  • 来源
  • +
\ No newline at end of file diff --git a/app/views/users/resource_search.js.erb b/app/views/users/resource_search.js.erb index d295ce003..38e80e75b 100644 --- a/app/views/users/resource_search.js.erb +++ b/app/views/users/resource_search.js.erb @@ -1,5 +1,14 @@ $("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments})%>'); +$("#resource_tip_list").html('<%= escape_javascript( render :partial => 'users/user_resource_tip_list', :locals => {:user => @user, :type => @type, :status => @status}) %>'); $("#pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); $("#res_all_count").html(<%= @atta_count%>); $("#res_count").html(0); -$("#checkboxAll").attr('checked',false); \ No newline at end of file +$("#checkboxAll").attr('checked',false); +//更新状态 +$("#public_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '6', :status => @status) %>'); +$("#my_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '1', :status => @status) %>'); +$("#resource_type_all").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 1) %>'); +$("#resource_type_course").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 2) %>'); +$("#resource_type_project").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 3) %>'); +$("#resource_type_user").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 5) %>'); +$("#resource_type_file").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 4) %>'); \ 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 f45eb11c2..751f0a48f 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -21,14 +21,6 @@ $("#resource_search_form").submit(); } - 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")); diff --git a/app/views/users/user_resource.js.erb b/app/views/users/user_resource.js.erb index 4ba186579..370b84711 100644 --- a/app/views/users/user_resource.js.erb +++ b/app/views/users/user_resource.js.erb @@ -1,4 +1,5 @@ $("#search_div").html('<%= escape_javascript( render :partial => 'resource_search_form', :locals => {:user => @user, :type => @type} ) %>'); +$("#resource_tip_list").html('<%= escape_javascript( render :partial => 'users/user_resource_tip_list', :locals => {:user => @user, :type => @type, :status => @status} ) %>'); $("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' , :locals => { :attachments => @attachments}) %>'); $("#pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); $("#res_count").html(0); diff --git a/app/views/users/user_resource_create.js.erb b/app/views/users/user_resource_create.js.erb index f69057273..5ce547fbf 100644 --- a/app/views/users/user_resource_create.js.erb +++ b/app/views/users/user_resource_create.js.erb @@ -1,4 +1,3 @@ - closeModal(); $("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments})%>'); //这里不能将翻页的更新 diff --git a/public/stylesheets/public.css b/public/stylesheets/public.css index b84fb040e..3780723b9 100644 --- a/public/stylesheets/public.css +++ b/public/stylesheets/public.css @@ -117,6 +117,7 @@ h4{ font-size:14px; color:#3b3b3b;} .mt6{ margin-top:6px;} .mt8{ margin-top:8px;} .mt10{ margin-top:10px !important;} +.mt16{ margin-top:16px !important;} .mt20{margin-top: 20px;} .mt30{ margin-top: 30px;} .mt40{ margin-top: 40px;} @@ -1131,4 +1132,6 @@ a.resource-tab-active {color:#fff; background-color:#269ac9; border-bottom:1px s a.group-btn{ background: url(../images/course/hwork_icon.png) -2px -58px no-repeat !important; height:20px; display:block; padding-left:23px; color:#888888; -moz-transition :all 0s linear 0s; -webkit-transition :all 0s linear 0s; -o-transition:all 0s linear 0s; transition:all 0s linear 0s;} a.program-btn{background: url(../images/homepage_icon.png) -86px -393px no-repeat; width:30px; height:20px; display:block; padding-left:23px; color:#888888;} - +/*排序样式*/ +a.st_up{ display: block; width:8px; float:left; height:13px; background:url(../images/pic_up.png) 0 0 no-repeat; margin-top:5px; margin-left:3px;} +a.st_down{ display: block; width:8px; float:left; height:13px; background:url(../images/pic_up.png) 0 -22px no-repeat; margin-top:5px; margin-left:3px;} \ No newline at end of file