diff --git a/ccp/js/methodeditorcontroller.js b/ccp/js/methodeditorcontroller.js index c01cf7f..22936a7 100644 --- a/ccp/js/methodeditorcontroller.js +++ b/ccp/js/methodeditorcontroller.js @@ -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=>{ diff --git a/ccp/js/methodlistcontroller2.js b/ccp/js/methodlistcontroller2.js index ff36ed0..2f9e862 100644 --- a/ccp/js/methodlistcontroller2.js +++ b/ccp/js/methodlistcontroller2.js @@ -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",