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
|
||||
|
||||
def export_filtered
|
||||
table = UTable.where(:category_id => params[:cat]).first rescue nil
|
||||
page = Page.where(:page_id => params[:page_id]).first
|
||||
return unless table
|
||||
def export_filtered
|
||||
table = UTable.where(:category_id => params[:cat]).first rescue nil
|
||||
page = Page.where(:page_id => params[:page_id]).first
|
||||
return unless table
|
||||
|
||||
host_url = Site.first.root_url
|
||||
host_url = request.protocol + request.host_with_port if host_url == "http://"
|
||||
host_url = Site.first.root_url
|
||||
host_url = request.protocol + request.host_with_port if host_url == "http://"
|
||||
|
||||
@rows = []
|
||||
@tablecolumns = []
|
||||
@rows = []
|
||||
@tablecolumns = []
|
||||
|
||||
# 處理 file 欄位雙欄輸出(連結與註解)
|
||||
table.table_columns.where(display_in_index: true).asc(:order).each do |column|
|
||||
if column.type == "file"
|
||||
@tablecolumns << column
|
||||
@tablecolumns << column.dup.tap { |c| c.define_singleton_method(:_file_title_column?) { true } }
|
||||
else
|
||||
@tablecolumns << column
|
||||
end
|
||||
end
|
||||
# 處理 file 欄位雙欄輸出(連結與註解)
|
||||
table.table_columns.where(display_in_index: true).asc(:order).each do |column|
|
||||
if column.type == "file"
|
||||
@tablecolumns << column
|
||||
@tablecolumns << column.dup.tap { |c| c.define_singleton_method(:_file_title_column?) { true } }
|
||||
else
|
||||
@tablecolumns << column
|
||||
end
|
||||
end
|
||||
|
||||
entries = get_entries(params, table, page, false)
|
||||
entries = get_entries(params, table, page, false)
|
||||
|
||||
entries.each do |te|
|
||||
cols = []
|
||||
entries.each do |te|
|
||||
cols = []
|
||||
|
||||
@tablecolumns.each do |column|
|
||||
# 跳過副註解欄(由主 file 欄處理)
|
||||
if column.respond_to?(:_file_title_column?) && column._file_title_column?
|
||||
next
|
||||
end
|
||||
@tablecolumns.each do |column|
|
||||
# 跳過副註解欄(由主 file 欄處理)
|
||||
if column.respond_to?(:_file_title_column?) && column._file_title_column?
|
||||
next
|
||||
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?
|
||||
case column.type
|
||||
when "text"
|
||||
cols << { "text" => ce.text.to_s }
|
||||
if ce.present?
|
||||
case column.type
|
||||
when "text"
|
||||
cols << { "text" => ce.text.to_s }
|
||||
|
||||
when "integer"
|
||||
cols << { "text" => ce.number.to_s }
|
||||
when "integer"
|
||||
cols << { "text" => ce.number.to_s }
|
||||
|
||||
when "editor"
|
||||
cols << { "text" => ce.content.to_s }
|
||||
when "editor"
|
||||
cols << { "text" => ce.content.to_s }
|
||||
|
||||
when "date"
|
||||
cols << { "text" => format_date(ce.date, column.date_format).to_s }
|
||||
when "date"
|
||||
cols << { "text" => format_date(ce.date, column.date_format).to_s }
|
||||
|
||||
when "period"
|
||||
from = format_date(ce.period_from, column.date_format)
|
||||
to = format_date(ce.period_to, column.date_format)
|
||||
text = from.blank? && to.present? ? to : "#{from} ~ #{to}"
|
||||
cols << { "text" => text.to_s }
|
||||
when "period"
|
||||
from = format_date(ce.period_from, column.date_format)
|
||||
to = format_date(ce.period_to, column.date_format)
|
||||
text = from.blank? && to.present? ? to : "#{from} ~ #{to}"
|
||||
cols << { "text" => text.to_s }
|
||||
|
||||
when "image"
|
||||
text = ce.image&.thumb&.url ? (host_url + ce.image.thumb.url) : ""
|
||||
cols << { "text" => text }
|
||||
when "image"
|
||||
text = ce.image&.thumb&.url ? (host_url + ce.image.thumb.url) : ""
|
||||
cols << { "text" => text }
|
||||
|
||||
when "file"
|
||||
file_links = []
|
||||
file_titles = []
|
||||
locale = I18n.locale.to_s
|
||||
when "file"
|
||||
file_links = []
|
||||
file_titles = []
|
||||
locale = I18n.locale.to_s
|
||||
|
||||
ce.column_entry_files.desc(:sort_number).each do |entry_file|
|
||||
next unless entry_file.choose_lang_display(locale)
|
||||
ce.column_entry_files.desc(:sort_number).each do |entry_file|
|
||||
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)
|
||||
entry_file.file_title_translations[locale]
|
||||
elsif entry_file.file_title.is_a?(Hash)
|
||||
entry_file.file_title[locale]
|
||||
else
|
||||
entry_file.file_title
|
||||
end
|
||||
title = if entry_file.respond_to?(:file_title_translations) && entry_file.file_title_translations.is_a?(Hash)
|
||||
entry_file.file_title_translations[locale]
|
||||
elsif entry_file.file_title.is_a?(Hash)
|
||||
entry_file.file_title[locale]
|
||||
else
|
||||
entry_file.file_title
|
||||
end
|
||||
|
||||
title = entry_file.file.filename.to_s if title.blank?
|
||||
file_titles << title
|
||||
end
|
||||
title = entry_file.file.filename.to_s if title.blank?
|
||||
file_titles << title
|
||||
end
|
||||
|
||||
cols << { "text" => file_links.join("\r\n") }
|
||||
cols << { "text" => file_titles.join("\r\n") }
|
||||
cols << { "text" => file_links.join("\r\n") }
|
||||
cols << { "text" => file_titles.join("\r\n") }
|
||||
|
||||
else
|
||||
cols << { "text" => "" }
|
||||
end
|
||||
else
|
||||
if column.type == "file"
|
||||
cols << { "text" => "" }
|
||||
cols << { "text" => "" }
|
||||
else
|
||||
cols << { "text" => "" }
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
cols << { "text" => "" }
|
||||
end
|
||||
else
|
||||
if column.type == "file"
|
||||
cols << { "text" => "" }
|
||||
cols << { "text" => "" }
|
||||
else
|
||||
cols << { "text" => "" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@rows << { "columns" => cols }
|
||||
end
|
||||
@rows << { "columns" => cols }
|
||||
end
|
||||
|
||||
excel_name = "#{table.title}.xlsx"
|
||||
excel_name = 'attachment; filename="' + excel_name + '"'
|
||||
excel_name = "#{table.title}.xlsx"
|
||||
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)
|
||||
if params["column"].present?
|
||||
q = {params["column"] => params["q"]}
|
||||
|
|
@ -146,10 +147,15 @@ end
|
|||
# regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")})
|
||||
# end
|
||||
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}])
|
||||
elsif column.type == "editor"
|
||||
when "editor"
|
||||
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
|
||||
# .or(:"content.en" => regex).or(:"content.zh_tw" => regex)
|
||||
tmp = columns.pluck(:table_entry_id)
|
||||
|
|
@ -292,7 +298,7 @@ end
|
|||
# csrf_input = "<input type=\"hidden\" name=\"authenticity_token\" value=\"#{csrf_value}\">"
|
||||
csrf_input = ""
|
||||
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_value = params_q[field_key]
|
||||
field_value = nil if field_value.blank?
|
||||
|
|
@ -310,7 +316,7 @@ end
|
|||
search = "hide"
|
||||
sort_url = "#"
|
||||
sort = "hide"
|
||||
when "editor"
|
||||
when "editor","file"
|
||||
sort_url = "#"
|
||||
sort = "hide"
|
||||
sort_class = "sort hide"
|
||||
|
|
|
|||
|
|
@ -81,6 +81,13 @@
|
|||
<%= f.check_box :is_searchable %> Searchable
|
||||
</label>
|
||||
</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]} %>
|
||||
<label class="checkbox date_format inline attributes-checkbox <%= column.type == "date" || column.type == "period" ? "" : "hide" %>">
|
||||
Date Format <%= f.select :date_format, select_values%>
|
||||
|
|
|
|||
|
|
@ -32,18 +32,30 @@
|
|||
<td>
|
||||
<%= table.table_entries.count %>
|
||||
</td>
|
||||
<td>
|
||||
<td class="lasttd">
|
||||
<% if can_edit %>
|
||||
<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 %>
|
||||
<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>
|
||||
<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>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</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.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");
|
||||
if(el.val() == "date" || el.val() == "period"){
|
||||
label.removeClass("hide");
|
||||
|
|
|
|||
Loading…
Reference in New Issue