Add is_searchable field.

This commit is contained in:
邱博亞 2024-08-11 10:17:53 +08:00
parent 184c1384c7
commit e2b132c21d
3 changed files with 29 additions and 2 deletions

View File

@ -3,7 +3,8 @@ class UniversalTablesController < ApplicationController
def index def index
params = OrbitHelper.params params = OrbitHelper.params
table = UTable.where(:category_id => OrbitHelper.page_categories.first).first rescue nil 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? if !table.nil?
reset = "hide" reset = "hide"
csrf_value = (0...46).map { ('a'..'z').to_a[rand(26)] }.join 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-sort" if sort == "sort"
title_class = title_class + " no-search" if search == "hide" title_class = title_class + " no-search" if search == "hide"
{ col = {
"title" => tc.title, "title" => tc.title,
"type" => tc.type, "type" => tc.type,
"key" => field_key, "key" => field_key,
@ -87,6 +88,10 @@ class UniversalTablesController < ApplicationController
"sort-url" => sort_url, "sort-url" => sort_url,
"title-class" => title_class "title-class" => title_class
} }
if tc.is_searchable
searchable_columns << col
end
col
end end
tablecolumns = table.table_columns.where(:display_in_index => true).asc(:order) tablecolumns = table.table_columns.where(:display_in_index => true).asc(:order)
rows = [] rows = []
@ -128,6 +133,7 @@ class UniversalTablesController < ApplicationController
reset = "" reset = ""
end end
{ {
"searchable-columns" => searchable_columns,
"head-columns" => table_heads, "head-columns" => table_heads,
"rows" => rows, "rows" => rows,
"total_pages" => total_pages, "total_pages" => total_pages,

View File

@ -8,6 +8,7 @@ class TableColumn
field :type field :type
field :date_format, default: "YYYY/MM/DD" field :date_format, default: "YYYY/MM/DD"
field :is_link_to_show, type: Boolean, default: false field :is_link_to_show, type: Boolean, default: false
field :is_searchable, type: Boolean
field :order, type: Integer field :order, type: Integer
field :make_categorizable, type: Boolean, default: false field :make_categorizable, type: Boolean, default: false
field :default_ordered_field, type: Boolean, default: false field :default_ordered_field, type: Boolean, default: false
@ -36,4 +37,21 @@ class TableColumn
{period_from: direction,period_to: direction} {period_from: direction,period_to: direction}
end end
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 end

View File

@ -77,6 +77,9 @@
<label class="checkbox inline attributes-checkbox"> <label class="checkbox inline attributes-checkbox">
<%= f.check_box :make_categorizable %> Categorizable <%= f.check_box :make_categorizable %> Categorizable
</label> </label>
<label class="checkbox inline attributes-checkbox ">
<%= f.check_box :is_searchable %> Searchable
</label>
</span> </span>
<% select_values = UTable::DATE_FORMATS.collect{|ft| [ft.upcase,ft]} %> <% select_values = UTable::DATE_FORMATS.collect{|ft| [ft.upcase,ft]} %>
<label class="checkbox date_format inline attributes-checkbox <%= column.type == "date" || column.type == "period" ? "" : "hide" %>"> <label class="checkbox date_format inline attributes-checkbox <%= column.type == "date" || column.type == "period" ? "" : "hide" %>">