Wait for answers on all conflicted files before uploading selected files

This commit is contained in:
nathan 2025-03-04 10:54:46 -07:00
parent 8b65f1286f
commit 6dae21b311
2 changed files with 29 additions and 3 deletions

View File

@ -119,6 +119,10 @@ export class Et2File extends Et2InputWidget(LitElement)
protected resumable : Resumable = null; protected resumable : Resumable = null;
private __value : { [tempName : string] : FileInfo } = {}; private __value : { [tempName : string] : FileInfo } = {};
// In case we need to do things between file added and start of upload, we wait
protected _uploadPending : { [uniqueIdentifier : string] : Promise<void> } = {};
private _uploadDelayTimeout : number;
/** Files already uploaded */ /** Files already uploaded */
@property({type: Object}) @property({type: Object})
set value(newValue : { [tempFileName : string] : FileInfo }) set value(newValue : { [tempFileName : string] : FileInfo })
@ -320,12 +324,30 @@ export class Et2File extends Et2InputWidget(LitElement)
await fileItem.updateComplete; await fileItem.updateComplete;
const ev = new CustomEvent("et2-add", {bubbles: true, detail: file}) const ev = new CustomEvent("et2-add", {bubbles: true, detail: file})
this.dispatchEvent(ev); this.dispatchEvent(ev);
setTimeout(this.resumable.upload, 100);
if(typeof this.onStart == "function") if(typeof this.onStart == "function")
{ {
this.onStart(ev); this.onStart(ev);
} }
if(ev.defaultPrevented)
{
// Event handling canceled the upload
file.cancel();
}
// We can't pause individual files, just the upload as a whole, so wait together
if(this._uploadDelayTimeout)
{
window.clearTimeout(this._uploadDelayTimeout);
}
this._uploadDelayTimeout = window.setTimeout(() =>
{
Promise.allSettled(Object.values(this._uploadPending)).then(() =>
{
this._uploadPending = {};
this._uploadDelayTimeout = null;
setTimeout(this.resumable.upload);
});
}, 100);
} }
protected resumableFileProgress(file : FileInfo, event) protected resumableFileProgress(file : FileInfo, event)

View File

@ -113,7 +113,11 @@ export class Et2VfsUpload extends Et2File
{ {
return superAdded(info, event); return superAdded(info, event);
} }
this.egw().request("EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_conflict_check", [ // Pause uploads while we check
this.resumable.pause();
this._uploadPending[info.uniqueIdentifier] = this.egw().request(
"EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_conflict_check", [
this.getInstanceManager()?.etemplate_exec_id, // request_id this.getInstanceManager()?.etemplate_exec_id, // request_id
this.path, // path this.path, // path
info.file.name, info.file.name,
@ -190,7 +194,7 @@ export class Et2VfsUpload extends Et2File
// Upload as set // Upload as set
return true; return true;
case "rename": case "rename":
info.fileName = value?.value ?? info.fileName; info.fileName = info['name'] = value?.value ?? info.fileName;
return true; return true;
case "cancel": case "cancel":
// Don't upload // Don't upload