From fdcaa8933b317bd607b654f26b4fd51be6a4c382 Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Mon, 18 Mar 2024 16:12:25 +0100 Subject: [PATCH] Move components around --- assets/css/tailwind.css | 9 +- .../{application => }/application.templ | 18 +- components/link/link.templ | 11 -- .../{uptime/uptime.templ => system.templ} | 33 +++- components/system/system.templ | 23 --- components/weather.templ | 160 ++++++++++++++++ services/bookmark.services.go | 27 --- services/bookmark.types.go | 28 +++ views/home/home.templ | 179 ++---------------- 9 files changed, 248 insertions(+), 240 deletions(-) rename components/{application => }/application.templ (66%) delete mode 100644 components/link/link.templ rename components/{uptime/uptime.templ => system.templ} (54%) delete mode 100644 components/system/system.templ create mode 100644 components/weather.templ create mode 100644 services/bookmark.types.go diff --git a/assets/css/tailwind.css b/assets/css/tailwind.css index 3d8d198..a8d2078 100644 --- a/assets/css/tailwind.css +++ b/assets/css/tailwind.css @@ -21,13 +21,10 @@ .extra-info { @apply text-xs truncate text-secondary; } - .grid-apps { - @apply grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-4 - } .hover-effect { - @apply no-underline md:hover:underline underline-offset-2 decoration-primary text-sm text-slate-700 dark:text-slate-300 hover:text-slate-900 dark:hover:text-slate-50 transition-all ease-linear duration-150 + @apply no-underline md:hover:underline underline-offset-2 decoration-primary text-sm text-slate-700 dark:text-slate-300 hover:text-slate-900 dark:hover:text-slate-50 transition-all ease-linear duration-150; } - .heading{ - @apply text-lg text-secondary select-none truncate underline decoration-primary underline-offset-4 + .heading { + @apply text-lg text-secondary select-none truncate underline decoration-primary underline-offset-4; } } diff --git a/components/application/application.templ b/components/application.templ similarity index 66% rename from components/application/application.templ rename to components/application.templ index b0835f0..06fdd79 100644 --- a/components/application/application.templ +++ b/components/application.templ @@ -1,11 +1,13 @@ -package application +package components -import "gitlab.unjx.de/flohoss/godash/services" -import "html/template" +import ( + "gitlab.unjx.de/flohoss/godash/services" + "html/template" +) var ImageTemplate = template.Must(template.New("bar").Parse("
")) -type Bar struct { +type Image struct { Background string Icon string } @@ -26,7 +28,13 @@ func backgroundColor(config string) string { templ Application(application services.Application) { - @templ.FromGoHTML(ImageTemplate, Bar{Background: backgroundColor(application.Background), Icon: application.Icon}) + @templ.FromGoHTML(ImageTemplate, Image{Background: backgroundColor(application.Background), Icon: application.Icon})
{ application.Name }
} + +templ Link(link services.Link) { + +
{ link.Name }
+
+} diff --git a/components/link/link.templ b/components/link/link.templ deleted file mode 100644 index b871c43..0000000 --- a/components/link/link.templ +++ /dev/null @@ -1,11 +0,0 @@ -package link - -import ( - "gitlab.unjx.de/flohoss/godash/services" -) - -templ Link(link services.Link) { - -
{ link.Name }
-
-} diff --git a/components/uptime/uptime.templ b/components/system.templ similarity index 54% rename from components/uptime/uptime.templ rename to components/system.templ index a0f6cc3..5a6b1e2 100644 --- a/components/uptime/uptime.templ +++ b/components/system.templ @@ -1,9 +1,30 @@ -package uptime +package components -import "gitlab.unjx.de/flohoss/godash/services" -import "gitlab.unjx.de/flohoss/godash/components/system" -import "fmt" -import "html/template" +import ( + "html/template" + "gitlab.unjx.de/flohoss/godash/services" + "fmt" +) + +var BarTemplate = template.Must(template.New("bar").Parse("
")) + +type Bar struct { + Id string + Percentage float64 +} + +templ System(icon string, infoPre string, infoPost string, extraInfo string, percentageId string, valueId string, percentage float64) { +
+ +
+
{ extraInfo }
+
{ infoPre }{ infoPost }
+
+ @templ.FromGoHTML(BarTemplate, Bar{Id:percentageId, Percentage:percentage}) +
+
+
+} var countDownTemplate = template.Must(template.New("countdown").Parse("")) @@ -32,7 +53,7 @@ templ Uptime(extraInfo string, id string, uptime services.Uptime) {
- @templ.FromGoHTML(system.BarTemplate, system.Bar{Id:id, Percentage:float64(uptime.Percentage)}) + @templ.FromGoHTML(BarTemplate, Bar{Id:id, Percentage:float64(uptime.Percentage)})
diff --git a/components/system/system.templ b/components/system/system.templ deleted file mode 100644 index 16e8b06..0000000 --- a/components/system/system.templ +++ /dev/null @@ -1,23 +0,0 @@ -package system - -import "html/template" - -var BarTemplate = template.Must(template.New("bar").Parse("
")) - -type Bar struct { - Id string - Percentage float64 -} - -templ System(icon string, infoPre string, infoPost string, extraInfo string, percentageId string, valueId string, percentage float64) { -
- -
-
{ extraInfo }
-
{ infoPre }{ infoPost }
-
- @templ.FromGoHTML(BarTemplate, Bar{Id:percentageId, Percentage:percentage}) -
-
-
-} diff --git a/components/weather.templ b/components/weather.templ new file mode 100644 index 0000000..fd40fb5 --- /dev/null +++ b/components/weather.templ @@ -0,0 +1,160 @@ +package components + +import ( + "gitlab.unjx.de/flohoss/godash/services" + "fmt" +) + +func getIcon(icon string) string { + switch icon { + case "01d": + return "icon-[bi--sun-fill]" + case "01n": + return "icon-[bi--moon-fill]" + case "02d": + return "icon-[bi--cloud-sun-fill]" + case "02n": + return "icon-[bi--cloud-moon-fill]" + case "03d", "03n": + return "icon-[bi--cloud-fill]" + case "04d", "04n": + return "icon-[bi--clouds-fill]" + case "09d", "09n": + return "icon-[bi--cloud-rain-heavy-fill]" + case "10d", "10n": + return "icon-[bi--cloud-drizzle-fill]" + case "11d", "11n": + return "icon-[bi--cloud-lightning-rain-fill]" + case "13d", "13n": + return "icon-[bi--cloud-snow-fill]" + case "50d", "50n": + return "icon-[bi--cloud-fog2-fill]" + default: + return "" + } +} + +templ Weather(weather *services.OpenWeather) { +
+ +
+
{ fmt.Sprintf("%0.2f",weather.Temp) } { weather.Units }
+
+
+ +
{ weather.Description }
+
+
+ +
{ fmt.Sprintf("%d %%",weather.Humidity) }
+
+ + +
+
+
+} + +templ WeatherScript() { + +} diff --git a/services/bookmark.services.go b/services/bookmark.services.go index 606015c..55653fc 100644 --- a/services/bookmark.services.go +++ b/services/bookmark.services.go @@ -43,33 +43,6 @@ func NewBookmarkService() *BookmarkService { return &bs } -type BookmarkService struct { - bookmarks Bookmarks -} - -type Bookmarks struct { - Links []struct { - Category string - Entries []Link - } - Applications []struct { - Category string - Entries []Application - } -} - -type Link struct { - Name string - URL string -} - -type Application struct { - Name string - Icon string - Background string - URL string -} - func (bs *BookmarkService) GetAllBookmarks() *Bookmarks { return &bs.bookmarks } diff --git a/services/bookmark.types.go b/services/bookmark.types.go new file mode 100644 index 0000000..6047664 --- /dev/null +++ b/services/bookmark.types.go @@ -0,0 +1,28 @@ +package services + +type BookmarkService struct { + bookmarks Bookmarks +} + +type Bookmarks struct { + Links []struct { + Category string + Entries []Link + } + Applications []struct { + Category string + Entries []Application + } +} + +type Link struct { + Name string + URL string +} + +type Application struct { + Name string + Icon string + Background string + URL string +} diff --git a/views/home/home.templ b/views/home/home.templ index 7d25734..b994566 100644 --- a/views/home/home.templ +++ b/views/home/home.templ @@ -1,73 +1,20 @@ package home -import "gitlab.unjx.de/flohoss/godash/services" -import "gitlab.unjx.de/flohoss/godash/views/layout" -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" - -func getIcon(icon string) string { - switch icon { - case "01d": - return "icon-[bi--sun-fill]" - case "01n": - return "icon-[bi--moon-fill]" - case "02d": - return "icon-[bi--cloud-sun-fill]" - case "02n": - return "icon-[bi--cloud-moon-fill]" - case "03d", "03n": - return "icon-[bi--cloud-fill]" - case "04d", "04n": - return "icon-[bi--clouds-fill]" - case "09d", "09n": - return "icon-[bi--cloud-rain-heavy-fill]" - case "10d", "10n": - return "icon-[bi--cloud-drizzle-fill]" - case "11d", "11n": - return "icon-[bi--cloud-lightning-rain-fill]" - case "13d", "13n": - return "icon-[bi--cloud-snow-fill]" - case "50d", "50n": - return "icon-[bi--cloud-fog2-fill]" - default: - return "" - } -} +import ( + "gitlab.unjx.de/flohoss/godash/services" + "gitlab.unjx.de/flohoss/godash/views/layout" + "fmt" + "gitlab.unjx.de/flohoss/godash/components" +) templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticInformation, live *services.LiveInformation, weather *services.OpenWeather) {
-
- -
-
{ fmt.Sprintf("%0.2f",weather.Temp) } { weather.Units }
-
-
- -
{ weather.Description }
-
-
- -
{ fmt.Sprintf("%d %%",weather.Humidity) }
-
- - -
-
-
+ @components.Weather(weather)
- @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) + @components.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) + @components.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)
for _, a := range bookmarks.Applications { @@ -77,120 +24,28 @@ templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticI }
for _, entry := range a.Entries { - @application.Application(entry) + @components.Application(entry) }
} -
+
for _, l := range bookmarks.Links {
if l.Category != "" {
{ l.Category }
+ } else { +
} for _, entry := range l.Entries { - @link.Link(entry) + @components.Link(entry) }
}
+ @components.WeatherScript()
- } templ HomeIndex(