added a route to get table entries

This commit is contained in:
rulingcom 2025-05-13 21:05:19 +08:00
parent 2f99e39bf2
commit b4879bd7ae
2 changed files with 23 additions and 7 deletions

View File

@ -48,6 +48,21 @@ class Admin::UniversalTablesController < OrbitAdminController
end
end
def get_entries
table = UTable.where(:uid => params["uid"]).first rescue nil
data = []
if !table.nil?
enteries = search_data(table, 50)
enteries.each do |entry|
data << {
"id" => entry.id.to_s,
"text" => entry.column_entries.first.text
}
end
end
render :json => data.to_json
end
def export_structure
uid = params[:universal_table_id].split("-").last
@table = UTable.where(:uid => uid).first rescue nil
@ -262,7 +277,7 @@ class Admin::UniversalTablesController < OrbitAdminController
private
def search_data(table)
def search_data(table, per=10)
keywords = params["q"]
keywords = keywords.strip.nil? ? keywords : keywords.strip
regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
@ -277,7 +292,7 @@ class Admin::UniversalTablesController < OrbitAdminController
columns_count = columns.count
columns_count = 1 if columns_count==0
columns = Kaminari.paginate_array(columns,limit: columns_count)
entries = TableEntry.where(:u_table_id=>table.id).sorting(params: params,table: table,column_entries: columns,page_num: params[:page],per: 10)
entries = TableEntry.where(:u_table_id=>table.id).sorting(params: params,table: table,column_entries: columns,page_num: params[:page],per: per)
end
def table_params

View File

@ -18,6 +18,7 @@ Rails.application.routes.draw do
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do
post "/universal_tables/add_entry", to: 'universal_tables#add_entry'
get "/universal_tables/get_entries", to: 'universal_tables#get_entries'
patch "/universal_tables/update_entry", to: 'universal_tables#update_entry'
post "/universal_tables/import_data_from_excel", to: 'universal_tables#import_data_from_excel'
get "universal_tables/checkforthread", to: "universal_tables#checkforthread"