Skip to content
Snippets Groups Projects
Commit 5a4c6c6e authored by Tögl, Christina's avatar Tögl, Christina
Browse files

Improve overwrite file dialog functionality for multiple files

parent b1f25b8a
No related branches found
No related tags found
1 merge request!1Filehandling overwrite dialog
Pipeline #12453 failed
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
......@@ -41,6 +41,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
this.uploadFileObject = null;
this.uploadFileDirectory = null;
this.isDialogOpen = true;
this.fileList = [];
}
static get scopedElements() {
......@@ -66,6 +67,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
allowedMimeTypes: { type: String, attribute: 'allowed-mime-types' },
directoriesOnly: { type: Boolean, attribute: 'directories-only' },
maxSelectedItems: { type: Number, attribute: 'max-selected-items' },
loading: { type: Boolean, attribute: false },
replaceFilename: { type: String, attribute: false },
uploadFileObject: { type: Object, attribute: false },
uploadFileDirectory: { type: String, attribute: false },
......@@ -363,27 +365,15 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
}
async uploadFiles(files, directory) {
console.log("before all file finished");
let ret = false;
let ret_outer = true;
const start = async () => {
for (let index = 0; index < files.length; index++) {
ret = await this.uploadFile(files[index], directory);
if(ret === false) {
ret_outer = false;
break;
}
}
uploadFiles(files, directory) {
this.fileList = files;
this.uploadFile(directory);
}
await start();
//let ret = await files.forEach((file) => this.uploadFile(file, directory));
console.log("all files finished", ret_outer);
return ret_outer;
}
async uploadFile(file, directory) {
async uploadFile(directory) {
if(this.fileList.length !== 0) {
let file = this.fileList[0];
this.replaceFilename = file.name;
console.log("before one file finished");
let path = directory + "/" + file.name;
// https://github.com/perry-mitchell/webdav-client#putfilecontents
......@@ -392,23 +382,36 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
let contents = await this.webDavClient
.putFileContents(path, file, { overwrite: false, onUploadProgress: progress => {
console.log(`Uploaded ${progress.loaded} bytes of ${progress.total}`);
}});
}}).then(function() {
this.loading = false;
this.statusText = "";
console.log("try finished");
ret = true;
console.log("after one file finished");
this.fileList.shift();
console.log("FileList: ", this.fileList);
this.uploadFile(directory);
}
);
} catch(error ) {
console.error(error.message);
this.loading = false;
//this.statusText = error.message;
this.statusText = error.message;
console.log("----", error.message);
if(error.message.search("412") !== -1) {
this.replaceModalDialog(file, directory);
console.log("dialog open after upload? ", this.isDialogOpen);
}
}
console.log("after one file finished");
return ret;
}
else {
const event = new CustomEvent("dbp-nextcloud-file-picker-file-uploaded-finished",
{ bubbles: true, composed: true });
this.dispatchEvent(event);
}
}
async uploadFileWithNewName() {
......@@ -419,20 +422,21 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
if(this._("input[name='replacement']:checked").value === "ignore") {
MicroModal.close();
this.fileList.shift();
return true;
}
else if (this._("input[name='replacement']:checked").value === "new-name") {
path = directory + "/" + this._("#replace-filename").value;
console.log("new name checked");
console.log("############# new name checked");
this.replaceFilename = this._("#replace-filename").value;
}
else {
path = directory + "/" + this.uploadFileObject.name;
overwrite = true;
console.log("replace checked");
console.log("############### replace checked");
}
// https://github.com/perry-mitchell/webdav-client#putfilecontents
let ret = false;
try{
let contents = await this.webDavClient
.putFileContents(path, file, { overwrite: overwrite, onUploadProgress: progress => {
......@@ -441,19 +445,24 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
this.loading = false;
this.statusText = "";
console.log("try finished");
ret = true;
console.log("after one file finished");
this.fileList.shift();
console.log("FileList length: ", this.fileList.length);
console.log("########## after one file finished");
MicroModal.close();
this.uploadFile(directory);
} catch(error ) {
console.error(error.message);
this.loading = false;
this.statusText = error.message;
console.log("----", error.message);
if(error.message.search("412") !== -1) {
MicroModal.close();
this.replaceModalDialog(file, directory);
console.log("dialog open after upload? ", this.isDialogOpen);
}
}
console.log("after one file finished");
MicroModal.close();
return ret;
}
/**
......@@ -465,15 +474,8 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
console.log("zeig uns an.");
this.uploadFileObject = file;
this.uploadFileDirectory = directory;
this.replaceFilename = file.name;
this.isDialogOpen = true;
/*MicroModal.init({
onShow: modal => { this.isDialogOpen = true },
onClose: modal => { this.isDialogOpen = false; },
});*/
MicroModal.show(this._('#replace-modal'), {
onClose: modal => { this.isDialogOpen = false; }
});
MicroModal.show(this._('#replace-modal'));
console.log("dialog is open? ", this.isDialogOpen);
}
......
......@@ -118,8 +118,8 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
let that = this;
const element = that._('#nextcloud-file-picker');
console.log("davor");
const finished = await element.uploadFiles(that.files, directory);
console.log("fertig", finished);
await element.uploadFiles(that.files, directory);
/*console.log("fertig", finished);
if(finished) {
MicroModal.close();
console.log("close");
......@@ -129,9 +129,20 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
"type": "success",
"timeout": 5,
});
}
}*/
}
finishedFileUpload() {
MicroModal.close();
console.log("close");
send({
"summary": i18n.t('file-sink.upload-success-title'),
"body": i18n.t('file-sink.upload-success-body', {name: this.nextcloudName}),
"type": "success",
"timeout": 5,
});
}
preventDefaults (e) {
......@@ -228,6 +239,9 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
nextcloud-name="${this.nextcloudName}"
@dbp-nextcloud-file-picker-file-uploaded="${(event) => {
this.uploadToNextcloud(event.detail);
}}"
@dbp-nextcloud-file-picker-file-uploaded-finished="${(event) => {
this.finishedFileUpload();
}}"></dbp-nextcloud-file-picker>
</div>
</main>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment