Move components in separate folder

This commit is contained in:
Florian Hoss 2024-03-12 16:16:49 +01:00
parent e253825635
commit 42975ca85f
7 changed files with 28 additions and 23 deletions

View file

@ -1,4 +1,4 @@
package components package application
import ( import (
"gitlab.unjx.de/flohoss/godash/services" "gitlab.unjx.de/flohoss/godash/services"

View file

@ -1,4 +1,4 @@
package components package link
import ( import (
"gitlab.unjx.de/flohoss/godash/services" "gitlab.unjx.de/flohoss/godash/services"

View file

@ -1,8 +1,8 @@
package components package system
import "html/template" import "html/template"
var barTemplate = template.Must(template.New("bar").Parse("<div id=\"{{ .Id }}\" class=\"progress-bar\" style=\"width: {{ .Percentage }}%\"></div>")) var BarTemplate = template.Must(template.New("bar").Parse("<div id=\"{{ .Id }}\" class=\"progress-bar\" style=\"width: {{ .Percentage }}%\"></div>"))
type Bar struct { type Bar struct {
Id string Id string
@ -16,7 +16,7 @@ templ System(icon string, infoPre string, infoPost string, extraInfo string, per
<div class="extra-info">{ extraInfo }</div> <div class="extra-info">{ extraInfo }</div>
<div class="truncate"><span id={ valueId }>{ infoPre }</span>{ infoPost }</div> <div class="truncate"><span id={ valueId }>{ infoPre }</span>{ infoPost }</div>
<div class="progress-bar-wrapper"> <div class="progress-bar-wrapper">
@templ.FromGoHTML(barTemplate, Bar{Id:percentageId, Percentage:percentage}) @templ.FromGoHTML(BarTemplate, Bar{Id:percentageId, Percentage:percentage})
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,6 +1,7 @@
package components package uptime
import "gitlab.unjx.de/flohoss/godash/services" import "gitlab.unjx.de/flohoss/godash/services"
import "gitlab.unjx.de/flohoss/godash/components/system"
import "fmt" import "fmt"
import "html/template" import "html/template"
@ -31,7 +32,7 @@ templ Uptime(extraInfo string, id string, uptime services.Uptime) {
</div> </div>
</div> </div>
<div class="progress-bar-wrapper"> <div class="progress-bar-wrapper">
@templ.FromGoHTML(barTemplate, Bar{Id:id, Percentage:float64(uptime.Percentage)}) @templ.FromGoHTML(system.BarTemplate, system.Bar{Id:id, Percentage:float64(uptime.Percentage)})
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,5 +1,6 @@
services: services:
godash: godash:
profiles: [build]
image: ${CURRENT_IMAGE} image: ${CURRENT_IMAGE}
build: build:
context: . context: .
@ -21,7 +22,7 @@ services:
apk add tzdata apk add tzdata
RUN go install github.com/cosmtrek/air@latest RUN go install github.com/cosmtrek/air@latest
COPY scripts/.air.toml . COPY .air.toml .
WORKDIR /app WORKDIR /app
COPY go.mod . COPY go.mod .

View file

@ -2,39 +2,42 @@ package home
import "gitlab.unjx.de/flohoss/godash/services" import "gitlab.unjx.de/flohoss/godash/services"
import "gitlab.unjx.de/flohoss/godash/views/layout" import "gitlab.unjx.de/flohoss/godash/views/layout"
import "gitlab.unjx.de/flohoss/godash/components" 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"
import "fmt" import "fmt"
templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticInformation, live *services.LiveInformation) { templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticInformation, live *services.LiveInformation) {
<section class="grid gap-14"> <section class="grid gap-14">
<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3 select-none"> <div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3 select-none">
@components.System("icon-[bi--cpu]",static.CPU.Name,"",static.CPU.Threads,"systemCpuPercentage","",live.CPU) @system.System("icon-[bi--cpu]",static.CPU.Name,"",static.CPU.Threads,"systemCpuPercentage","",live.CPU)
@components.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--nvme]",live.Disk.Value,fmt.Sprintf(" | %s", static.Disk.Total),static.Disk.Partitions,"systemDiskPercentage","systemDiskValue",live.Disk.Percentage)
@components.System("icon-[bi--memory]",live.Ram.Value,fmt.Sprintf(" | %s", static.Ram.Total),static.Ram.Swap,"systemRamPercentage","systemRamValue",live.Ram.Percentage) @system.System("icon-[bi--memory]",live.Ram.Value,fmt.Sprintf(" | %s", static.Ram.Total),static.Ram.Swap,"systemRamPercentage","systemRamValue",live.Ram.Percentage)
@components.Uptime(static.Host.Architecture,"systemUptimePercentage",live.Uptime) @uptime.Uptime(static.Host.Architecture,"systemUptimePercentage",live.Uptime)
</div> </div>
<div class="grid gap-4"> <div class="grid gap-4">
for _, app := range bookmarks.Applications { for _, a := range bookmarks.Applications {
<div class="grid gap-2"> <div class="grid gap-2">
if app.Category != "" { if a.Category != "" {
<div class="heading">{ app.Category }</div> <div class="heading">{ a.Category }</div>
} }
<div class="grid-apps"> <div class="grid-apps">
for _, entry := range app.Entries { for _, entry := range a.Entries {
@components.Application(entry) @application.Application(entry)
} }
</div> </div>
</div> </div>
} }
</div> </div>
<div class="grid-apps"> <div class="grid-apps">
for _, link := range bookmarks.Links { for _, l := range bookmarks.Links {
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
if link.Category != "" { if l.Category != "" {
<div class="heading">{ link.Category }</div> <div class="heading">{ l.Category }</div>
} }
for _, entry := range link.Entries { for _, entry := range l.Entries {
@components.Link(entry) @link.Link(entry)
} }
</div> </div>
} }