From 2665ac4d58ae4e24dd8828c769553ae14b312235 Mon Sep 17 00:00:00 2001 From: dcore94 Date: Thu, 9 Feb 2023 13:20:14 +0100 Subject: [PATCH] added drop support for importing methods --- ccp/js/methodeditorcontroller.js | 22 +++++++++++++------ ccp/js/methodlistcontroller2.js | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) 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",