added drop support for importing methods

This commit is contained in:
dcore94 2023-02-09 13:20:14 +01:00
parent 1cd4196765
commit 2665ac4d58
2 changed files with 52 additions and 7 deletions

View File

@ -535,13 +535,21 @@ class CCPMethodEditorController extends HTMLElement{
})
this.#rootdoc.addEventListener("drop", ev=>{
if(ev.dataTransfer && ev.dataTransfer.getData('text/plain+ccpmethod')){
const method = JSON.parse(ev.dataTransfer.getData('application/json+ccpmethod'))
ev.stopImmediatePropagation()
ev.preventDefault()
ev.stopPropagation()
this.cloneOrEditMethod(method)
}
if(ev.dataTransfer && ev.dataTransfer.files.length === 0){
if(ev.dataTransfer.getData('text/plain+ccpmethod')){
const method = JSON.parse(ev.dataTransfer.getData('application/json+ccpmethod'))
ev.stopImmediatePropagation()
ev.preventDefault()
ev.stopPropagation()
this.cloneOrEditMethod(method)
}
} else {
const files = Array.prototype.slice.call(ev.dataTransfer.files)
const jsons = files.filter(f=>f.type === "application/json")
if(confirm("Confirm import of method files?")){
this.importMethodsfiles)
}
}
})
this.#rootdoc.addEventListener("dragover", ev=>{

View File

@ -194,10 +194,47 @@ class CCPMethodList2 extends HTMLElement{
}, {})
}
importMethods(files){
if(files && files.length) {
let formdata = new FormData();
files.reduce((formdata, f)=>{
formdata.append("files[]", f)
return formdata
}, formdata)
this.#boot.secureFetch(`${this.#serviceurl}/methods`, { body: formdata, method : "POST"})
.then(reply=>{
if (reply.status !== 200) {
throw "Unable to import"
}else return reply.text()
}).then(data=>{
this.refreshExecutions()
}).catch(err=>{ alert(err) })
}
}
#process_list_bss = {
template : "#PROCESS_LIST_TEMPLATE",
target : "ul[name=process_category_list]",
"in" : this,
on_dragover : (ev)=>{
ev.preventDefault()
},
on_dragenter : (ev)=>{
ev.target.classList.toggle("border-info")
},
on_dragleave : (ev)=>{
ev.target.classList.toggle("border-info")
},
on_drop : (ev)=>{
if(ev.dataTransfer && ev.dataTransfer.files && ev.dataTransfer.files.length){
const files = Array.prototype.slice.call(ev.dataTransfer.files)
const zips = files.filter(f=>f.type === "application/json")
if(confirm("Confirm import of method files?")){
this.importMethods(files)
}
}
ev.target.classList.toggle("border-info")
},
recurse : [
{
target : "li",