公共资源相关功能

This commit is contained in:
huang 2016-03-04 18:22:22 +08:00
parent 91b8a81b9d
commit ae40a4ea61
5 changed files with 83 additions and 24 deletions

View File

@ -2273,9 +2273,19 @@ class UsersController < ApplicationController
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") 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 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")
end
# 获取我的项目资源 # 获取我的项目资源
def get_project_resources author_id, user_project_ids def get_project_resources author_id, user_project_ids
attchments = Attachment.where("author_id = #{author_id} and container_type = 'Project'").order("created_on desc") 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")
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")
end end
# 获取我上传的附件 # 获取我上传的附件
@ -2283,11 +2293,21 @@ class UsersController < ApplicationController
attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc")
end end
# 获取公共资源中我上传的附件
def get_attch_resources_public
attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc")
end
# 获取我的用户类型资源 # 获取我的用户类型资源
def get_principal_resources author_id def get_principal_resources author_id
attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc") attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc")
end end
# 获取我的用户类型资源
def get_principal_resources_public
attchments = Attachment.where("container_type = 'Principal'").order("created_on desc")
end
# 资源库 分为全部 课程资源 项目资源 附件 # 资源库 分为全部 课程资源 项目资源 附件
def user_resource def user_resource
# 别人的资源库是没有权限去看的 # 别人的资源库是没有权限去看的
@ -2300,7 +2320,18 @@ class UsersController < ApplicationController
# 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") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) if params[:status] == 2
@attachments = get_course_resources(params[:id], user_course_ids)
elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids)
elsif params[:status] == "4"
@attachments = get_attch_resources params[:id]
elsif params[:status] == "5"
@attachments = get_principal_resources params[:id]
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
end
elsif params[:type] == "2" # 课程资源 elsif params[:type] == "2" # 课程资源
@attachments = get_course_resources(params[:id], user_course_ids) @attachments = get_course_resources(params[:id], user_course_ids)
elsif params[:type] == "3" # 项目资源 elsif params[:type] == "3" # 项目资源
@ -2310,9 +2341,20 @@ class UsersController < ApplicationController
elsif params[:type] == "5" #用户资源 elsif params[:type] == "5" #用户资源
@attachments = get_principal_resources params[:id] @attachments = get_principal_resources params[:id]
elsif params[:type] == "6" # 公共资源 elsif params[:type] == "6" # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源 if params[:status] == "2"
@attachments = get_public_resources(user_course_ids, user_project_ids) @attachments = get_course_resources_public( user_course_ids)
elsif params[:status] == "3"
@attachments = get_project_resources_public(user_project_ids)
elsif params[:status] == "4"
@attachments = get_attch_resources_public
elsif params[:status] == "5"
@attachments = get_principal_resources_public
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources(user_course_ids, user_project_ids)
end
end end
@status = params[:status]
@type = params[:type] @type = params[:type]
@limit = 25 @limit = 25
@is_remote = true @is_remote = true

View File

@ -1,5 +1,10 @@
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
<% if type == "1" %>
$("#my_resources_choose").addClass("choose-active");
$("#public_resources_choose").removeClass("choose-active");
<% end %>
$(".subject-choose").click(function(){ $(".subject-choose").click(function(){
$(".subject-choose").removeClass("choose-active"); $(".subject-choose").removeClass("choose-active");
$(this).addClass("choose-active"); $(this).addClass("choose-active");
@ -12,14 +17,14 @@
<div class="f16 fb fontBlue mb10">选用资源库中的资源</div> <div class="f16 fb fontBlue mb10">选用资源库中的资源</div>
<div class="subjectList fl mr10"> <div class="subjectList fl mr10">
<% if !params[:course_id].nil? %> <% if !params[:course_id].nil? %>
<a href="<%= import_resources_user_path(User.current, :type => '6', :course_id => params[:course_id]) %>" class="subject-choose choose-active fl" data-remote="true">公共资源</a> <a href="<%= import_resources_user_path(User.current, :type => '6', :course_id => params[:course_id]) %>" id="public_resources_choose" class="subject-choose choose-active fl" data-remote="true">公共资源</a>
<a href="<%= import_resources_user_path(User.current, :type => '1', :course_id => params[:course_id]) %>" class="subject-choose fl" data-remote="true">我的资源</a> <a href="<%= import_resources_user_path(User.current, :type => '1', :course_id => params[:course_id]) %>" id="my_resources_choose" class="subject-choose fl" data-remote="true">我的资源</a>
<% elsif !params[:project_id].nil? %> <% elsif !params[:project_id].nil? %>
<a href="<%= import_resources_user_path(User.current, :type => '6', :project_id => params[:project_id]) %>" class="subject-choose choose-active fl" data-remote="true">公共资源</a> <a href="<%= import_resources_user_path(User.current, :type => '6', :project_id => params[:project_id]) %>" id="public_resources_choose" class="subject-choose choose-active fl" data-remote="true">公共资源</a>
<a href="<%= import_resources_user_path(User.current, :type => '1', :project_id => params[:project_id]) %>" class="subject-choose fl" data-remote="true">我的资源</a> <a href="<%= import_resources_user_path(User.current, :type => '1', :project_id => params[:project_id]) %>" id="my_resources_choose" class="subject-choose fl" data-remote="true">我的资源</a>
<% elsif !params[:subfield_file_id].nil? %> <% elsif !params[:subfield_file_id].nil? %>
<a href="<%= import_resources_user_path(User.current, :type => '6', :subfield_file_id => params[:subfield_file_id]) %>" class="subject-choose choose-active fl" data-remote="true">公共资源</a> <a href="<%= import_resources_user_path(User.current, :type => '6', :subfield_file_id => params[:subfield_file_id]) %>" id="public_resources_choose" class="subject-choose choose-active fl" data-remote="true">公共资源</a>
<a href="<%= import_resources_user_path(User.current, :type => '1', :subfield_file_id => params[:subfield_file_id]) %>" class="subject-choose fl" data-remote="true">我的资源</a> <a href="<%= import_resources_user_path(User.current, :type => '1', :subfield_file_id => params[:subfield_file_id]) %>" id="my_resources_choose" class="subject-choose fl" data-remote="true">我的资源</a>
<% end %> <% end %>
<%= form_tag( url_for(:controller => 'users', :action => 'import_resources_search', :id => User.current.id, :type => 1), <%= form_tag( url_for(:controller => 'users', :action => 'import_resources_search', :id => User.current.id, :type => 1),
:remote => true , :method => 'get', :id => 'resource_search_form') do %> :remote => true , :method => 'get', :id => 'resource_search_form') do %>
@ -50,7 +55,7 @@
</label> </label>
</li> </li>
<li class="subjectType fl"><%= get_resource_type(attach.container_type)%></li> <li class="subjectType fl"><%= get_resource_type(attach.container_type)%></li>
<li class="subjectCount fl"><%= number_to_human_size(attach.filesize) %></li> <li class="subjectCount fl hidden"><%= number_to_human_size(attach.filesize) %></li>
<li class="subjectPublisher fl"><%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %></li> <li class="subjectPublisher fl"><%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %></li>
<li class="fl subjectDate"><%= format_date(attach.created_on) %></li> <li class="fl subjectDate"><%= format_date(attach.created_on) %></li>
</ul> </ul>

View File

@ -1,9 +1,9 @@
<% if params[:project_id] %> <% 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]} ) %>'); $('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :project_id => params[:project_id]} ) %>');
<% elsif params[:course_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]} ) %>'); $('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :course_id => params[:course_id]} ) %>');
<% elsif params[:subfield_file_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]} ) %>'); $('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :subfield_file_id => params[:subfield_file_id]} ) %>');
<% end %> <% end %>
showModal('ajax-modal', '615px'); showModal('ajax-modal', '615px');
$('#ajax-modal').siblings().remove(); $('#ajax-modal').siblings().remove();

View File

@ -12,7 +12,7 @@
} }
$(document).ready(function(){ $(document).ready(function(){
$(".resource-switch").click(function(){ $(".resource-switch").click(function(){
$(".resource-switch").children().removeClass("resource-tab-active"); $(".resource-switch").children().removeClass("resource-tab-active");
$(this).children().addClass("resource-tab-active"); $(this).children().addClass("resource-tab-active");
}); });
@ -69,14 +69,13 @@
} }
} }
</script> </script>
<div> <div>
<ul class="resource-banner"> <ul class="resource-banner">
<li class="fl resource-switch"> <li class="fl resource-switch">
<a href="<%= user_resource_user_path(@user, :type => '6') %>" class="resource-tab resource-tab-active" data-remote="true">公共资源</a> <a href="<%= user_resource_user_path(@user, :type => '6', :status => @status) %>" class="resource-tab resource-tab-active" id="public_resource_list" data-remote="true">公共资源</a>
</li> </li>
<li class="fl resource-switch"> <li class="fl resource-switch">
<a href="<%= user_resource_user_path(@user, :type => '1') %>" class="resource-tab" data-remote="true">我的资源</a> <a href="<%= user_resource_user_path(@user, :type => '1', :status => @status) %>" class="resource-tab" id="my_resource_list" data-remote="true">我的资源</a>
</li> </li>
<li class="fl w770 border-bottom h34">&nbsp;</li> <li class="fl w770 border-bottom h34">&nbsp;</li>
<li class="fr resource-banner-li border-bottom h34"> <li class="fr resource-banner-li border-bottom h34">
@ -84,19 +83,23 @@
<li class="resourcesSelected"><a href="javascript:void(0);" class="resourcesIcon"></a> <li class="resourcesSelected"><a href="javascript:void(0);" class="resourcesIcon"></a>
<ul class="resourcesType"> <ul class="resourcesType">
<li> <li>
<%= link_to '全部' ,user_resource_user_path(:id => @user.id, :type => 1), :remote => true, :method => 'get', :class => 'resourcesTypeAll resourcesGrey' %> <a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 1)%>" id="resource_type_all" class="resourcesTypeAll resourcesGrey" data-method="get" data-remote="true">全部 </a>
</li> </li>
<li> <li>
<%= link_to '课程资源' ,user_resource_user_path(:id => @user.id, :type => 2), :remote => true, :method => 'get', :class=> 'homepagePostTypeAssignment postTypeGrey' %> <a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 2) %>" id="resource_type_course" class="homepagePostTypeAssignment postTypeGrey'" data-method="get" data-remote="true">课程资源 </a>
<%#= link_to '课程资源' ,user_resource_user_path(:id => @user.id, :type => 2), id="resource_type_course", :remote => true, :method => 'get', :class=> 'homepagePostTypeAssignment postTypeGrey' %>
</li> </li>
<li> <li>
<%= link_to '项目资源' ,user_resource_user_path(:id => @user.id, :type => 3), :remote => true, :method => 'get', :class => 'homepagePostTypeQuiz postTypeGrey' %> <a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 3) %>" id="resource_type_project" class="homepagePostTypeQuiz postTypeGrey" data-method="get" data-remote="true">项目资源 </a>
<%#= link_to '项目资源' ,user_resource_user_path(:id => @user.id, :type => 3), id="resource_type_project", :remote => true, :method => 'get', :class => 'homepagePostTypeQuiz postTypeGrey' %>
</li> </li>
<li> <li>
<%= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5),:remote=>true,:method => 'get', :class=>'resourcesTypeUser resourcesGrey' %> <a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 5) %>" id="resource_type_user" class="resourcesTypeUser resourcesGrey" data-method="get" data-remote="true">用户资源 </a>
<%#= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5), id="resource_type_user", :remote=>true,:method => 'get', :class=>'resourcesTypeUser resourcesGrey' %>
</li> </li>
<li> <li>
<%= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4),:remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %> <a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 4) %>" id="resource_type_file" class="resourcesTypeAtt resourcesGrey" data-method="get" data-remote="true">附件 </a>
<%#= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4), id="resource_type_file", :remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %>
</li> </li>
</ul> </ul>
</li> </li>

View File

@ -3,4 +3,13 @@ $("#resources_list").html('<%= escape_javascript( render :partial => 'resources_
$("#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_count").html(0); $("#res_count").html(0);
$("#checkboxAll").attr('checked',false); $("#checkboxAll").attr('checked',false);
$("#res_all_count").html(<%= @atta_count%>); $("#res_all_count").html(<%= @atta_count %>);
$("#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','<%= 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_project").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 3) %>');
$("#resource_type_user").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 5) %>');
$("#resource_type_file").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 4) %>');