fixed several issues with rendering and synch

This commit is contained in:
dcore94 2023-06-23 16:40:02 +02:00
parent 242753e3dc
commit c96c98c38b
2 changed files with 19 additions and 11 deletions

View File

@ -114,8 +114,7 @@ class CCPExecutionHistory extends HTMLElement {
<span style="text-overflow:ellipsis" class="badge badge-light text-info border border-info" name="infrastructure" alt="Infrastructure" title="Infrastructure"></span> <span style="text-overflow:ellipsis" class="badge badge-light text-info border border-info" name="infrastructure" alt="Infrastructure" title="Infrastructure"></span>
<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 name="logterminalcontainer" style="margin:5px 0 5px 0">
<d4s-ccp-logterminal maxstoredlines="100" maxlines="10"></d4s-ccp-logterminal>
</div> </div>
<ul> <ul>
<li></li> <li></li>
@ -312,7 +311,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(`d4s-ccp-logterminal[index=${exid}]`) 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{
@ -649,9 +648,9 @@ class CCPExecutionHistory extends HTMLElement {
} }
}, },
{ {
target : "d4s-ccp-logterminal", target : "div[name=logterminalcontainer]",
apply : (e,d)=>{ apply : (e,d)=>{
e.setAttribute("index", d.id) e.innerHTML = `<d4s-ccp-logterminal index="${d.id}" maxstoredlines="100" maxlines="10"></d4s-ccp-logterminal>`
} }
}, },
{ {

View File

@ -6,12 +6,13 @@ class LogTerminal extends HTMLElement {
#lines = []; #lines = [];
#index = null; #index = null;
static get observedAttributes() { return ['index']; }
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(){
@ -19,6 +20,13 @@ class LogTerminal extends HTMLElement {
this.refresh() this.refresh()
} }
attributeChangedCallback(name, oldValue, newValue) {
if(name === "index"){
this.#index = newValue
this.reloadLines()
}
}
get lines(){ get lines(){
return this.#lines return this.#lines
} }
@ -30,8 +38,9 @@ class LogTerminal extends HTMLElement {
} }
reloadLines(){ reloadLines(){
if(this.#index == null) return;
if(sessionStorage.getItem("logs-" + this.#index)){ if(sessionStorage.getItem("logs-" + this.#index)){
this.#lines = sessionStorage.getItem("logs-" + this.#index) this.#lines = JSON.parse(sessionStorage.getItem("logs-" + this.#index))
}else{ }else{
this.#lines = [] this.#lines = []
} }
@ -41,7 +50,7 @@ class LogTerminal extends HTMLElement {
if(this.#lines.length > this.#maxstoredlines){ if(this.#lines.length > this.#maxstoredlines){
this.#lines.splice(0, this.#lines.length - this.#maxstoredlines) this.#lines.splice(0, this.#lines.length - this.#maxstoredlines)
} }
sessionStorage.setItem("logs-" + this.#index, this.#lines) sessionStorage.setItem("logs-" + this.#index, JSON.stringify(this.#lines))
} }
render(){ render(){