added export button for methods

This commit is contained in:
dcore94 2023-02-09 12:21:39 +01:00
parent b06f29312f
commit 79a1b0b5ac
1 changed files with 37 additions and 1 deletions

View File

@ -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{
</svg>
`
#delete_icon = `
<svg style="width:24px;height:24px;pointer-events: none;" viewBox="0 0 24 24">
<svg viewBox="0 0 24 24">
<path d="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z" />
</svg>
`
#download_icon = `
<svg viewBox="0 0 24 24"><g><rect fill="none" height="24" width="24"/></g><g><path d="M18,15v3H6v-3H4v3c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-3H18z M17,11l-1.41-1.41L13,12.17V4h-2v8.17L8.41,9.59L7,11l5,5 L17,11z"/></g></svg>
`
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{
<div class="ccp-toolbar-right">
${this.renderSaveButton()}
${this.renderResetButton()}
${this.renderDownloadButton()}
${ this.#isupdate ? this.renderDeleteButton() : "" }
</div>
</div>
@ -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()