公共资源删除、新建代码优化

This commit is contained in:
huang 2016-03-15 16:28:35 +08:00
parent 22ce591c36
commit a10475fa65
4 changed files with 58 additions and 50 deletions

View File

@ -1549,43 +1549,39 @@ class UsersController < ApplicationController
user_project_ids = User.current.projects.map {|p| p.id} user_project_ids = User.current.projects.map {|p| p.id}
# user_org_ids = User.current.organizations.map {|o| o.id} # user_org_ids = User.current.organizations.map {|o| o.id}
@user = User.find(params[:id]) @user = User.find(params[:id])
#@user.save_attachments(params[:attachments],User.current) # 保存文件
# Container_type为Principal
attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true) attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true)
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@score = @b_sort == "desc" ? "asc" : "desc"
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") # 我的资源 if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == 2 if params[:status] == "2"
@attachments = get_course_resources(params[:id], user_course_ids, params[:order]) @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
elsif params[:status] == "3" elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids, params[:order]) @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
elsif params[:status] == "4" elsif params[:status] == "4"
@attachments = get_attch_resources params[:id], params[:order] @attachments = get_attch_resources(params[:id], @order, @score)
elsif params[:status] == "5" elsif params[:status] == "5"
@attachments = get_principal_resources params[:id], params[:order] @attachments = get_principal_resources(params[:id], @order, @score)
else else
# 公共资源库:所有公开资源或者我上传的私有资源 # 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
end end
elsif params[:type] == "2" # 课程资源
@attachments = get_course_resources(params[:id], user_course_ids, params[:order])
elsif params[:type] == "3" # 项目资源
@attachments = get_project_resources(params[:id], user_project_ids, params[:order])
elsif params[:type] == "4" #附件
@attachments = get_attch_resources params[:id], params[:order]
elsif params[:type] == "5" #用户资源
@attachments = get_principal_resources params[:id], params[:order]
elsif params[:type] == "6" # 公共资源 elsif params[:type] == "6" # 公共资源
if params[:status] == "2" if params[:status] == "2"
@attachments = get_course_resources_public( user_course_ids, params[:order]) @attachments = get_course_resources_public( user_course_ids, @order, @score)
elsif params[:status] == "3" elsif params[:status] == "3"
@attachments = get_project_resources_public(user_project_ids, params[:order]) @attachments = get_project_resources_public(user_project_ids, @order, @score)
elsif params[:status] == "4" elsif params[:status] == "4"
@attachments = get_attch_resources_public params[:order] @attachments = get_attch_resources_public(@order, @score)
elsif params[:status] == "5" elsif params[:status] == "5"
@attachments = get_principal_resources_public params[:order] @attachments = get_principal_resources_public(@order, @score)
else else
# 公共资源库:所有公开资源或者我上传的私有资源 # 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
end end
end end
@status = params[:status] @status = params[:status]
@ -1611,43 +1607,38 @@ class UsersController < ApplicationController
Attachment.where("author_id = #{User.current.id}").delete(id) Attachment.where("author_id = #{User.current.id}").delete(id)
end end
end end
@user = User.current
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@score = @b_sort == "desc" ? "asc" : "desc"
user_course_ids = User.current.courses.map { |c| c.id} user_course_ids = User.current.courses.map { |c| c.id}
user_project_ids = User.current.projects.map {|p| p.id} user_project_ids = User.current.projects.map {|p| p.id}
# user_org_ids = User.current.organizations.map {|o| o.id} # user_org_ids = User.current.organizations.map {|o| o.id}
if(params[:type].blank? || params[:type] == "1") # 我的资源 if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == 2 if params[:status] == "2"
@attachments = get_course_resources(params[:id], user_course_ids, params[:order]) @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
elsif params[:status] == "3" elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids, params[:order]) @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
elsif params[:status] == "4" elsif params[:status] == "4"
@attachments = get_attch_resources params[:id], params[:order] @attachments = get_attch_resources(params[:id], @order, @score)
elsif params[:status] == "5" elsif params[:status] == "5"
@attachments = get_principal_resources params[:id], params[:order] @attachments = get_principal_resources(params[:id], @order, @score)
else else
# 公共资源库:所有公开资源或者我上传的私有资源 # 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
end end
elsif params[:type] == "2" # 课程资源
@attachments = get_course_resources(params[:id], user_course_ids, params[:order])
elsif params[:type] == "3" # 项目资源
@attachments = get_project_resources(params[:id], user_project_ids, params[:order])
elsif params[:type] == "4" #附件
@attachments = get_attch_resources params[:id], params[:order]
elsif params[:type] == "5" #用户资源
@attachments = get_principal_resources params[:id], params[:order]
elsif params[:type] == "6" # 公共资源 elsif params[:type] == "6" # 公共资源
if params[:status] == "2" if params[:status] == "2"
@attachments = get_course_resources_public( user_course_ids, params[:order]) @attachments = get_course_resources_public( user_course_ids, @order, @score)
elsif params[:status] == "3" elsif params[:status] == "3"
@attachments = get_project_resources_public(user_project_ids, params[:order]) @attachments = get_project_resources_public(user_project_ids, @order, @score)
elsif params[:status] == "4" elsif params[:status] == "4"
@attachments = get_attch_resources_public params[:order] @attachments = get_attch_resources_public(@order, @score)
elsif params[:status] == "5" elsif params[:status] == "5"
@attachments = get_principal_resources_public params[:order] @attachments = get_principal_resources_public(@order, @score)
else else
# 公共资源库:所有公开资源或者我上传的私有资源 # 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
end end
end end
@status = params[:status] @status = params[:status]
@ -2478,13 +2469,13 @@ class UsersController < ApplicationController
end end
elsif params[:type] == "6" # 公共资源 elsif params[:type] == "6" # 公共资源
if params[:status] == "2" if params[:status] == "2"
@attachments = get_course_resources_public( user_course_ids, params[:order], @score) @attachments = get_course_resources_public( user_course_ids, @order, @score)
elsif params[:status] == "3" elsif params[:status] == "3"
@attachments = get_project_resources_public(user_project_ids, params[:order], @score) @attachments = get_project_resources_public(user_project_ids, @order, @score)
elsif params[:status] == "4" elsif params[:status] == "4"
@attachments = get_attch_resources_public(params[:order], @score) @attachments = get_attch_resources_public(@order, @score)
elsif params[:status] == "5" elsif params[:status] == "5"
@attachments = get_principal_resources_public(params[:order], @score) @attachments = get_principal_resources_public(@order, @score)
else else
# 公共资源库:所有公开资源或者我上传的私有资源 # 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)

View File

@ -9,7 +9,6 @@ $("#res_all_count").html(<%= @atta_count %>);
$("#public_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '6') %>'); $("#public_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '6') %>');
$("#my_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '1') %>'); $("#my_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '1') %>');
$("#resource_type_all").attr('href','<%= user_resource_user_path(@user, :type => @type, :status => 1) %>'); $("#resource_type_all").attr('href','<%= user_resource_user_path(@user, :type => @type, :status => 1) %>');
$("#resource_type_course").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 2) %>'); $("#resource_type_course").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 2) %>');
$("#resource_type_project").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 3) %>'); $("#resource_type_project").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 3) %>');

View File

@ -1,6 +1,15 @@
closeModal(); closeModal();
$("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments})%>'); $("#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}) %>');
$("#res_all_count").html('<%= @atta_count%>'); $("#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); $("#res_count").html(0);
$("#checkboxAll").attr('checked',false); $("#checkboxAll").attr('checked',false);
//更新状态
$("#public_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '6') %>');
$("#my_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '1') %>');
$("#resource_type_all").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 1, :search => @switch_search) %>');
$("#resource_type_course").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 2, :search => @switch_search) %>');
$("#resource_type_project").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 3, :search => @switch_search) %>');
$("#resource_type_user").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 5, :search => @switch_search) %>');
$("#resource_type_file").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 4, :search => @switch_search) %>');

View File

@ -1,5 +1,14 @@
$("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments})%>'); $("#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 %>'); $("#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_all_count").html(<%= @atta_count%>);
$("#res_count").html(0); $("#res_count").html(0);
$("#checkboxAll").attr('checked',false); $("#checkboxAll").attr('checked',false);
//更新状态
$("#public_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '6') %>');
$("#my_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '1') %>');
$("#resource_type_all").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 1, :search => @switch_search) %>');
$("#resource_type_course").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 2, :search => @switch_search) %>');
$("#resource_type_project").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 3, :search => @switch_search) %>');
$("#resource_type_user").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 5, :search => @switch_search) %>');
$("#resource_type_file").attr('href','<%= resource_search_user_path(@user,:type => @type, :status => 4, :search => @switch_search) %>');