support also dropping of execution objects

This commit is contained in:
dcore94 2023-02-02 12:30:38 +01:00
parent c243983942
commit be2f797d38
1 changed files with 76 additions and 29 deletions

View File

@ -65,20 +65,7 @@ class CCPExecutionForm extends HTMLElement{
</div> </div>
</div> </div>
</div> </div>
<!--div class="card"> <button id="execute_method_button" class="btn btn-info">Execute</button>
<div class="card-header">
<h5>Runtimes <span alt="refresh" title="refresh" style="cursor:pointer" name="refresh-runtimes" class="text-info">&#8634;</span></h5>
</div>
<div class="card-body">
<div class="ccp-runtimes">
<div class="form-row">
<select class="form-control">
</select>
</div>
</div>
</div>
</div-->
<button id="execute_method_button" class="btn btn-info">Execute</button>
</form> </form>
</div> </div>
</template> </template>
@ -93,7 +80,7 @@ class CCPExecutionForm extends HTMLElement{
} }
loadMethod(){ loadMethod(){
this.#boot.secureFetch(this.#serviceurl + "/processes/" + this.#method).then( return this.#boot.secureFetch(this.#serviceurl + "/processes/" + this.#method).then(
(resp)=>{ (resp)=>{
if(resp.status === 200){ if(resp.status === 200){
return resp.json() return resp.json()
@ -122,7 +109,6 @@ class CCPExecutionForm extends HTMLElement{
showMethod(){ showMethod(){
if(this.#method == null) this.showEmpty(); if(this.#method == null) this.showEmpty();
else{ else{
console.log(this.#data)
BSS.apply(this.#executionform_bss, this.#rootdoc) 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")) 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 = { #empty_executionform_bss = {
template : "#EXECUTION_FORM_EMPTY_TEMPLATE", template : "#EXECUTION_FORM_EMPTY_TEMPLATE",
target : "div[name=execution_form]", target : "div[name=execution_form]",
on_drop : ev=>{ on_drop : ev=>{
if(ev.dataTransfer && ev.dataTransfer.getData('text/plain+ccpmethod')){ if(ev.dataTransfer){
const id = ev.dataTransfer.getData('text/plain+ccpmethod') if(ev.dataTransfer.getData('text/plain+ccpmethod')){
this.setAttribute("method", id); const id = ev.dataTransfer.getData('text/plain+ccpmethod')
ev.preventDefault() this.setAttribute("method", id);
ev.stopPropagation() ev.preventDefault()
ev.currentTarget.style.backgroundColor = "white" 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=>{ on_dragover : ev=>{
@ -198,11 +238,18 @@ class CCPExecutionForm extends HTMLElement{
target : "div[name=execution_form]", target : "div[name=execution_form]",
in : ()=>this.#data, in : ()=>this.#data,
on_drop : ev=>{ on_drop : ev=>{
if(ev.dataTransfer && ev.dataTransfer.getData('text/plain+ccpmethod')){ if(ev.dataTransfer){
const id = ev.dataTransfer.getData('text/plain+ccpmethod'); if(ev.dataTransfer.getData('text/plain+ccpmethod')){
this.setAttribute("method", id); const id = ev.dataTransfer.getData('text/plain+ccpmethod');
ev.preventDefault() this.setAttribute("method", id);
ev.stopPropagation() 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=>{ on_dragover : ev=>{
@ -225,7 +272,7 @@ class CCPExecutionForm extends HTMLElement{
"in" : (e,d)=>{ return Object.values(d.inputs) }, "in" : (e,d)=>{ return Object.values(d.inputs) },
target : "div", target : "div",
apply : (e,d)=>{ apply : (e,d)=>{
e.innerHTML = `<d4s-ccp-input input='${JSON.stringify(d)}'></d4s-ccp-input>` e.innerHTML = `<d4s-ccp-input name="${d.id}" input='${JSON.stringify(d)}'></d4s-ccp-input>`
} }
} }
] ]
@ -238,7 +285,7 @@ class CCPExecutionForm extends HTMLElement{
"in" : (e,d)=>{ return Object.values(d.outputs) }, "in" : (e,d)=>{ return Object.values(d.outputs) },
target : "div", target : "div",
apply : (e,d)=>{ apply : (e,d)=>{
e.innerHTML = `<d4s-ccp-output output='${JSON.stringify(d)}'></d4s-ccp-output>` e.innerHTML = `<d4s-ccp-output name="${d.id}" output='${JSON.stringify(d)}'></d4s-ccp-output>`
} }
} }
] ]