From e2b132c21da25f6897afb0fde556c34af5405082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Sun, 11 Aug 2024 10:17:53 +0800 Subject: [PATCH] Add is_searchable field. --- app/controllers/universal_tables_controller.rb | 10 ++++++++-- app/models/table_column.rb | 18 ++++++++++++++++++ .../admin/universal_tables/_column.html.erb | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/controllers/universal_tables_controller.rb b/app/controllers/universal_tables_controller.rb index 5f8dd49..e5ce1b4 100644 --- a/app/controllers/universal_tables_controller.rb +++ b/app/controllers/universal_tables_controller.rb @@ -3,7 +3,8 @@ class UniversalTablesController < ApplicationController def index params = OrbitHelper.params table = UTable.where(:category_id => OrbitHelper.page_categories.first).first rescue nil - page = Page.where(:page_id => params[:page_id]).first + page = OrbitHelper.page rescue Page.where(:page_id => params[:page_id]).first + searchable_columns = [] if !table.nil? reset = "hide" csrf_value = (0...46).map { ('a'..'z').to_a[rand(26)] }.join @@ -76,7 +77,7 @@ class UniversalTablesController < ApplicationController title_class = title_class + "no-sort" if sort == "sort" title_class = title_class + " no-search" if search == "hide" - { + col = { "title" => tc.title, "type" => tc.type, "key" => field_key, @@ -87,6 +88,10 @@ class UniversalTablesController < ApplicationController "sort-url" => sort_url, "title-class" => title_class } + if tc.is_searchable + searchable_columns << col + end + col end tablecolumns = table.table_columns.where(:display_in_index => true).asc(:order) rows = [] @@ -128,6 +133,7 @@ class UniversalTablesController < ApplicationController reset = "" end { + "searchable-columns" => searchable_columns, "head-columns" => table_heads, "rows" => rows, "total_pages" => total_pages, diff --git a/app/models/table_column.rb b/app/models/table_column.rb index 362c501..81e720e 100644 --- a/app/models/table_column.rb +++ b/app/models/table_column.rb @@ -8,6 +8,7 @@ class TableColumn field :type field :date_format, default: "YYYY/MM/DD" field :is_link_to_show, type: Boolean, default: false + field :is_searchable, type: Boolean field :order, type: Integer field :make_categorizable, type: Boolean, default: false field :default_ordered_field, type: Boolean, default: false @@ -36,4 +37,21 @@ class TableColumn {period_from: direction,period_to: direction} end end + + def is_searchable + tmp = self[:is_searchable] + if tmp.nil? + case self.type + when "date", "period","image" + tmp = false + else + tmp = self.display_in_index + end + end + tmp + end + + def self.filter_searchable + self.any_of({is_searchable: true}, {is_searchable:nil, display_in_index: true, :type.nin=> ["date", "period","image"]}) + end end \ No newline at end of file diff --git a/app/views/admin/universal_tables/_column.html.erb b/app/views/admin/universal_tables/_column.html.erb index 11e72f3..9befaa4 100644 --- a/app/views/admin/universal_tables/_column.html.erb +++ b/app/views/admin/universal_tables/_column.html.erb @@ -77,6 +77,9 @@ + <% select_values = UTable::DATE_FORMATS.collect{|ft| [ft.upcase,ft]} %>