From 79a1b0b5ac9e85ce392902a676979d077be7e364 Mon Sep 17 00:00:00 2001 From: dcore94 Date: Thu, 9 Feb 2023 12:21:39 +0100 Subject: [PATCH] added export button for methods --- ccp/js/methodeditorcontroller.js | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/ccp/js/methodeditorcontroller.js b/ccp/js/methodeditorcontroller.js index 567107f..72e33a7 100644 --- a/ccp/js/methodeditorcontroller.js +++ b/ccp/js/methodeditorcontroller.js @@ -78,6 +78,7 @@ class CCPMethodEditorController extends HTMLElement{ fill: white; width:24px; height:24px; + pointer-events: none; } .ccp-option { @@ -150,10 +151,13 @@ class CCPMethodEditorController extends HTMLElement{ ` #delete_icon = ` - + ` + #download_icon = ` + + ` constructor(){ super(); @@ -291,6 +295,31 @@ class CCPMethodEditorController extends HTMLElement{ }) } + downloadMethod(method){ + if(this.#locked) return; + this.lockRender() + var filename = this.#current.title + "-" + this.#current.version + ".json" + this.#boot.secureFetch(this.#serviceurl + "/methods/" + method + "/shareable").then( + (resp)=>{ + if(resp.status === 200){ + return resp.json() + }else throw "Error retrieving sharable process: " + resp.status + } + ).then(data=>{ + const objectURL = URL.createObjectURL(data) + var tmplnk = document.createElement("a") + tmplnk.download = filename + tmplnk.href = objectURL + document.body.appendChild(tmplnk) + tmplnk.click() + document.body.removeChild(tmplnk) + this.unlockRender() + }).catch(err=>{ + alert(err) + this.unlockRender() + }) + } + editMethod(method){ if(this.#locked) return; this.lockRender() @@ -378,6 +407,7 @@ class CCPMethodEditorController extends HTMLElement{
${this.renderSaveButton()} ${this.renderResetButton()} + ${this.renderDownloadButton()} ${ this.#isupdate ? this.renderDeleteButton() : "" }
@@ -532,6 +562,12 @@ class CCPMethodEditorController extends HTMLElement{ this.saveMethod() }) + this.#rootdoc.querySelector("button[name=download]").addEventListener("click", ev=>{ + ev.preventDefault() + ev.stopPropagation() + this.downloadMethod() + }) + if(this.#isupdate){ this.#rootdoc.querySelector("button[name=delete]").addEventListener("click", ev=>{ ev.preventDefault()