diff --git a/ccp/js/executionformcontroller.js b/ccp/js/executionformcontroller.js index ec7b215..e96f959 100644 --- a/ccp/js/executionformcontroller.js +++ b/ccp/js/executionformcontroller.js @@ -65,20 +65,7 @@ class CCPExecutionForm extends HTMLElement{ - - + @@ -93,7 +80,7 @@ class CCPExecutionForm extends HTMLElement{ } loadMethod(){ - this.#boot.secureFetch(this.#serviceurl + "/processes/" + this.#method).then( + return this.#boot.secureFetch(this.#serviceurl + "/processes/" + this.#method).then( (resp)=>{ if(resp.status === 200){ return resp.json() @@ -122,7 +109,6 @@ class CCPExecutionForm extends HTMLElement{ showMethod(){ if(this.#method == null) this.showEmpty(); else{ - console.log(this.#data) BSS.apply(this.#executionform_bss, this.#rootdoc) } } @@ -176,16 +162,70 @@ class CCPExecutionForm extends HTMLElement{ return Array.prototype.slice.call(this.#rootdoc.querySelectorAll("d4s-ccp-output")) } + initValues(inputs){ + Object.keys(inputs).forEach(k=>{ + const w = this.#rootdoc.querySelector(`d4s-ccp-input[name=${k}]`) + if(w){ + w.value = (inputs[k]) + } + }) + } + + prepareFromExecution(exec){ + let f1 = + this.#boot.secureFetch(this.#serviceurl + `/executions/${exec.id}/metadata/method.json`) + .then(resp=>{ + if(resp.status === 200){ + return resp.json() + }else throw "Error retrieving process" + } + ).then(data=>data) + + let f2 = + this.#boot.secureFetch(this.#serviceurl + `/executions/${exec.id}/metadata/request.json`) + .then(resp=>{ + if(resp.status === 200){ + return resp.json() + }else throw "Error retrieving process" + } + ).then(data=>data) + + var requestdata = null + Promise.all([f1, f2]).then(m_and_r => { + this.#data = m_and_r[0] + requestdata = m_and_r[1] + this.#method = this.#data.id + const rts = + this.#data.links + .filter(l => l.rel === "compatibleWith") + .map(l=>l.href.replace("runtimes/","")) + .join(" ") + return this.#boot.secureFetch(this.#serviceurl + "/infrastructures/runtimes?runtimes=" + rts) + }).then(resp=>{ + this.#data.executable = resp.status === 200 + }).then(()=>{ + this.showMethod() + this.initValues(requestdata.inputs) + }).catch(err=>alert(err)) + } + #empty_executionform_bss = { template : "#EXECUTION_FORM_EMPTY_TEMPLATE", target : "div[name=execution_form]", on_drop : ev=>{ - if(ev.dataTransfer && ev.dataTransfer.getData('text/plain+ccpmethod')){ - const id = ev.dataTransfer.getData('text/plain+ccpmethod') - this.setAttribute("method", id); - ev.preventDefault() - ev.stopPropagation() - ev.currentTarget.style.backgroundColor = "white" + if(ev.dataTransfer){ + if(ev.dataTransfer.getData('text/plain+ccpmethod')){ + const id = ev.dataTransfer.getData('text/plain+ccpmethod') + this.setAttribute("method", id); + ev.preventDefault() + ev.stopPropagation() + ev.currentTarget.style.backgroundColor = "white" + }else if(ev.dataTransfer.getData('text/plain+ccpexecution')){ + this.prepareFromExecution(JSON.parse(ev.dataTransfer.getData('application/json+ccpexecution'))) + ev.preventDefault() + ev.stopPropagation() + ev.currentTarget.style.backgroundColor = "white" + } } }, on_dragover : ev=>{ @@ -198,11 +238,18 @@ class CCPExecutionForm extends HTMLElement{ target : "div[name=execution_form]", in : ()=>this.#data, on_drop : ev=>{ - if(ev.dataTransfer && ev.dataTransfer.getData('text/plain+ccpmethod')){ - const id = ev.dataTransfer.getData('text/plain+ccpmethod'); - this.setAttribute("method", id); - ev.preventDefault() - ev.stopPropagation() + if(ev.dataTransfer){ + if(ev.dataTransfer.getData('text/plain+ccpmethod')){ + const id = ev.dataTransfer.getData('text/plain+ccpmethod'); + this.setAttribute("method", id); + ev.preventDefault() + ev.stopPropagation() + }else if(ev.dataTransfer.getData('text/plain+ccpexecution')){ + this.prepareFromExecution(JSON.parse(ev.dataTransfer.getData('application/json+ccpexecution'))) + ev.preventDefault() + ev.stopPropagation() + ev.currentTarget.style.backgroundColor = "white" + } } }, on_dragover : ev=>{ @@ -225,7 +272,7 @@ class CCPExecutionForm extends HTMLElement{ "in" : (e,d)=>{ return Object.values(d.inputs) }, target : "div", apply : (e,d)=>{ - e.innerHTML = `` + e.innerHTML = `` } } ] @@ -238,7 +285,7 @@ class CCPExecutionForm extends HTMLElement{ "in" : (e,d)=>{ return Object.values(d.outputs) }, target : "div", apply : (e,d)=>{ - e.innerHTML = `` + e.innerHTML = `` } } ]