added support for result download

This commit is contained in:
dcore94 2022-05-05 13:00:44 +02:00
parent bb6427afaa
commit 163982ace6
1 changed files with 27 additions and 3 deletions

View File

@ -49,7 +49,7 @@ class CCPExecutionMonitor extends HTMLElement {
refreshExecution(execution){ refreshExecution(execution){
this.#boot.secureFetch(execution.self).then(reply =>{ this.#boot.secureFetch(execution.self).then(reply =>{
if(reply.status === 200) return reply.json(); if(reply.status === 200) return reply.json();
else throw "Unable to load job links" + reply.text else throw "Unable to load job links"
}).then(data=>{ }).then(data=>{
execution.links = data execution.links = data
BSS.apply(this.execution_list_bss, this.#rootdoc) BSS.apply(this.execution_list_bss, this.#rootdoc)
@ -70,6 +70,26 @@ class CCPExecutionMonitor extends HTMLElement {
window.setInterval( ()=>this.#socket.send("ping"), 30000) window.setInterval( ()=>this.#socket.send("ping"), 30000)
} }
download(url, name) {
this.#boot.secureFetch(url).then(reply => {
if (reply.status !== 200) {
throw "Unable to download"
}
return reply.blob()
}).then(blob => {
const objectURL = URL.createObjectURL(blob)
var tmplnk = document.createElement("a")
tmplnk.download = name
tmplnk.href = objectURL
//tmplnk.target="_blank"
document.body.appendChild(tmplnk)
tmplnk.click()
document.body.removeChild(tmplnk)
}).catch(err => console.error(err))
}
execution_list_bss = { execution_list_bss = {
template : "#EXECUTIOM_LIST_TEMPLATE", template : "#EXECUTIOM_LIST_TEMPLATE",
target : "ol[name=ccp_execution_list]", target : "ol[name=ccp_execution_list]",
@ -117,9 +137,13 @@ class CCPExecutionMonitor extends HTMLElement {
{ {
target : "li", target : "li",
"in" : (e,d)=>{return d.links.map(l=>{ return { href : d.self + "/" + l.path, path : l.path} })}, "in" : (e,d)=>{return d.links.map(l=>{ return { href : d.self + "/" + l.path, path : l.path} })},
on_click : ev=>{
const href = ev.currentTarget.bss_input.data.href
const name = ev.currentTarget.bss_input.data.path
this.download(href, name)
},
apply : (e,d)=>{ apply : (e,d)=>{
console.log("applying", e, d) e.innerHTML = `<a href="${d.href}" onclick="event.preventDefault()">${d.path}</a>`
e.innerHTML = `<a href="${d.href}">${d.path}</a>`
} }
} }
] ]