diff --git a/app/controllers/admin/universal_tables_controller.rb b/app/controllers/admin/universal_tables_controller.rb index 528a856..44cf0c1 100644 --- a/app/controllers/admin/universal_tables_controller.rb +++ b/app/controllers/admin/universal_tables_controller.rb @@ -7,7 +7,7 @@ class Admin::UniversalTablesController < OrbitAdminController .with_categories(filters("category")) end - + def update_sort uid = params[:universal_table_id].split("-").last @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'] end end - + def show uid = params[:id].split("-").last @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| 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 } sheet.each_with_index do |row, i| @@ -128,13 +128,13 @@ class Admin::UniversalTablesController < OrbitAdminController when "period" if tc.date_format == "yyyy" && !val.nil? val = val.to_s + "/01/01" - end + end skip = 2 ce.period_from = val val = row.cells[index + 1].value rescue nil if tc.date_format == "yyyy" && !val.nil? val = val.to_s + "/01/01" - end + end ce.period_to = val end ce.table_column_id = tc.id @@ -270,6 +270,7 @@ class Admin::UniversalTablesController < OrbitAdminController 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)) end + columns = columns.uniq{|col| col.table_entry_id} columns_count = columns.count columns_count = 1 if columns_count==0 columns = Kaminari.paginate_array(columns,limit: columns_count) @@ -284,9 +285,3 @@ class Admin::UniversalTablesController < OrbitAdminController params.require(:table_entry).permit! end end - - - - - - diff --git a/app/controllers/universal_tables_controller.rb b/app/controllers/universal_tables_controller.rb index 2776cbd..ddc1159 100644 --- a/app/controllers/universal_tables_controller.rb +++ b/app/controllers/universal_tables_controller.rb @@ -117,7 +117,7 @@ class UniversalTablesController < ApplicationController reset = "" if !OrbitHelper.current_user.nil? p = {} - params.each do |k,v| + params.each do |k,v| p[k] = v if ["q","column","sort","sortcolumn"].include?(k) end export_button = "Export" @@ -180,7 +180,7 @@ class UniversalTablesController < ApplicationController end excel_name = table.title + ".xlsx" excel_name = 'attachment; filename="' + excel_name + '"' - + end respond_to do |format| format.xlsx { @@ -201,7 +201,12 @@ class UniversalTablesController < ApplicationController regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/) regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")}) 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 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 @@ -253,6 +258,3 @@ class UniversalTablesController < ApplicationController } end end - - -