From 5d7505fe217ae88ba3e52b5abb1ca6a287305c5a Mon Sep 17 00:00:00 2001 From: manson Date: Thu, 7 Aug 2014 18:47:37 +0800 Subject: [PATCH] add search for backend index --- app/controllers/admin/faqs_controller.rb | 47 ++++----------- app/views/admin/faqs/_index.html.erb | 74 ++++++++++++------------ app/views/admin/faqs/index.html.erb | 9 +-- 3 files changed, 52 insertions(+), 78 deletions(-) diff --git a/app/controllers/admin/faqs_controller.rb b/app/controllers/admin/faqs_controller.rb index d93acf9..1cf21a6 100644 --- a/app/controllers/admin/faqs_controller.rb +++ b/app/controllers/admin/faqs_controller.rb @@ -3,48 +3,23 @@ class Admin::FaqsController < OrbitAdminController before_filter :setup_vars def index - @table_fields = ["status","category","title","tags"] + @table_fields = [:status,:category,:title,:tags] @categories = @module_app.categories @tags = @module_app.tags - @filter_fields = { - :status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}], - :category=>@categories.map{|c| {:title=>c.title, :id=>c.id}}, - :tags=>@tags.map{|tag| {:title=>tag.name, :id=>tag.id}} - } - status = params[:filters][:status].blank? ? [] : params[:filters][:status] rescue [] - categories = params[:filters][:category].blank? ? [] : params[:filters][:category] rescue [] - tags = params[:filters][:tags].blank? ? [] : params[:filters][:tags] rescue [] + @filter_fields = filter_fields(@categories, @tags) - @qas = Qa.order_by(sort).with_categories(categories).with_tags(tags).with_status(status).page(params[:page]).per(10) + @qas = Qa.order_by(sort) + .with_categories(filters("category")) + .with_tags(filters("tag")) + .with_status(filters("status")) - if request.xhr? - render :partial => "index" - end + @qas = search_data(@qas,[:title]).page(params[:page]).per(10) + + render :partial => "index" if request.xhr? end - def sort - unless params[:sort].blank? - case params[:sort] - when "status" - @sort = [[:is_top, params[:order]], - [:is_hot, params[:order]], - [:is_hidden,params[:order]]] - when "category" - @sort = {:category_id=>params[:order]} - when "title" - @sort = {:title=>params[:order]} - when "last_modified" - @sort = {:update_user_id=>params[:order]} - end - else - @sort = {:created_at=>'desc'} - end - @sort - end - - def new - @qa = Qa.new + @qa = Qa.new @tags = @module_app.tags @categories = @module_app.categories respond_to do |format| @@ -87,7 +62,7 @@ class Admin::FaqsController < OrbitAdminController private def setup_vars - @module_app = ModuleApp.where(:key => "faq").first + @module_app = ModuleApp.where(:key => "faq").first end def create_params diff --git a/app/views/admin/faqs/_index.html.erb b/app/views/admin/faqs/_index.html.erb index 22e09f0..f343445 100644 --- a/app/views/admin/faqs/_index.html.erb +++ b/app/views/admin/faqs/_index.html.erb @@ -1,37 +1,39 @@ - - - <% @table_fields.each do |f| %> - <%= thead(f) %> - <% end %> - - - - <% @qas.each do |qa| %> - - - - - - - <% end %> - -
- <%= qa.status_for_table %> - - <%= qa.category.title %> - - <%= qa.title %> -
- -
-
- <% qa.tags.each do |tag| %> - <%= tag.name %> - <% end %> -
\ No newline at end of file + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @qas.each do |qa| %> + + <%= qa.status_for_table %> + <%= qa.category.title %> + + <%= qa.title %> +
+ +
+ + + <% qa.tags.each do |tag| %> + <%= tag.name %> + <% end %> + + + <% end %> + + + +<%= + content_tag :div, class: "bottomnav clearfix" do + content_tag :div, paginate(@qas), class: "pagination pagination-centered" + end +%> \ No newline at end of file diff --git a/app/views/admin/faqs/index.html.erb b/app/views/admin/faqs/index.html.erb index 851c4b7..3041cda 100644 --- a/app/views/admin/faqs/index.html.erb +++ b/app/views/admin/faqs/index.html.erb @@ -1,8 +1,5 @@ -<%= render_filter @filter_fields %> -
- <%= render 'index'%> +<%= render_filter @filter_fields, "index_table" %> +
+ <%= render 'index'%>
-