公共资源库,排序

This commit is contained in:
huang 2016-03-15 09:26:26 +08:00
parent 97a7694778
commit 2b21213b7f
9 changed files with 178 additions and 131 deletions

View File

@ -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

View File

@ -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'

View File

@ -1,21 +1,11 @@
<div id="users_setting">
<div class="resourcesUploadBox mt10"><a href="javascript:void(0);" onclick="show_upload();" class="uploadBoxIcon">上传资源</a></div>
<div id="search_div">
<%= 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} %>
</div>
</div>
<div class="cl"></div>
<ul class="resource-list-tab mt10">
<li class="resource-list-checkbox fl"> </li>
<li class="resource-list-name fl">资源名称</li>
<li class="resource-list-time fr">上传时间</li>
<li class="resource-list-quote fr">引用数</li>
<li class="resource-list-download fr">下载数</li>
<li class="resource-list-size fr">大小</li>
<li class="resource-list-uploader fr">上传者</li>
<li class="resource-list-type fr">类别</li>
<li class="resource-list-from fr">来源</li>
</ul>
<%= render :partial => 'users/user_resource_tip_list', :locals => { :type => @type, :status => @status} %>
<div class="cl"></div>
<form id="resources_list_form">
<div id="resources_list">
@ -23,7 +13,6 @@
</div>
<div class="cl"></div>
<div class="resource-list-option fl">
<div class="resource-check-all">
<input id="checkboxAll" type="checkbox" value="" onclick="all_select();" class="resourcesCheckbox" />

View File

@ -0,0 +1,33 @@
<ul class="resource-list-tab mt10" id="resource_tip_list">
<li class="resource-list-checkbox fl"> </li>
<li class="resource-list-name fl">资源名称</li>
<li class="resource-list-time fr">
<%= 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 %>
</li>
<li class="resource-list-quote fr">
<%= 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 %>
</li>
<li class="resource-list-download fr">
<%= 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 %>
</li>
<li class="resource-list-size fr">
<div style="margin: 0 auto; width: 40px">
<%= 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 %>
</div>
</li>
<li class="resource-list-uploader fr">上传者</li>
<li class="resource-list-type fr">类别</li>
<li class="resource-list-from fr">来源</li>
</ul>

View File

@ -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);
$("#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) %>');

View File

@ -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"));

View File

@ -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);

View File

@ -1,4 +1,3 @@
closeModal();
$("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments})%>');
//这里不能将翻页的更新

View File

@ -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;}