fixed import

This commit is contained in:
rulingcom 2025-07-04 23:03:53 +08:00
parent a43523d91f
commit 007da54954
4 changed files with 26 additions and 15 deletions

View File

@ -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

View File

@ -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();

View File

@ -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"

View File

@ -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