Skip to content
Snippets Groups Projects

Filehandling overwrite dialog

Merged Steinwender, Tamara requested to merge filehandling-overwrite-dialog into master
All threads resolved!
2 files
+ 77
61
Compare changes
  • Side-by-side
  • Inline

Files

@@ -41,6 +41,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
@@ -41,6 +41,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
this.uploadFileObject = null;
this.uploadFileObject = null;
this.uploadFileDirectory = null;
this.uploadFileDirectory = null;
this.isDialogOpen = true;
this.isDialogOpen = true;
 
this.fileList = [];
}
}
static get scopedElements() {
static get scopedElements() {
@@ -66,6 +67,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
@@ -66,6 +67,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
allowedMimeTypes: { type: String, attribute: 'allowed-mime-types' },
allowedMimeTypes: { type: String, attribute: 'allowed-mime-types' },
directoriesOnly: { type: Boolean, attribute: 'directories-only' },
directoriesOnly: { type: Boolean, attribute: 'directories-only' },
maxSelectedItems: { type: Number, attribute: 'max-selected-items' },
maxSelectedItems: { type: Number, attribute: 'max-selected-items' },
 
loading: { type: Boolean, attribute: false },
replaceFilename: { type: String, attribute: false },
replaceFilename: { type: String, attribute: false },
uploadFileObject: { type: Object, attribute: false },
uploadFileObject: { type: Object, attribute: false },
uploadFileDirectory: { type: String, attribute: false },
uploadFileDirectory: { type: String, attribute: false },
@@ -363,52 +365,53 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
@@ -363,52 +365,53 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
}
}
async uploadFiles(files, directory) {
uploadFiles(files, directory) {
console.log("before all file finished");
this.fileList = files;
let ret = false;
this.uploadFile(directory);
let ret_outer = true;
}
const start = async () => {
for (let index = 0; index < files.length; index++) {
async uploadFile(directory) {
ret = await this.uploadFile(files[index], directory);
if(this.fileList.length !== 0) {
if(ret === false) {
let file = this.fileList[0];
ret_outer = false;
this.replaceFilename = file.name;
break;
console.log("before one file finished");
 
let path = directory + "/" + file.name;
 
// https://github.com/perry-mitchell/webdav-client#putfilecontents
 
let ret = false;
 
try{
 
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");
 
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;
 
console.log("----", error.message);
 
if(error.message.search("412") !== -1) {
 
this.replaceModalDialog(file, directory);
 
console.log("dialog open after upload? ", this.isDialogOpen);
}
}
}
}
 
 
}
 
else {
 
const event = new CustomEvent("dbp-nextcloud-file-picker-file-uploaded-finished",
 
{ bubbles: true, composed: true });
 
this.dispatchEvent(event);
}
}
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) {
console.log("before one file finished");
let path = directory + "/" + file.name;
// https://github.com/perry-mitchell/webdav-client#putfilecontents
let ret = false;
try{
let contents = await this.webDavClient
.putFileContents(path, file, { overwrite: false, onUploadProgress: progress => {
console.log(`Uploaded ${progress.loaded} bytes of ${progress.total}`);
}});
this.loading = false;
this.statusText = "";
console.log("try finished");
ret = true;
} catch(error ) {
console.error(error.message);
this.loading = false;
//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;
}
}
async uploadFileWithNewName() {
async uploadFileWithNewName() {
@@ -419,20 +422,21 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
@@ -419,20 +422,21 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
if(this._("input[name='replacement']:checked").value === "ignore") {
if(this._("input[name='replacement']:checked").value === "ignore") {
MicroModal.close();
MicroModal.close();
 
this.fileList.shift();
return true;
return true;
}
}
else if (this._("input[name='replacement']:checked").value === "new-name") {
else if (this._("input[name='replacement']:checked").value === "new-name") {
path = directory + "/" + this._("#replace-filename").value;
path = directory + "/" + this._("#replace-filename").value;
console.log("new name checked");
console.log("############# new name checked");
 
this.replaceFilename = this._("#replace-filename").value;
}
}
else {
else {
path = directory + "/" + this.uploadFileObject.name;
path = directory + "/" + this.uploadFileObject.name;
overwrite = true;
overwrite = true;
console.log("replace checked");
console.log("############### replace checked");
}
}
// https://github.com/perry-mitchell/webdav-client#putfilecontents
// https://github.com/perry-mitchell/webdav-client#putfilecontents
let ret = false;
try{
try{
let contents = await this.webDavClient
let contents = await this.webDavClient
.putFileContents(path, file, { overwrite: overwrite, onUploadProgress: progress => {
.putFileContents(path, file, { overwrite: overwrite, onUploadProgress: progress => {
@@ -441,19 +445,24 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
@@ -441,19 +445,24 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
this.loading = false;
this.loading = false;
this.statusText = "";
this.statusText = "";
console.log("try finished");
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 ) {
} catch(error ) {
console.error(error.message);
console.error(error.message);
this.loading = false;
this.loading = false;
this.statusText = error.message;
this.statusText = error.message;
console.log("----", error.message);
console.log("----", error.message);
if(error.message.search("412") !== -1) {
if(error.message.search("412") !== -1) {
 
MicroModal.close();
this.replaceModalDialog(file, directory);
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) {
@@ -465,15 +474,8 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
console.log("zeig uns an.");
console.log("zeig uns an.");
this.uploadFileObject = file;
this.uploadFileObject = file;
this.uploadFileDirectory = directory;
this.uploadFileDirectory = directory;
this.replaceFilename = file.name;
this.isDialogOpen = true;
MicroModal.show(this._('#replace-modal'));
/*MicroModal.init({
onShow: modal => { this.isDialogOpen = true },
onClose: modal => { this.isDialogOpen = false; },
});*/
MicroModal.show(this._('#replace-modal'), {
onClose: modal => { this.isDialogOpen = false; }
});
console.log("dialog is open? ", this.isDialogOpen);
console.log("dialog is open? ", this.isDialogOpen);
}
}
Loading