From 007da5495472936fe6eb69b1f79f501c97b926b2 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Fri, 4 Jul 2025 23:03:53 +0800 Subject: [PATCH] fixed import --- .../admin/universal_tables_controller.rb | 9 +++++--- .../admin/universal_tables/index.html.erb | 21 +++++++++++-------- config/routes.rb | 4 ++-- lib/tasks/universal_table_tasks.rake | 7 ++++++- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/universal_tables_controller.rb b/app/controllers/admin/universal_tables_controller.rb index bf62c3f..3ef07c8 100755 --- a/app/controllers/admin/universal_tables_controller.rb +++ b/app/controllers/admin/universal_tables_controller.rb @@ -124,7 +124,11 @@ end def checkforimportthread utable = UTable.find(params[:utable_id]) - render :json => {"currentCount" => utable.current_xlsx_value, "totalCount" => utable.table_entries.count}.to_json + render :json => { + "currentCount" => utable.current_xlsx_value, + "totalCount" => utable.table_entries.count, + "id" => utable.id.to_s + }.to_json end def export_data @@ -177,8 +181,7 @@ end render json: { success: true, - totalCount: sheet.count - 3, - id: table.id.to_s + totalCount: sheet.count - 3 }.to_json end diff --git a/app/views/admin/universal_tables/index.html.erb b/app/views/admin/universal_tables/index.html.erb index ba9f821..d478bab 100755 --- a/app/views/admin/universal_tables/index.html.erb +++ b/app/views/admin/universal_tables/index.html.erb @@ -56,8 +56,9 @@ importModalBtn = $("#import-modal-close-btn"), importCompleteZone = $("#import-complete-zone"), importErrorZone = $("#import-error-zone"), - currentNumber = importWaitZone.find(".current-number"); - totalNumber = importWaitZone.find(".total-number") + currentNumber = importWaitZone.find(".current-number"), + totalNumber = importWaitZone.find(".total-number"), + firstData = null, processManager = new ProcessManager(); $("form.import_from_excel_form").on("submit",function(){ var form = this; @@ -74,28 +75,30 @@ $(this).ajaxSubmit({ dataType : "json", success : function(data){ + firstData = data; if(data.success){ totalNumber.text(data.totalCount); - checkForThread = new Process(function(){ + checkForImportThread = new Process(function(){ $.ajax({ url : "/admin/universal_tables/checkforimportthread", type : "get", data : {"utable_id" : tableID}, dataType : "json" }).done(function(threadData){ - currentNumber.text(threadData.currentCount) - if(threadData.currentCount >= threadData.totalCount){ - checkForThread.kill(); + currentNumber.text(threadData.currentCount); + if(threadData.currentCount >= firstData.totalCount){ + checkForImportThread.kill(); importWaitZone.hide(); importCompleteZone.show(); importWaitZone.find("img").hide(); importModalBtn.show(); + $("tr#table_" + threadData.id + " td:eq(2)").text(threadData.totalCount); } }) }) - checkForThread.setTimeInterval(2000); - checkForThread.setRepeat(Process.CONSTANTS.REPEAT_INFINITE); - processManager.queue(checkForThread); + checkForImportThread.setTimeInterval(3000); + checkForImportThread.setRepeat(Process.CONSTANTS.REPEAT_INFINITE); + processManager.queue(checkForImportThread); }else{ importWaitZone.hide(); importErrorZone.show(); diff --git a/config/routes.rb b/config/routes.rb index 00a0c5e..197fd8d 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,8 +23,8 @@ Rails.application.routes.draw do get "/universal_tables/get_mindmaps", to: 'universal_tables#get_mindmaps' 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" - get "universal_tables/checkforimportthread", to: "universal_tables#checkforimportthread" + get "/universal_tables/checkforthread", to: "universal_tables#checkforthread" + get "/universal_tables/checkforimportthread", to: "universal_tables#checkforimportthread" get "/universal_table/:id/mind_maps", to: "mind_maps#index" resources :universal_tables do get "new_entry" diff --git a/lib/tasks/universal_table_tasks.rake b/lib/tasks/universal_table_tasks.rake index 309852f..2d47daf 100755 --- a/lib/tasks/universal_table_tasks.rake +++ b/lib/tasks/universal_table_tasks.rake @@ -84,7 +84,12 @@ namespace :universal_table_tasks do end.to_h sheet.each_with_index do |row, i| - next if i < 3 || row.cells.compact.map { |c| c.value.to_s.strip }.all?(&:blank?) + if i >= 3 && row.cells.all? { |c| c.nil? || c.value.to_s.strip.blank? } + table.inc(current_xlsx_value: 1) + next + end + + next if i < 3 uid_val = row[0]&.value.to_s.strip rescue nil te = uid_val.present? ? TableEntry.where(uid: uid_val, u_table_id: table.id).first_or_initialize : TableEntry.new