Merge branch 'ccp-features' of https://code-repo.d4science.org/gCubeSystem/cdn-experiments into ccp-features

This commit is contained in:
dcore94 2023-06-23 15:36:55 +02:00
commit 242753e3dc
2 changed files with 31 additions and 5 deletions

View File

@ -115,7 +115,7 @@ class CCPExecutionHistory extends HTMLElement {
<span class="badge" name="runtime" alt="Runtime" title="Runtime"></span> <span class="badge" name="runtime" alt="Runtime" title="Runtime"></span>
</div> </div>
<div style="margin:5px 0 5px 0"> <div style="margin:5px 0 5px 0">
<d4s-ccp-logterminal maxlines="10"></d4s-ccp-logterminal> <d4s-ccp-logterminal maxstoredlines="100" maxlines="10"></d4s-ccp-logterminal>
</div> </div>
<ul> <ul>
<li></li> <li></li>
@ -278,7 +278,7 @@ class CCPExecutionHistory extends HTMLElement {
this.#socket.onmessage = event=>{ this.#socket.onmessage = event=>{
const data = JSON.parse(event.data) const data = JSON.parse(event.data)
if(data[0].source){ if(data[0] && data[0].source){
//has to be logs //has to be logs
this.appendLogs(data) this.appendLogs(data)
return return
@ -312,7 +312,7 @@ class CCPExecutionHistory extends HTMLElement {
appendLogs(data){ appendLogs(data){
if(!data.length) return; if(!data.length) return;
const exid = data[0]["attrs"]["execution"] const exid = data[0]["attrs"]["execution"]
const lt = this.#rootdoc.querySelector(`li.ccp.execution-item#${exid} d4s-ccp-logterminal`) const lt = this.#rootdoc.querySelector(`d4s-ccp-logterminal[index=${exid}]`)
if(!lt){ if(!lt){
console.error("No terminal found for adding logs of " + exid) console.error("No terminal found for adding logs of " + exid)
}else{ }else{
@ -648,6 +648,12 @@ class CCPExecutionHistory extends HTMLElement {
this.generateCode(id, lang, `${id}.${ext}`) this.generateCode(id, lang, `${id}.${ext}`)
} }
}, },
{
target : "d4s-ccp-logterminal",
apply : (e,d)=>{
e.setAttribute("index", d.id)
}
},
{ {
target : "ul", target : "ul",
recurse : [ recurse : [

View File

@ -1,18 +1,22 @@
class LogTerminal extends HTMLElement { class LogTerminal extends HTMLElement {
#maxlines = 10; #maxlines = 10;
#maxstoredlines = 100;
#rootdoc = null; #rootdoc = null;
#lines = [] #lines = [];
#index = null;
constructor(){ constructor(){
super() super()
this.#maxlines = this.getAttribute("maxlines") this.#maxlines = this.getAttribute("maxlines")
this.#rootdoc = this.attachShadow({ "mode" : "open"}) this.#rootdoc = this.attachShadow({ "mode" : "open"})
this.render() this.render()
this.#index = this.getAttribute("index")
} }
connectedCallback(){ connectedCallback(){
this.reloadLines()
this.refresh()
} }
get lines(){ get lines(){
@ -22,6 +26,22 @@ class LogTerminal extends HTMLElement {
addLines(lines){ addLines(lines){
this.#lines = this.#lines.concat(lines) this.#lines = this.#lines.concat(lines)
this.refresh() this.refresh()
this.storeLines()
}
reloadLines(){
if(sessionStorage.getItem("logs-" + this.#index)){
this.#lines = sessionStorage.getItem("logs-" + this.#index)
}else{
this.#lines = []
}
}
storeLines(){
if(this.#lines.length > this.#maxstoredlines){
this.#lines.splice(0, this.#lines.length - this.#maxstoredlines)
}
sessionStorage.setItem("logs-" + this.#index, this.#lines)
} }
render(){ render(){