This commit is contained in:
2020-04-24 20:46:56 +00:00
parent b7d4cd9f6c
commit 3c01876a09
3 changed files with 110 additions and 41 deletions

View File

@@ -67,9 +67,9 @@ CURRENT TODOs
@@@@@@@@@@@ ROADMAP STAGE 2: @@@@@@@@@@@ ROADMAP STAGE 2:
todo: drag and drop files on to attachments and have them stored and added automatically
todo: drag and drop image file on to wiki and have it added as attachment then linked automatically todo: drag and drop image file on to wiki and have it added as attachment then linked automatically
todo: Attachments control, sb minimized on parent form open and only do it's thing when expanded like wiki todo: Attachments control, sb minimized on parent form open and only do it's thing when expanded like wiki
- i.e. don't bother fetching until the user expands it - i.e. don't bother fetching until the user expands it

View File

@@ -165,6 +165,7 @@ export default {
return "height: " + this.height + "px;overflow-y:auto;"; return "height: " + this.height + "px;overflow-y:auto;";
}, },
upload() { upload() {
//similar code in wiki-control
let vm = this; let vm = this;
let at = { let at = {
ayaId: vm.ayaId, ayaId: vm.ayaId,

View File

@@ -384,8 +384,8 @@ export default {
imageText: "", imageText: "",
attachments: [], attachments: [],
selectedImageAttachment: null, selectedImageAttachment: null,
notes: null, //attachment upload notes
dropTest: null uploadFiles: [] //attachment upload files
}; };
}, },
props: { props: {
@@ -853,19 +853,85 @@ export default {
window.$gz.errorHandler.handleFormError(error); window.$gz.errorHandler.handleFormError(error);
}); });
}, },
upload() {
//similar code in attachment-control upload
let vm = this;
let at = {
ayaId: vm.ayaId,
ayaType: vm.ayaType,
files: vm.uploadFiles,
notes: ""
};
window.$gz.api
.uploadAttachment(at)
.then(res => {
if (res.error) {
window.$gz.errorHandler.handleFormError(res.error);
} else {
let ret = [];
for (let i = 0; i < res.data.length; i++) {
let o = res.data[i];
// if (
// window.$gz.util.isImageAttachment(
// o.displayFileName,
// o.contentType
// )
// ) {
//let them attach any file type to the wiki since it supports it anyway
ret.push({
id: o.id,
url: window.$gz.api.downloadUrl(o.id, o.contentType),
name: o.displayFileName
});
//}
}
//put into attachments list
vm.attachments = ret;
//NOW iterate upload files list and insert into wiki based on attachments
//insert into wiki
for (let i = 0; i < vm.uploadFiles.length; i++) {
let upFile = vm.uploadFiles[i];
for (let j = 0; j < vm.attachments.length; j++) {
let atFile = vm.attachments[j];
if (upFile.name == atFile.name) {
//found it
console.log("upload inserting found file:", atFile);
this.insertUrl(atFile.url, atFile.name);
break;
}
}
}
//finally, clear the upload files
vm.uploadFiles = [];
}
})
.catch(function handleUploadError(error) {
window.$gz.errorHandler.handleFormError(error);
});
},
onDrop(ev) { onDrop(ev) {
//Drop image file //Drop image file
var files = Array.from(ev.dataTransfer.files); var files = Array.from(ev.dataTransfer.files);
if (files.length > 0) { if (files.length > 0) {
//handle file drop //handle file drop
console.log("DROP:Possible files", files); var files = Array.from(ev.dataTransfer.files);
if (files.length > 0) {
this.uploadFiles = files;
this.upload();
}
//if an image then put it directly in viewable, if not an image then make a link and keep as an attach //if an image then put it directly in viewable, if not an image then make a link and keep as an attach
} else { } else {
//maybe an url? //maybe an url?
let url = ev.dataTransfer.getData("text"); let url = ev.dataTransfer.getData("text");
let isImageUrl = false; this.insertUrl(url);
}
},
insertUrl(url, name) {
if (url) { if (url) {
let isImageUrl = false;
//Attachment? //Attachment?
if (url.includes("Attachment/download/")) { if (url.includes("Attachment/download/")) {
//it's an attachment url so fixup accordingly //it's an attachment url so fixup accordingly
@@ -884,10 +950,13 @@ export default {
if (url != null) { if (url != null) {
//insert into textarea //insert into textarea
let txt = this.getSelectedText(); let txt = this.getSelectedText();
if (!txt) {
txt = name;
}
if (txt) { if (txt) {
if (isImageUrl) { if (isImageUrl) {
this.replaceSelectedText( this.replaceSelectedText(
"![" + txt + "](" + url + ' "' + txt + '") \n' + txt //keep original selected text otherwise it will vanish "![" + txt + "](" + url + ' "' + txt + '") \n' + txt + "\n" //keep original selected text otherwise it will vanish
); );
} else { } else {
//regular url not image //regular url not image
@@ -909,7 +978,6 @@ export default {
//handle accordingly //handle accordingly
} }
} }
}
//----------end methods---------- //----------end methods----------
} }