add website part of log view

This commit is contained in:
Empire 2025-03-20 22:47:39 +01:00
parent 67c653fa8b
commit 8ff2763580
2 changed files with 54 additions and 0 deletions
rust/src_webpack/src

@ -0,0 +1,7 @@
<style>
</style>
<button id="loadLog">Load Logs</button>
<div id="logpanel">
</div>

@ -0,0 +1,47 @@
import { Controller } from "./main";
export class LogView {
private readonly logpanel: HTMLElement;
private readonly loadLog: HTMLButtonElement;
loglocale: LogLocalisation | undefined;
constructor(controller: Controller) {
(document.getElementById("logview") as HTMLElement).innerHTML = require('./log.html') as string;
this.logpanel = document.getElementById("logpanel") as HTMLElement
this.loadLog = document.getElementById("loadLog") as HTMLButtonElement
controller.loadLogLocaleConfig();
this.loadLog.onclick = () => {
controller.loadLog();
}
}
setLogLocalisation(loglocale: LogLocalisation) {
this.loglocale = loglocale;
}
setLog(logs: LogArray) {
this.logpanel.textContent = ""
logs.forEach(entry => {
let message = this.loglocale!![entry.message_id];
let template = message.message
template = template.replace("${number_a}", entry.a.toString());
template = template.replace("${number_b}", entry.b.toString());
template = template.replace("${txt_short}", entry.txt_short.toString());
template = template.replace("${txt_long}", entry.txt_long.toString());
let ts = new Date(entry.timestamp);
let div = document.createElement("div")
let timestampDiv = document.createElement("div")
let messageDiv = document.createElement("div")
timestampDiv.innerText = ts.toISOString();
messageDiv.innerText = template;
div.appendChild(timestampDiv)
div.appendChild(messageDiv)
this.logpanel.appendChild(div)
}
)
}
}