added filters and file and editor search
This commit is contained in:
parent
f00fe8a348
commit
77097850e0
|
|
@ -10,114 +10,115 @@ class UniversalTablesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_filtered
|
def export_filtered
|
||||||
table = UTable.where(:category_id => params[:cat]).first rescue nil
|
table = UTable.where(:category_id => params[:cat]).first rescue nil
|
||||||
page = Page.where(:page_id => params[:page_id]).first
|
page = Page.where(:page_id => params[:page_id]).first
|
||||||
return unless table
|
return unless table
|
||||||
|
|
||||||
host_url = Site.first.root_url
|
host_url = Site.first.root_url
|
||||||
host_url = request.protocol + request.host_with_port if host_url == "http://"
|
host_url = request.protocol + request.host_with_port if host_url == "http://"
|
||||||
|
|
||||||
@rows = []
|
@rows = []
|
||||||
@tablecolumns = []
|
@tablecolumns = []
|
||||||
|
|
||||||
# 處理 file 欄位雙欄輸出(連結與註解)
|
# 處理 file 欄位雙欄輸出(連結與註解)
|
||||||
table.table_columns.where(display_in_index: true).asc(:order).each do |column|
|
table.table_columns.where(display_in_index: true).asc(:order).each do |column|
|
||||||
if column.type == "file"
|
if column.type == "file"
|
||||||
@tablecolumns << column
|
@tablecolumns << column
|
||||||
@tablecolumns << column.dup.tap { |c| c.define_singleton_method(:_file_title_column?) { true } }
|
@tablecolumns << column.dup.tap { |c| c.define_singleton_method(:_file_title_column?) { true } }
|
||||||
else
|
else
|
||||||
@tablecolumns << column
|
@tablecolumns << column
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
entries = get_entries(params, table, page, false)
|
entries = get_entries(params, table, page, false)
|
||||||
|
|
||||||
entries.each do |te|
|
entries.each do |te|
|
||||||
cols = []
|
cols = []
|
||||||
|
|
||||||
@tablecolumns.each do |column|
|
@tablecolumns.each do |column|
|
||||||
# 跳過副註解欄(由主 file 欄處理)
|
# 跳過副註解欄(由主 file 欄處理)
|
||||||
if column.respond_to?(:_file_title_column?) && column._file_title_column?
|
if column.respond_to?(:_file_title_column?) && column._file_title_column?
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
ce = te.column_entries.where(table_column_id: column.id).first rescue nil
|
ce = te.column_entries.where(table_column_id: column.id).first rescue nil
|
||||||
|
|
||||||
if ce.present?
|
if ce.present?
|
||||||
case column.type
|
case column.type
|
||||||
when "text"
|
when "text"
|
||||||
cols << { "text" => ce.text.to_s }
|
cols << { "text" => ce.text.to_s }
|
||||||
|
|
||||||
when "integer"
|
when "integer"
|
||||||
cols << { "text" => ce.number.to_s }
|
cols << { "text" => ce.number.to_s }
|
||||||
|
|
||||||
when "editor"
|
when "editor"
|
||||||
cols << { "text" => ce.content.to_s }
|
cols << { "text" => ce.content.to_s }
|
||||||
|
|
||||||
when "date"
|
when "date"
|
||||||
cols << { "text" => format_date(ce.date, column.date_format).to_s }
|
cols << { "text" => format_date(ce.date, column.date_format).to_s }
|
||||||
|
|
||||||
when "period"
|
when "period"
|
||||||
from = format_date(ce.period_from, column.date_format)
|
from = format_date(ce.period_from, column.date_format)
|
||||||
to = format_date(ce.period_to, column.date_format)
|
to = format_date(ce.period_to, column.date_format)
|
||||||
text = from.blank? && to.present? ? to : "#{from} ~ #{to}"
|
text = from.blank? && to.present? ? to : "#{from} ~ #{to}"
|
||||||
cols << { "text" => text.to_s }
|
cols << { "text" => text.to_s }
|
||||||
|
|
||||||
when "image"
|
when "image"
|
||||||
text = ce.image&.thumb&.url ? (host_url + ce.image.thumb.url) : ""
|
text = ce.image&.thumb&.url ? (host_url + ce.image.thumb.url) : ""
|
||||||
cols << { "text" => text }
|
cols << { "text" => text }
|
||||||
|
|
||||||
when "file"
|
when "file"
|
||||||
file_links = []
|
file_links = []
|
||||||
file_titles = []
|
file_titles = []
|
||||||
locale = I18n.locale.to_s
|
locale = I18n.locale.to_s
|
||||||
|
|
||||||
ce.column_entry_files.desc(:sort_number).each do |entry_file|
|
ce.column_entry_files.desc(:sort_number).each do |entry_file|
|
||||||
next unless entry_file.choose_lang_display(locale)
|
next unless entry_file.choose_lang_display(locale)
|
||||||
|
|
||||||
file_links << (host_url + entry_file.get_link)
|
file_links << (host_url + entry_file.get_link)
|
||||||
|
|
||||||
title = if entry_file.respond_to?(:file_title_translations) && entry_file.file_title_translations.is_a?(Hash)
|
title = if entry_file.respond_to?(:file_title_translations) && entry_file.file_title_translations.is_a?(Hash)
|
||||||
entry_file.file_title_translations[locale]
|
entry_file.file_title_translations[locale]
|
||||||
elsif entry_file.file_title.is_a?(Hash)
|
elsif entry_file.file_title.is_a?(Hash)
|
||||||
entry_file.file_title[locale]
|
entry_file.file_title[locale]
|
||||||
else
|
else
|
||||||
entry_file.file_title
|
entry_file.file_title
|
||||||
end
|
end
|
||||||
|
|
||||||
title = entry_file.file.filename.to_s if title.blank?
|
title = entry_file.file.filename.to_s if title.blank?
|
||||||
file_titles << title
|
file_titles << title
|
||||||
end
|
end
|
||||||
|
|
||||||
cols << { "text" => file_links.join("\r\n") }
|
cols << { "text" => file_links.join("\r\n") }
|
||||||
cols << { "text" => file_titles.join("\r\n") }
|
cols << { "text" => file_titles.join("\r\n") }
|
||||||
|
|
||||||
else
|
else
|
||||||
cols << { "text" => "" }
|
cols << { "text" => "" }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if column.type == "file"
|
if column.type == "file"
|
||||||
cols << { "text" => "" }
|
cols << { "text" => "" }
|
||||||
cols << { "text" => "" }
|
cols << { "text" => "" }
|
||||||
else
|
else
|
||||||
cols << { "text" => "" }
|
cols << { "text" => "" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@rows << { "columns" => cols }
|
@rows << { "columns" => cols }
|
||||||
end
|
end
|
||||||
|
|
||||||
excel_name = "#{table.title}.xlsx"
|
excel_name = "#{table.title}.xlsx"
|
||||||
excel_name = 'attachment; filename="' + excel_name + '"'
|
excel_name = 'attachment; filename="' + excel_name + '"'
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.xlsx {
|
||||||
|
response.headers['Content-Disposition'] = excel_name
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.xlsx {
|
|
||||||
response.headers['Content-Disposition'] = excel_name
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
def get_query(params)
|
def get_query(params)
|
||||||
if params["column"].present?
|
if params["column"].present?
|
||||||
q = {params["column"] => params["q"]}
|
q = {params["column"] => params["q"]}
|
||||||
|
|
@ -146,10 +147,15 @@ end
|
||||||
# regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")})
|
# regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")})
|
||||||
# end
|
# end
|
||||||
regex = Regexp.new(".*"+v+".*", "i")
|
regex = Regexp.new(".*"+v+".*", "i")
|
||||||
if column.type == "text"
|
case column.type
|
||||||
|
when "text"
|
||||||
columns = column.column_entries.any_of([{"text.en" => regex}, {"text.zh_tw" => regex}])
|
columns = column.column_entries.any_of([{"text.en" => regex}, {"text.zh_tw" => regex}])
|
||||||
elsif column.type == "editor"
|
when "editor"
|
||||||
columns = column.column_entries.any_of([{"content.en" => regex}, {"content.zh_tw" => regex}])
|
columns = column.column_entries.any_of([{"content.en" => regex}, {"content.zh_tw" => regex}])
|
||||||
|
when "file"
|
||||||
|
column_ids = column.column_entries.pluck(:id)
|
||||||
|
filtered_column_ids = ColumnEntryFile.where(:column_entry_id.in => column_ids).any_of([{ "file_title.en" => regex },{"file_title.zh_tw" => regex }]).pluck(:column_entry)
|
||||||
|
columns = ColumnEntry.where(:id.in => filtered_column_ids)
|
||||||
end
|
end
|
||||||
# .or(:"content.en" => regex).or(:"content.zh_tw" => regex)
|
# .or(:"content.en" => regex).or(:"content.zh_tw" => regex)
|
||||||
tmp = columns.pluck(:table_entry_id)
|
tmp = columns.pluck(:table_entry_id)
|
||||||
|
|
@ -292,7 +298,7 @@ end
|
||||||
# csrf_input = "<input type=\"hidden\" name=\"authenticity_token\" value=\"#{csrf_value}\">"
|
# csrf_input = "<input type=\"hidden\" name=\"authenticity_token\" value=\"#{csrf_value}\">"
|
||||||
csrf_input = ""
|
csrf_input = ""
|
||||||
have_serial_number = (page.layout != 'index1')
|
have_serial_number = (page.layout != 'index1')
|
||||||
table_heads = table.table_columns.where(:display_in_index => true).asc(:order).collect do |tc|
|
table_heads = table.table_columns.where(:is_searchable => true).asc(:order).collect do |tc|
|
||||||
field_key = tc.key
|
field_key = tc.key
|
||||||
field_value = params_q[field_key]
|
field_value = params_q[field_key]
|
||||||
field_value = nil if field_value.blank?
|
field_value = nil if field_value.blank?
|
||||||
|
|
@ -310,7 +316,7 @@ end
|
||||||
search = "hide"
|
search = "hide"
|
||||||
sort_url = "#"
|
sort_url = "#"
|
||||||
sort = "hide"
|
sort = "hide"
|
||||||
when "editor"
|
when "editor","file"
|
||||||
sort_url = "#"
|
sort_url = "#"
|
||||||
sort = "hide"
|
sort = "hide"
|
||||||
sort_class = "sort hide"
|
sort_class = "sort hide"
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,13 @@
|
||||||
<%= f.check_box :is_searchable %> Searchable
|
<%= f.check_box :is_searchable %> Searchable
|
||||||
</label>
|
</label>
|
||||||
</span>
|
</span>
|
||||||
|
<% if column.type == "file" || column.type == "editor" %>
|
||||||
|
<span class="link_to_show2">
|
||||||
|
<label class="checkbox inline attributes-checkbox ">
|
||||||
|
<%= f.check_box :is_searchable %> Searchable
|
||||||
|
</label>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
<% 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" %>">
|
||||||
Date Format <%= f.select :date_format, select_values%>
|
Date Format <%= f.select :date_format, select_values%>
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,14 @@
|
||||||
<td>
|
<td>
|
||||||
<%= table.table_entries.count %>
|
<%= table.table_entries.count %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td class="lasttd">
|
||||||
<% if can_edit %>
|
<% if can_edit %>
|
||||||
<form action="/admin/universal_tables/import_data_from_excel" method="post" enctype="multipart/form-data" class="import_from_excel_form">
|
<form action="/admin/universal_tables/import_data_from_excel" method="post" enctype="multipart/form-data" class="import_from_excel_form">
|
||||||
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
|
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
|
||||||
<input type="file" name="import_data" />
|
<input class="import_data" type="file" name="import_data" />
|
||||||
<button class="btn btn-primary btn-small"><i class="icons-upload"></i></button>
|
<button class="btn btn-primary btn-small"><i class="icons-upload"></i></button>
|
||||||
<input type="hidden" name="universal_table_id" value="<%= table.id.to_s %>" />
|
<input type="hidden" name="universal_table_id" value="<%= table.id.to_s %>" />
|
||||||
<a href="<%= admin_universal_table_export_structure_path(table, :format => "xlsx") %>"><%= t("universal_table.export_structure") %></a>
|
<a class="Downloadtablestructure" href="<%= admin_universal_table_export_structure_path(table, :format => "xlsx") %>"><%= t("universal_table.export_structure") %></a>
|
||||||
</form>
|
</form>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
|
@ -47,3 +47,15 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<style>
|
||||||
|
.import_data{
|
||||||
|
max-width: 180px;
|
||||||
|
}
|
||||||
|
.lasttd{
|
||||||
|
width: 40%;
|
||||||
|
}
|
||||||
|
.Downloadtablestructure{
|
||||||
|
padding-left: 3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
@ -121,6 +121,13 @@
|
||||||
label.addClass("hide");
|
label.addClass("hide");
|
||||||
label.find("input[type=checkbox]").prop("checked",false);
|
label.find("input[type=checkbox]").prop("checked",false);
|
||||||
}
|
}
|
||||||
|
label = el.parent().find("span.link_to_show2");
|
||||||
|
if(el.val() == "editor" || el.val() == "file"){
|
||||||
|
label.removeClass("hide");
|
||||||
|
}else{
|
||||||
|
label.addClass("hide");
|
||||||
|
label.find("input[type=checkbox]").prop("checked",false);
|
||||||
|
}
|
||||||
label = el.parent().find("label.date_format");
|
label = el.parent().find("label.date_format");
|
||||||
if(el.val() == "date" || el.val() == "period"){
|
if(el.val() == "date" || el.val() == "period"){
|
||||||
label.removeClass("hide");
|
label.removeClass("hide");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue