From d3ba23bc64d1a64f033017056dbd7fd0dc164674 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 29 Jan 2016 15:37:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=9A=84=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 11 +++++ app/controllers/homework_common_controller.rb | 6 ++- .../_user_homework_search_list.html.erb | 46 +++++++++++++++++++ app/views/courses/homework_search.js.erb | 5 ++ .../_homework_search_form.html.erb | 6 +++ app/views/homework_common/index.html.erb | 5 +- app/views/users/_user_homework_list.html.erb | 4 +- config/routes.rb | 1 + 8 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 app/views/courses/_user_homework_search_list.html.erb create mode 100644 app/views/courses/homework_search.js.erb create mode 100644 app/views/homework_common/_homework_search_form.html.erb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0961f2480..97dacb178 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -907,6 +907,17 @@ class CoursesController < ApplicationController return 404 end end + #搜索作业 + def homework_search + @search = "%#{params[:search].strip.downcase}%" + @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) + @page = params[:page] ? params[:page].to_i + 1 : 0 + if @is_teacher + @homeworks = @course.homework_commons.where("name like '%#{@search}%'").order("created_at desc").limit(10).offset(@page * 10) + else + @homeworks = @course.homework_commons.where("name like '%#{@search}%' and publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) + end + end private def update_quotes attachment diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index d345fba5f..398b385a4 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -15,8 +15,12 @@ class HomeworkCommonController < ApplicationController @new_homework.homework_detail_manual = HomeworkDetailManual.new @new_homework.course = @course @page = params[:page] ? params[:page].to_i + 1 : 0 - @homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) + if @is_teacher + @homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) + else + @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) + end @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) @is_new = params[:is_new] diff --git a/app/views/courses/_user_homework_search_list.html.erb b/app/views/courses/_user_homework_search_list.html.erb new file mode 100644 index 000000000..585d8761a --- /dev/null +++ b/app/views/courses/_user_homework_search_list.html.erb @@ -0,0 +1,46 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true, prettify: false, init_activity: true) %> +<% end %> + + +
+ <% homework_commons.each do |homework_common|%> + + <%= render :partial => 'users/user_homework_detail', :locals => {:homework_common => homework_common,:is_in_course => is_in_course} %> + <% end%> + <% if homework_commons.count == 10%> + <%= link_to "点击展开更多",homework_search_course_path(course_id,:page => page,:search=>search),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%> + <% end%> +
\ No newline at end of file diff --git a/app/views/courses/homework_search.js.erb b/app/views/courses/homework_search.js.erb new file mode 100644 index 000000000..3c644ad9e --- /dev/null +++ b/app/views/courses/homework_search.js.erb @@ -0,0 +1,5 @@ +<% if @page == 0 %> + $("#user_homework_list").replaceWith("<%= escape_javascript( render :partial => 'courses/user_homework_search_list',:locals => {:homework_commons => @homeworks, :page => @page, :is_in_course => 1,:course_id => @course.id,:search=>@search} )%>"); +<% else %> + $("#user_show_more_homework").replaceWith("<%= escape_javascript( render :partial => 'courses/user_homework_search_list',:locals => {:homework_commons => @homeworks, :page => @page, :is_in_course => 1,:course_id => @course.id,:search=>@search} )%>"); +<% end %> \ No newline at end of file diff --git a/app/views/homework_common/_homework_search_form.html.erb b/app/views/homework_common/_homework_search_form.html.erb new file mode 100644 index 000000000..aa3eef59e --- /dev/null +++ b/app/views/homework_common/_homework_search_form.html.erb @@ -0,0 +1,6 @@ +<%= form_tag( url_for(:controller => 'courses',:action => 'homework_search',:id=>course.id), + :remote=>true ,:method => 'get',:class=>'resourcesSearchloadBox',:id=>'resource_search_form') do %> + + <%= submit_tag '',:class=>'homepageSearchIcon',:onfocus=>'this.blur();',:style=>'border-style:none' %> + +<% end %> \ No newline at end of file diff --git a/app/views/homework_common/index.html.erb b/app/views/homework_common/index.html.erb index bc960154e..5c91a37fc 100644 --- a/app/views/homework_common/index.html.erb +++ b/app/views/homework_common/index.html.erb @@ -36,6 +36,9 @@
作业
+
+ <%= render :partial => 'homework_search_form',:locals => {:course=>@course} %> +
@@ -50,8 +53,8 @@ <% end%>
<% end%> - <%= render :partial => 'users/user_homework_list', :locals => {:homework_commons => @homeworks,:page => 0,:is_in_course => 1,:course_id => @course.id} %> +
diff --git a/app/views/users/_user_homework_list.html.erb b/app/views/users/_user_homework_list.html.erb index 36f823a9a..28544fbf3 100644 --- a/app/views/users/_user_homework_list.html.erb +++ b/app/views/users/_user_homework_list.html.erb @@ -14,6 +14,7 @@ .homepagePostReplyInputContainer .ke-inline-block {display: none;} .homepagePostReplyInputContainer .ke-container {float: left;} +
<% homework_commons.each do |homework_common|%>