From 2db32cd8b2b05365c7ba51933561aca85dc08316 Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 6 Aug 2014 19:37:43 +0800 Subject: [PATCH] seach for backend --- app/controllers/admin/announcements_controller.rb | 8 ++++++++ app/views/admin/announcements/index.html.erb | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index c1d2a0f..f3666aa 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -16,6 +16,14 @@ class Admin::AnnouncementsController < OrbitAdminController @table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified] @bulletins = Bulletin.where(:is_preview.in=>[false,nil]).order_by(sort).with_categories(filters("category")).with_tags(filters("tag")).with_status(filters("status")).page(params[:page]).per(10) + + if params[:keywords].present? + key_string = params[:keywords] + key_string = key_string.strip.nil? ? key_string : key_string.strip + keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/) + regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")}) + @bulletins = @bulletins.any_of({:title=>regex}).page(params[:page]).per(10) + end if request.xhr? render :partial => "index" diff --git a/app/views/admin/announcements/index.html.erb b/app/views/admin/announcements/index.html.erb index 5606225..0c75748 100644 --- a/app/views/admin/announcements/index.html.erb +++ b/app/views/admin/announcements/index.html.erb @@ -1,5 +1,4 @@ -<%= render_filter @filter_fields %> - +<%= render_filter @filter_fields, "index_table" %> <%= render 'index'%> @@ -8,4 +7,5 @@ \ No newline at end of file