修改搜索功能,页面跳转

This commit is contained in:
huang 2016-03-04 16:05:58 +08:00
parent dfddb30ca3
commit bbbf13084e
4 changed files with 93 additions and 37 deletions

View File

@ -2358,27 +2358,55 @@ class UsersController < ApplicationController
end
end
def import_resources_search
search = "%#{params[:search].strip.downcase}%"
# 别人的资源库是没有权限去看的
if User.current.id.to_i != params[:id].to_i
render_403
return
end
user_course_ids = User.current.courses.map { |c| c.id}
user_project_ids = User.current.projects.map {|p| p.id}
# user_org_ids = User.current.organizations.map {|o| o.id}
if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
user_course_ids = User.current.courses.map { |c| c.id}
user_project_ids = User.current.projects.map {|p| p.id}
# 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")
elsif params[:type] == "6" # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources(user_course_ids, user_project_ids)
end
@type = params[:type]
@limit = 10
@is_remote = true
@atta_count = @attachments.count
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
@offset ||= @atta_pages.offset
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments,10
respond_to do |format|
format.js
format.html {render :layout => 'new_base'}
end
end
# 内容导入到对象中
def import_into_container
# attachments = Attachment.where("id in (#{params[:checkbox1].join(',')})")
# if params[:mul_type] == "Project"
#
# elsif params[:mul_type] == "Course"
# Attachment.create(:container_id => params[:mul_id], :container_type => "Course", :name => attachment.name)
# elsif params[:mul_type] == "SubfieldFile"
# end
send_ids = params[:checkbox1]
# mul_id为当前课程id、项目id、组织id的多种形态
mul_id = params[:mul_id]
if params[:mul_type] == "Course"
mul_container = Course.find(mul_id)
elsif params[:mul_type] == "Project"
mul_container = Project.find(mul_id)
elsif params[:mul_type] == "SubfieldFile"
mul_container = OrgSubfield.find(mul_id)
end
unless params[:checkbox1].blank?
send_ids = params[:checkbox1]
# mul_id为当前课程id、项目id、组织id的多种形态
mul_id = params[:mul_id]
if params[:mul_type] == "Course"
mul_container = Course.find(mul_id)
elsif params[:mul_type] == "Project"
mul_container = Project.find(mul_id)
elsif params[:mul_type] == "SubfieldFile"
mul_container = OrgSubfield.find(mul_id)
end
send_ids.each do |send_id|
ori = Attachment.find_by_id(send_id)
# 如果该附件已经存课程中,则只更新附件创建时间
@ -2408,11 +2436,11 @@ class UsersController < ApplicationController
respond_to do |format|
format.html {
if params[:mul_type] == "Course"
redirect_to course_files_url(mul_container)
redirect_to course_files_url(mul_container) unless mul_container.nil?
elsif params[:mul_type] == "Project"
redirect_to project_files_url(mul_container)
redirect_to project_files_url(mul_container) unless mul_container.nil?
elsif params[:mul_type] == "SubfieldFile"
redirect_to org_subfield_files_url(mul_container)
redirect_to org_subfield_files_url(mul_container) unless mul_container.nil?
end
}
end
@ -2421,12 +2449,13 @@ class UsersController < ApplicationController
# 根据资源关键字进行搜索
def resource_search
search = "%#{params[:search].strip.downcase}%"
user_course_ids = User.current.courses.map { |c| c.id}
user_project_ids = User.current.projects.map {|p| p.id}
# user_org_ids = User.current.organizations.map {|o| o.id}
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
if User.current.id.to_i == params[:id].to_i
user_course_ids = User.current.courses.map { |c| c.id}
user_project_ids = User.current.projects.map {|p| p.id}
# user_org_ids = User.current.organizations.map {|o| o.id}
@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')) "+
@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")
else
@ -2466,8 +2495,9 @@ class UsersController < ApplicationController
end
elsif params[:type] == "6" #全部资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = Attachment.where("((is_public =1 and is_publish = 1 and container_id is not null)" +
"or (author_id = #{params[:id]} and is_publish = 0)) and (filename like :p) ", :p => search).order("created_on desc")
@attachments = 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
@type = params[:type]
@limit = 25

View File

@ -1,8 +1,8 @@
<script>
$(document).ready(function(){
$(".subjectChoose").click(function(){
$(".subjectChoose").removeClass("chooseActive");
$(this).addClass("chooseActive");
$(".subject-choose").click(function(){
$(".subject-choose").removeClass("choose-active");
$(this).addClass("choose-active");
});
$(".popupClose").click(function(){
$(".popupWrap").hide();
@ -12,16 +12,16 @@
<div class="f16 fb fontBlue mb10">选用资源库中的资源</div>
<div class="subjectList fl mr10">
<% if !params[:course_id].nil? %>
<a href="<%= import_resources_user_path(User.current, :type => '6', :course_id => params[:course_id]) %>" class="subjectChoose chooseActive fl" data-remote="true">公共资源</a>
<a href="<%= import_resources_user_path(User.current, :type => '1', :course_id => params[:course_id]) %>" class="subjectChoose fl" data-remote="true">我的资源</a>
<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 => '1', :course_id => params[:course_id]) %>" class="subject-choose fl" data-remote="true">我的资源</a>
<% elsif !params[:project_id].nil? %>
<a href="<%= import_resources_user_path(User.current, :type => '6', :project_id => params[:project_id]) %>" class="subjectChoose chooseActive fl" data-remote="true">公共资源</a>
<a href="<%= import_resources_user_path(User.current, :type => '1', :project_id => params[:project_id]) %>" class="subjectChoose fl" data-remote="true">我的资源</a>
<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 => '1', :project_id => params[:project_id]) %>" class="subject-choose fl" data-remote="true">我的资源</a>
<% elsif !params[:subfield_file_id].nil? %>
<a href="<%= import_resources_user_path(User.current, :type => '6', :subfield_file_id => params[:subfield_file_id]) %>" class="subjectChoose chooseActive fl" data-remote="true">公共资源</a>
<a href="<%= import_resources_user_path(User.current, :type => '1', :subfield_file_id => params[:subfield_file_id]) %>" class="subjectChoose fl" data-remote="true">我的资源</a>
<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 => '1', :subfield_file_id => params[:subfield_file_id]) %>" class="subject-choose fl" data-remote="true">我的资源</a>
<% end %>
<%= form_tag( url_for(:controller => 'users', :action => 'resource_search', :id => User.current.id),
<%= 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 %>
<input type="text" name="search" placeholder="输入资源关键词进行搜索" class="subjectSearch fr" />
<%= hidden_field_tag(:type,type.nil? ? 1 : type) %>

View File

@ -0,0 +1,25 @@
//$("#resources_list").html('<%#= escape_javascript( render :partial => 'users/import_resource_info' ,:locals=>{ :attachments => @attachments, :type => @type})%>');
//$("#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);
<% if params[:project_id] %>
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :project_id => params[:project_id]} ) %>');
<% elsif params[:course_id] %>
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :course_id => params[:course_id]} ) %>');
<% elsif params[:subfield_file_id] %>
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :subfield_file_id => params[:subfield_file_id]} ) %>');
<% end %>
showModal('ajax-modal', '615px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal()' style='margin-left: 580px;'><img src='/images/bid/close.png' width='26px' height='26px' /></a>");
<% if params[:project_id] %>
$('#ajax-modal').parent().css("top","10%").css("left","34%").css("border","3px solid #269ac9");
<% else %>
$('#ajax-modal').parent().css("top","20%").css("left","42%").css("border","3px solid #269ac9");
<% end %>
$('#ajax-modal').parent().addClass("popbox_polls");

View File

@ -538,6 +538,7 @@ RedmineApp::Application.routes.draw do
get 'edit_brief_introduction'
get "user_resource"
get "import_resources"
get "import_resources_search"
post "import_into_container"
get "resource_search"
post "user_resource_create"