fix query filter to avoid repeating results
This commit is contained in:
parent
2889581306
commit
061447c5d1
|
@ -7,7 +7,7 @@ class Admin::UniversalTablesController < OrbitAdminController
|
||||||
.with_categories(filters("category"))
|
.with_categories(filters("category"))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_sort
|
def update_sort
|
||||||
uid = params[:universal_table_id].split("-").last
|
uid = params[:universal_table_id].split("-").last
|
||||||
@table = UTable.where(:uid => uid).first rescue nil
|
@table = UTable.where(:uid => uid).first rescue nil
|
||||||
|
@ -33,7 +33,7 @@ class Admin::UniversalTablesController < OrbitAdminController
|
||||||
@table_fields = ['universal_table.sort_number']+@columns.collect{|tc| tc.title} + ['universal_table.created_at']
|
@table_fields = ['universal_table.sort_number']+@columns.collect{|tc| tc.title} + ['universal_table.created_at']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
uid = params[:id].split("-").last
|
uid = params[:id].split("-").last
|
||||||
@table = UTable.where(:uid => uid).first rescue nil
|
@table = UTable.where(:uid => uid).first rescue nil
|
||||||
|
@ -88,7 +88,7 @@ class Admin::UniversalTablesController < OrbitAdminController
|
||||||
columns = sheet[1].cells.collect.with_index{|c,i|
|
columns = sheet[1].cells.collect.with_index{|c,i|
|
||||||
c.value.blank? ? table.table_columns.where(:title => sheet[0].cells[i].value.to_s.split("-").first.strip).first : table.table_columns.where(:key => c.value.to_s).first
|
c.value.blank? ? table.table_columns.where(:title => sheet[0].cells[i].value.to_s.split("-").first.strip).first : table.table_columns.where(:key => c.value.to_s).first
|
||||||
}
|
}
|
||||||
languages = sheet[2].cells.collect{|c|
|
languages = sheet[2].cells.collect{|c|
|
||||||
c.value.split("-").last rescue nil
|
c.value.split("-").last rescue nil
|
||||||
}
|
}
|
||||||
sheet.each_with_index do |row, i|
|
sheet.each_with_index do |row, i|
|
||||||
|
@ -128,13 +128,13 @@ class Admin::UniversalTablesController < OrbitAdminController
|
||||||
when "period"
|
when "period"
|
||||||
if tc.date_format == "yyyy" && !val.nil?
|
if tc.date_format == "yyyy" && !val.nil?
|
||||||
val = val.to_s + "/01/01"
|
val = val.to_s + "/01/01"
|
||||||
end
|
end
|
||||||
skip = 2
|
skip = 2
|
||||||
ce.period_from = val
|
ce.period_from = val
|
||||||
val = row.cells[index + 1].value rescue nil
|
val = row.cells[index + 1].value rescue nil
|
||||||
if tc.date_format == "yyyy" && !val.nil?
|
if tc.date_format == "yyyy" && !val.nil?
|
||||||
val = val.to_s + "/01/01"
|
val = val.to_s + "/01/01"
|
||||||
end
|
end
|
||||||
ce.period_to = val
|
ce.period_to = val
|
||||||
end
|
end
|
||||||
ce.table_column_id = tc.id
|
ce.table_column_id = tc.id
|
||||||
|
@ -270,6 +270,7 @@ class Admin::UniversalTablesController < OrbitAdminController
|
||||||
column.each do |c|
|
column.each do |c|
|
||||||
columns = (columns | c.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex))
|
columns = (columns | c.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex))
|
||||||
end
|
end
|
||||||
|
columns = columns.uniq{|col| col.table_entry_id}
|
||||||
columns_count = columns.count
|
columns_count = columns.count
|
||||||
columns_count = 1 if columns_count==0
|
columns_count = 1 if columns_count==0
|
||||||
columns = Kaminari.paginate_array(columns,limit: columns_count)
|
columns = Kaminari.paginate_array(columns,limit: columns_count)
|
||||||
|
@ -284,9 +285,3 @@ class Admin::UniversalTablesController < OrbitAdminController
|
||||||
params.require(:table_entry).permit!
|
params.require(:table_entry).permit!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ class UniversalTablesController < ApplicationController
|
||||||
reset = ""
|
reset = ""
|
||||||
if !OrbitHelper.current_user.nil?
|
if !OrbitHelper.current_user.nil?
|
||||||
p = {}
|
p = {}
|
||||||
params.each do |k,v|
|
params.each do |k,v|
|
||||||
p[k] = v if ["q","column","sort","sortcolumn"].include?(k)
|
p[k] = v if ["q","column","sort","sortcolumn"].include?(k)
|
||||||
end
|
end
|
||||||
export_button = "<a href='/xhr/universal_table/export.xlsx?cat=#{OrbitHelper.page_categories.first}&page_id=#{page.page_id}&#{p.to_param}'>Export</a>"
|
export_button = "<a href='/xhr/universal_table/export.xlsx?cat=#{OrbitHelper.page_categories.first}&page_id=#{page.page_id}&#{p.to_param}'>Export</a>"
|
||||||
|
@ -180,7 +180,7 @@ class UniversalTablesController < ApplicationController
|
||||||
end
|
end
|
||||||
excel_name = table.title + ".xlsx"
|
excel_name = table.title + ".xlsx"
|
||||||
excel_name = 'attachment; filename="' + excel_name + '"'
|
excel_name = 'attachment; filename="' + excel_name + '"'
|
||||||
|
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.xlsx {
|
format.xlsx {
|
||||||
|
@ -201,7 +201,12 @@ class UniversalTablesController < ApplicationController
|
||||||
regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
|
regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
|
||||||
regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")})
|
regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")})
|
||||||
end
|
end
|
||||||
columns = column.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex)
|
if column.type == "text"
|
||||||
|
columns = column.column_entries.any_of(:"text.en" => regex, :"text.zh_tw" => regex)
|
||||||
|
elsif column.type == "editor"
|
||||||
|
columns = column.column_entries.any_of(:"content.en" => regex, :"content.zh_tw" => regex)
|
||||||
|
end
|
||||||
|
# .or(:"content.en" => regex).or(:"content.zh_tw" => regex)
|
||||||
if paginated
|
if paginated
|
||||||
entries = TableEntry.where(:u_table_id=>table.id).sorting(params: params,table: table,column_entries: columns,page_num: params["page_no"],per: OrbitHelper.page_data_count)
|
entries = TableEntry.where(:u_table_id=>table.id).sorting(params: params,table: table,column_entries: columns,page_num: params["page_no"],per: OrbitHelper.page_data_count)
|
||||||
else
|
else
|
||||||
|
@ -253,6 +258,3 @@ class UniversalTablesController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue