added drop support for importing methods
This commit is contained in:
parent
1cd4196765
commit
2665ac4d58
|
@ -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=>{
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue