This commit is contained in:
@@ -67,9 +67,9 @@ CURRENT TODOs
|
||||
@@@@@@@@@@@ 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: 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
|
||||
|
||||
|
||||
@@ -165,6 +165,7 @@ export default {
|
||||
return "height: " + this.height + "px;overflow-y:auto;";
|
||||
},
|
||||
upload() {
|
||||
//similar code in wiki-control
|
||||
let vm = this;
|
||||
let at = {
|
||||
ayaId: vm.ayaId,
|
||||
|
||||
@@ -384,8 +384,8 @@ export default {
|
||||
imageText: "",
|
||||
attachments: [],
|
||||
selectedImageAttachment: null,
|
||||
|
||||
dropTest: null
|
||||
notes: null, //attachment upload notes
|
||||
uploadFiles: [] //attachment upload files
|
||||
};
|
||||
},
|
||||
props: {
|
||||
@@ -853,61 +853,129 @@ export default {
|
||||
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) {
|
||||
//Drop image file
|
||||
var files = Array.from(ev.dataTransfer.files);
|
||||
if (files.length > 0) {
|
||||
//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
|
||||
} else {
|
||||
//maybe an url?
|
||||
let url = ev.dataTransfer.getData("text");
|
||||
this.insertUrl(url);
|
||||
}
|
||||
},
|
||||
insertUrl(url, name) {
|
||||
if (url) {
|
||||
let isImageUrl = false;
|
||||
|
||||
if (url) {
|
||||
//Attachment?
|
||||
if (url.includes("Attachment/download/")) {
|
||||
//it's an attachment url so fixup accordingly
|
||||
//i paramter added by gzapi::downloadUrl function
|
||||
isImageUrl = url.includes("&i=");
|
||||
let m = url.match(/Attachment\/download\/(.*)\?t=/);
|
||||
if (m.length > 1) {
|
||||
url = "[ATTACH:" + m[1] + "]";
|
||||
//Attachment?
|
||||
if (url.includes("Attachment/download/")) {
|
||||
//it's an attachment url so fixup accordingly
|
||||
//i paramter added by gzapi::downloadUrl function
|
||||
isImageUrl = url.includes("&i=");
|
||||
let m = url.match(/Attachment\/download\/(.*)\?t=/);
|
||||
if (m.length > 1) {
|
||||
url = "[ATTACH:" + m[1] + "]";
|
||||
} else {
|
||||
url = null;
|
||||
}
|
||||
} else {
|
||||
//External url, sniff out if it's an image
|
||||
isImageUrl = window.$gz.util.isImageAttachment(url);
|
||||
}
|
||||
if (url != null) {
|
||||
//insert into textarea
|
||||
let txt = this.getSelectedText();
|
||||
if (!txt) {
|
||||
txt = name;
|
||||
}
|
||||
if (txt) {
|
||||
if (isImageUrl) {
|
||||
this.replaceSelectedText(
|
||||
" \n' + txt + "\n" //keep original selected text otherwise it will vanish
|
||||
);
|
||||
} else {
|
||||
url = null;
|
||||
//regular url not image
|
||||
this.replaceSelectedText(
|
||||
"[" + txt + "](" + url + ' "' + txt + '")\n'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
//External url, sniff out if it's an image
|
||||
isImageUrl = window.$gz.util.isImageAttachment(url);
|
||||
}
|
||||
if (url != null) {
|
||||
//insert into textarea
|
||||
let txt = this.getSelectedText();
|
||||
if (txt) {
|
||||
if (isImageUrl) {
|
||||
this.replaceSelectedText(
|
||||
" \n' + txt //keep original selected text otherwise it will vanish
|
||||
);
|
||||
} else {
|
||||
//regular url not image
|
||||
this.replaceSelectedText(
|
||||
"[" + txt + "](" + url + ' "' + txt + '")\n'
|
||||
);
|
||||
}
|
||||
//No selected text
|
||||
if (isImageUrl) {
|
||||
this.replaceSelectedText("\n");
|
||||
} else {
|
||||
//No selected text
|
||||
if (isImageUrl) {
|
||||
this.replaceSelectedText("\n");
|
||||
} else {
|
||||
//regular no text non image url
|
||||
this.replaceSelectedText("<" + url + ">\n");
|
||||
}
|
||||
//regular no text non image url
|
||||
this.replaceSelectedText("<" + url + ">\n");
|
||||
}
|
||||
}
|
||||
|
||||
//handle accordingly
|
||||
}
|
||||
|
||||
//handle accordingly
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user