diff --git a/ccp/js/executionhistorycontroller.js b/ccp/js/executionhistorycontroller.js index 3d60174..5694001 100644 --- a/ccp/js/executionhistorycontroller.js +++ b/ccp/js/executionhistorycontroller.js @@ -79,9 +79,9 @@ class CCPExecutionHistory extends HTMLElement { - + @@ -302,6 +313,24 @@ class CCPExecutionHistory extends HTMLElement { } } + generateCode(id, mime){ + this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}/code`, + { method: "GET", headers : { "Accept" : mime} }).then(reply =>{ + if (reply.status !== 200) { + throw "Unable to generate code for " + mime + } + return reply.blob() + }).then(blob => { + const objectURL = URL.createObjectURL(blob) + var tmplnk = document.createElement("a") + tmplnk.download = filename + tmplnk.href = objectURL + document.body.appendChild(tmplnk) + tmplnk.click() + document.body.removeChild(tmplnk) + }).catch(err=>{ alert(err)}) + } + #execution_list_bss = { template : "#EXECUTIOM_LIST_TEMPLATE", target : "ul[name=ccp_execution_list]", @@ -485,6 +514,15 @@ class CCPExecutionHistory extends HTMLElement { e.classList.add(t2) } }, + { + target : "button[name=codegen]", + apply : (e,d)=>e.setAttribute("data-index", d.id), + on_click: (ev)=>{ + const id = ev.target.getAttribute("data-index") + const lang = ev.target.parentElement.querySelector("select[name=language-selector]") + this.generateCode(id, lang) + } + }, { target : "ul", recurse : [ @@ -513,4 +551,4 @@ class CCPExecutionHistory extends HTMLElement { ] } } -window.customElements.define('d4s-ccp-executionhistory', CCPExecutionHistory); +window.customElements.define('d4s-ccp-executionhistory', CCPExecutionHistory); \ No newline at end of file