From a69769c5b710050469067ac61c741cd1710a3cdc Mon Sep 17 00:00:00 2001 From: manson Date: Thu, 7 Aug 2014 18:46:24 +0800 Subject: [PATCH] add search for backend index --- .../admin/archive_files_controller.rb | 40 ++++++------- app/controllers/archives_controller.rb | 1 - app/views/admin/archive_files/_index.html.erb | 58 +++++++++---------- app/views/admin/archive_files/index.html.erb | 7 +-- 4 files changed, 48 insertions(+), 58 deletions(-) diff --git a/app/controllers/admin/archive_files_controller.rb b/app/controllers/admin/archive_files_controller.rb index fa0d9a3..1bf12bb 100644 --- a/app/controllers/admin/archive_files_controller.rb +++ b/app/controllers/admin/archive_files_controller.rb @@ -1,29 +1,25 @@ class Admin::ArchiveFilesController < OrbitAdminController def index - @table_fields = [:status, :category, :title] + @table_fields = [:status, :category, :title, :update_at,:last_modified] @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) - @archives = ArchiveFile.order_by(sort).with_categories(categories).with_tags(tags).with_status(status).page(params[:page]).per(10) + @archives = ArchiveFile.order_by(sort) + .with_categories(filters("category")) + .with_tags(filters("tag")) + .with_status(filters("status")) - if request.xhr? - render :partial => "index" - end + @archives = search_data(@archives,[:title]).page(params[:page]).per(10) + + render :partial => "index" if request.xhr? end def new - @archive_file = ArchiveFile.new - @tags = @module_app.tags - @categories = @module_app.categories + @archive_file = ArchiveFile.new + @tags = @module_app.tags + @categories = @module_app.categories end def edit @@ -36,7 +32,7 @@ class Admin::ArchiveFilesController < OrbitAdminController end end - def create + def create @archive_file = ArchiveFile.new(archive_vars) @archive_file.create_user_id = current_user.id @archive_file.update_user_id = current_user.id @@ -57,7 +53,7 @@ class Admin::ArchiveFilesController < OrbitAdminController # PUT /archive_files/1.xml def update @archive_file = ArchiveFile.find(params[:id]) - + @archive_file.update_user_id = current_user.id respond_to do |format| @@ -80,12 +76,12 @@ class Admin::ArchiveFilesController < OrbitAdminController private def archive_vars - params[:archive_file][:tags] ||=[] - params.require(:archive_file).permit! + params[:archive_file][:tags] ||=[] + params.require(:archive_file).permit! end def setup_vars - @module_app = ModuleApp.where(:key => "archive").first + @module_app = ModuleApp.where(:key => "archive").first end def sort unless params[:sort].blank? @@ -100,7 +96,7 @@ class Admin::ArchiveFilesController < OrbitAdminController @sort = {:title=>params[:order]} when "last_modified" @sort = {:update_user_id=>params[:order]} - end + end else @sort = {:created_at=>'desc'} end diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index a81c3aa..a67fd25 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -42,7 +42,6 @@ class ArchivesController < ApplicationController "url_to_edit" => url_to_edit } end - { "categories" => cats } diff --git a/app/views/admin/archive_files/_index.html.erb b/app/views/admin/archive_files/_index.html.erb index 0fff8f6..18bd30a 100644 --- a/app/views/admin/archive_files/_index.html.erb +++ b/app/views/admin/archive_files/_index.html.erb @@ -3,36 +3,34 @@ - - - <% @table_fields.each do |f| %> - <%= thead(f) %> - <% end %> - - - - <% @archives.each do |archive| %> - - - - - - <% end %> - + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @archives.each do |archive| %> + + + + + + + + <% end %> +
- <%= archive.status_for_table %> - - <%= archive.category.title %> - - <%= archive.title %> -
- -
-
<%= archive.status_for_table %><%= archive.category.title %> + <%= archive.title %> +
+ +
+
<%= format_value archive.updated_at rescue nil %><%= User.find(archive.update_user_id).user_name rescue nil %>
<%= diff --git a/app/views/admin/archive_files/index.html.erb b/app/views/admin/archive_files/index.html.erb index aa621c6..dba461b 100644 --- a/app/views/admin/archive_files/index.html.erb +++ b/app/views/admin/archive_files/index.html.erb @@ -1,7 +1,4 @@ -<%= render_filter @filter_fields %> -
+<%= render_filter @filter_fields, "index_table" %> +
<%= render 'index'%>
-