From 73b80a4567c53c5b74e1b433f7da6980a1fc6c3d Mon Sep 17 00:00:00 2001 From: dcore94 Date: Fri, 21 Apr 2023 17:31:02 +0200 Subject: [PATCH] added triggers for archiving and unarchiving methods and for uploading from file --- ccp/js/methodlistcontroller.js | 76 +++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/ccp/js/methodlistcontroller.js b/ccp/js/methodlistcontroller.js index 8bd9b2b..8e1a3b9 100644 --- a/ccp/js/methodlistcontroller.js +++ b/ccp/js/methodlistcontroller.js @@ -8,6 +8,9 @@ class CCPMethodList extends HTMLElement{ #searchfield = null; #allowedit = false; #allowexecute = false; + #archive = false; + #fileupload = null; + #archiveupload = null; #serviceurl; @@ -16,6 +19,7 @@ class CCPMethodList extends HTMLElement{ this.#boot = document.querySelector("d4s-boot-2") this.#serviceurl = this.getAttribute("serviceurl") this.#rootdoc = this.attachShadow({ "mode" : "open"}) + this.#archive = this.getAttribute("archive") this.render() this.fetchProcesses() } @@ -73,6 +77,12 @@ class CCPMethodList extends HTMLElement{ + ${ this.#archive ? ` + ` + : `` + }

@@ -89,15 +99,25 @@ class CCPMethodList extends HTMLElement{
-
+
- List of available methods + Methods
-
+
+ + +
+ + +
@@ -120,6 +140,25 @@ class CCPMethodList extends HTMLElement{ this.#searchfield.addEventListener("input", ev=>{ this.updateList() }) + + this.#fileupload = this.#rootdoc.querySelector("label[name=fileupload] > input[type=file]") + this.#fileupload.addEventListener("change", ev=>{ + const filelist = ev.target.files; + if (filelist.length > 0) { + const files = Array.prototype.slice.call(filelist) + this.importMethods(files) + } + }) + + this.#archiveupload = this.#rootdoc.querySelector("button[name=archive]") + this.#archiveupload.addEventListener("click", ev=>{ + const link = ev.target.parentElement.querySelector("input").value + if(link){ + if(confirm("Confirm importing of method from link?")){ + this.fromArchive(link) + } + } + }) } connectedCallback(){ @@ -258,6 +297,29 @@ class CCPMethodList extends HTMLElement{ } } + toArchive(id){ + this.#boot.secureFetch(`${this.#serviceurl}/methods/${id}/archive`, { method: "POST" }) + .then(reply =>{ + if (reply.status !== 200) { + throw "Unable to archive" + } + }).catch(err=>{ alert(err)}) + } + + fromArchive(url){ + if(url){ + this.#boot.secureFetch(`${this.#serviceurl}/methods/archive?url=${url}`) + .then(reply =>{ + if (reply.status !== 200) { + throw "Unable to fetch from archive" + } + return reply.text() + }).then(data=>{ + this.fetchProcesses() + }).catch(err=>{ alert(err)}) + } + } + #process_list_bss = { template : "#PROCESS_LIST_TEMPLATE", target : "ul[name=process_category_list]", @@ -329,6 +391,10 @@ class CCPMethodList extends HTMLElement{ }else if(ev.target.getAttribute("name") === "edit"){ const event = new CustomEvent('neweditrequest', { detail: ev.currentTarget.bss_input.data }); document.dispatchEvent(event) + }else if(ev.target.getAttribute("name") === "archive"){ + if(confirm("Confirm archiving of method to workspace?")){ + this.toArchive(id) + } } }, on_dragstart : ev=>{ @@ -386,4 +452,4 @@ class CCPMethodList extends HTMLElement{ } } -window.customElements.define('d4s-ccp-methodlist', CCPMethodList); +window.customElements.define('d4s-ccp-methodlist', CCPMethodList); \ No newline at end of file