added management of line storage and limit for max lines

This commit is contained in:
dcore94 2023-06-23 15:35:28 +02:00
parent d095d00d7d
commit 87932992e7
2 changed files with 31 additions and 5 deletions

View File

@ -112,7 +112,7 @@ class CCPExecutionHistory extends HTMLElement {
<span class="badge" name="runtime" alt="Runtime" title="Runtime"></span>
</div>
<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>
<ul>
<li></li>
@ -275,7 +275,7 @@ class CCPExecutionHistory extends HTMLElement {
this.#socket.onmessage = event=>{
const data = JSON.parse(event.data)
if(data[0].source){
if(data[0] && data[0].source){
//has to be logs
this.appendLogs(data)
return
@ -309,7 +309,7 @@ class CCPExecutionHistory extends HTMLElement {
appendLogs(data){
if(!data.length) return;
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){
console.error("No terminal found for adding logs of " + exid)
}else{
@ -630,6 +630,12 @@ class CCPExecutionHistory extends HTMLElement {
this.generateCode(id, lang, `${id}.${ext}`)
}
},
{
target : "d4s-ccp-logterminal",
apply : (e,d)=>{
e.setAttribute("index", d.id)
}
},
{
target : "ul",
recurse : [

View File

@ -1,18 +1,22 @@
class LogTerminal extends HTMLElement {
#maxlines = 10;
#maxstoredlines = 100;
#rootdoc = null;
#lines = []
#lines = [];
#index = null;
constructor(){
super()
this.#maxlines = this.getAttribute("maxlines")
this.#rootdoc = this.attachShadow({ "mode" : "open"})
this.render()
this.#index = this.getAttribute("index")
}
connectedCallback(){
this.reloadLines()
this.refresh()
}
get lines(){
@ -22,6 +26,22 @@ class LogTerminal extends HTMLElement {
addLines(lines){
this.#lines = this.#lines.concat(lines)
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(){