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=>{ this.#rootdoc.addEventListener("drop", ev=>{
if(ev.dataTransfer && ev.dataTransfer.getData('text/plain+ccpmethod')){ if(ev.dataTransfer && ev.dataTransfer.files.length === 0){
const method = JSON.parse(ev.dataTransfer.getData('application/json+ccpmethod')) if(ev.dataTransfer.getData('text/plain+ccpmethod')){
ev.stopImmediatePropagation() const method = JSON.parse(ev.dataTransfer.getData('application/json+ccpmethod'))
ev.preventDefault() ev.stopImmediatePropagation()
ev.stopPropagation() ev.preventDefault()
this.cloneOrEditMethod(method) 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=>{ 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 = { #process_list_bss = {
template : "#PROCESS_LIST_TEMPLATE", template : "#PROCESS_LIST_TEMPLATE",
target : "ul[name=process_category_list]", target : "ul[name=process_category_list]",
"in" : this, "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 : [ recurse : [
{ {
target : "li", target : "li",