2024-03-12 15:49:08 +01:00
|
|
|
package home
|
|
|
|
|
|
|
|
import "gitlab.unjx.de/flohoss/godash/services"
|
|
|
|
import "gitlab.unjx.de/flohoss/godash/views/layout"
|
2024-03-12 16:16:49 +01:00
|
|
|
import "gitlab.unjx.de/flohoss/godash/components/system"
|
|
|
|
import "gitlab.unjx.de/flohoss/godash/components/uptime"
|
|
|
|
import "gitlab.unjx.de/flohoss/godash/components/application"
|
|
|
|
import "gitlab.unjx.de/flohoss/godash/components/link"
|
2024-03-12 15:49:08 +01:00
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticInformation, live *services.LiveInformation) {
|
|
|
|
<section class="grid gap-14">
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3 select-none">
|
2024-03-12 16:16:49 +01:00
|
|
|
@system.System("icon-[bi--cpu]",static.CPU.Name,"",static.CPU.Threads,"systemCpuPercentage","",live.CPU)
|
|
|
|
@system.System("icon-[bi--nvme]",live.Disk.Value,fmt.Sprintf(" | %s", static.Disk.Total),static.Disk.Partitions,"systemDiskPercentage","systemDiskValue",live.Disk.Percentage)
|
|
|
|
@system.System("icon-[bi--memory]",live.Ram.Value,fmt.Sprintf(" | %s", static.Ram.Total),static.Ram.Swap,"systemRamPercentage","systemRamValue",live.Ram.Percentage)
|
|
|
|
@uptime.Uptime(static.Host.Architecture,"systemUptimePercentage",live.Uptime)
|
2024-03-12 15:49:08 +01:00
|
|
|
</div>
|
|
|
|
<div class="grid gap-4">
|
2024-03-12 16:16:49 +01:00
|
|
|
for _, a := range bookmarks.Applications {
|
2024-03-12 15:49:08 +01:00
|
|
|
<div class="grid gap-2">
|
2024-03-12 16:16:49 +01:00
|
|
|
if a.Category != "" {
|
|
|
|
<div class="heading">{ a.Category }</div>
|
2024-03-12 15:49:08 +01:00
|
|
|
}
|
|
|
|
<div class="grid-apps">
|
2024-03-12 16:16:49 +01:00
|
|
|
for _, entry := range a.Entries {
|
|
|
|
@application.Application(entry)
|
2024-03-12 15:49:08 +01:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<div class="grid-apps">
|
2024-03-12 16:16:49 +01:00
|
|
|
for _, l := range bookmarks.Links {
|
2024-03-12 15:49:08 +01:00
|
|
|
<div class="flex flex-col gap-2">
|
2024-03-12 16:16:49 +01:00
|
|
|
if l.Category != "" {
|
|
|
|
<div class="heading">{ l.Category }</div>
|
2024-03-12 15:49:08 +01:00
|
|
|
}
|
2024-03-12 16:16:49 +01:00
|
|
|
for _, entry := range l.Entries {
|
|
|
|
@link.Link(entry)
|
2024-03-12 15:49:08 +01:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<script>
|
|
|
|
let systemSSESource = null;
|
|
|
|
addEventListener('beforeunload', () => {
|
2024-03-12 16:05:20 +01:00
|
|
|
systemSSESource && systemSSESource.close();
|
2024-03-12 15:49:08 +01:00
|
|
|
});
|
|
|
|
systemSSESource = new EventSource('/sse?stream=system');
|
|
|
|
systemSSESource.onmessage = (e) => {
|
2024-03-12 16:05:20 +01:00
|
|
|
const parsed = JSON.parse(e.data);
|
|
|
|
replaceSystem(parsed);
|
2024-03-12 15:49:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// system elements
|
|
|
|
const systemCpuPercentage = document.getElementById('systemCpuPercentage');
|
|
|
|
const systemRamPercentage = document.getElementById('systemRamPercentage');
|
|
|
|
const systemRamValue = document.getElementById('systemRamValue');
|
|
|
|
const systemDiskPercentage = document.getElementById('systemDiskPercentage');
|
|
|
|
const systemDiskValue = document.getElementById('systemDiskValue');
|
|
|
|
const systemUptimePercentage = document.getElementById('systemUptimePercentage');
|
|
|
|
const uptimeDays = document.getElementById('uptimeDays');
|
|
|
|
const uptimeHours = document.getElementById('uptimeHours');
|
|
|
|
const uptimeMinutes = document.getElementById('uptimeMinutes');
|
|
|
|
const uptimeSeconds = document.getElementById('uptimeSeconds');
|
|
|
|
|
|
|
|
function replaceSystem(parsed) {
|
2024-03-12 16:05:20 +01:00
|
|
|
systemCpuPercentage.style = 'width:' + parsed.cpu + '%';
|
|
|
|
systemRamPercentage.style = 'width:' + parsed.ram.percentage + '%';
|
|
|
|
systemRamValue.innerText = parsed.ram.value;
|
|
|
|
systemDiskPercentage.style = 'width:' + parsed.disk.percentage + '%';
|
|
|
|
systemDiskValue.innerText = parsed.disk.value;
|
|
|
|
systemUptimePercentage.style = 'width:' + parsed.uptime.percentage + '%';
|
|
|
|
uptimeDays.style = '--value:' + parsed.uptime.days;
|
|
|
|
uptimeHours.style = '--value:' + parsed.uptime.hours;
|
|
|
|
uptimeMinutes.style = '--value:' + parsed.uptime.minutes;
|
|
|
|
uptimeSeconds.style = '--value:' + parsed.uptime.seconds;
|
2024-03-12 15:49:08 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
}
|
|
|
|
|
|
|
|
templ HomeIndex(
|
|
|
|
title,
|
|
|
|
version string,
|
|
|
|
bookmarks *services.Bookmarks,
|
|
|
|
static *services.StaticInformation,
|
|
|
|
live *services.LiveInformation,
|
|
|
|
cmp templ.Component,
|
|
|
|
) {
|
|
|
|
@layout.Base(title, version) {
|
|
|
|
@cmp
|
|
|
|
}
|
|
|
|
}
|