From 91e83885c0730c0fd5370506c591d96cad5cf3e9 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Mon, 13 May 2024 16:40:30 +0300 Subject: use enum for page for navigation bar Signed-off-by: Arthur Zamarin --- pkg/app/handler/about/feedback.templ | 2 +- pkg/app/handler/about/feeds.templ | 2 +- pkg/app/handler/about/help.templ | 2 +- pkg/app/handler/about/index.templ | 2 +- pkg/app/handler/about/status.templ | 2 +- pkg/app/handler/arches/changedVersions.templ | 2 +- pkg/app/handler/categories/show.templ | 2 +- pkg/app/handler/categories/utils.go | 2 +- pkg/app/handler/index/index.templ | 2 +- pkg/app/handler/maintainer/browse.templ | 2 +- pkg/app/handler/maintainer/show.go | 14 ++++++------- pkg/app/handler/packages/search.go | 2 +- pkg/app/handler/packages/show.go | 2 +- pkg/app/handler/useflags/show.templ | 2 +- pkg/app/handler/useflags/utils.go | 2 +- pkg/app/handler/user/preferences.templ | 2 +- pkg/app/layout/page.templ | 31 +++++++++++++++++++--------- 17 files changed, 43 insertions(+), 32 deletions(-) diff --git a/pkg/app/handler/about/feedback.templ b/pkg/app/handler/about/feedback.templ index edd20a2..f29117e 100644 --- a/pkg/app/handler/about/feedback.templ +++ b/pkg/app/handler/about/feedback.templ @@ -76,5 +76,5 @@ templ feedback() { // Feedback shows the feedback about page func Feedback(w http.ResponseWriter, r *http.Request) { - layout.Layout("About", "about", feedback()).Render(r.Context(), w) + layout.Layout("About", layout.About, feedback()).Render(r.Context(), w) } diff --git a/pkg/app/handler/about/feeds.templ b/pkg/app/handler/about/feeds.templ index 3b66538..0116ee6 100644 --- a/pkg/app/handler/about/feeds.templ +++ b/pkg/app/handler/about/feeds.templ @@ -34,5 +34,5 @@ templ feeds() { // Feeds shows the feeds about page func Feeds(w http.ResponseWriter, r *http.Request) { - layout.Layout("About", "about", feeds()).Render(r.Context(), w) + layout.Layout("About", layout.About, feeds()).Render(r.Context(), w) } diff --git a/pkg/app/handler/about/help.templ b/pkg/app/handler/about/help.templ index 4487600..5ef1209 100644 --- a/pkg/app/handler/about/help.templ +++ b/pkg/app/handler/about/help.templ @@ -38,5 +38,5 @@ templ help() { // Help shows the help about page func Help(w http.ResponseWriter, r *http.Request) { - layout.Layout("About", "about", help()).Render(r.Context(), w) + layout.Layout("About", layout.About, help()).Render(r.Context(), w) } diff --git a/pkg/app/handler/about/index.templ b/pkg/app/handler/about/index.templ index 033b09a..7d4311d 100644 --- a/pkg/app/handler/about/index.templ +++ b/pkg/app/handler/about/index.templ @@ -55,5 +55,5 @@ templ index() { // Index shows the landing page of the about pages func Index(w http.ResponseWriter, r *http.Request) { - layout.Layout("About", "about", index()).Render(r.Context(), w) + layout.Layout("About", layout.About, index()).Render(r.Context(), w) } diff --git a/pkg/app/handler/about/status.templ b/pkg/app/handler/about/status.templ index 3c9193b..9829345 100644 --- a/pkg/app/handler/about/status.templ +++ b/pkg/app/handler/about/status.templ @@ -45,5 +45,5 @@ templ status(applications []*models.Application) { func Status(w http.ResponseWriter, r *http.Request) { var applicationData []*models.Application database.DBCon.Model(&applicationData).Order("id").Column("id", "last_update").Select() - layout.Layout("About", "about", status(applicationData)).Render(r.Context(), w) + layout.Layout("About", layout.About, status(applicationData)).Render(r.Context(), w) } diff --git a/pkg/app/handler/arches/changedVersions.templ b/pkg/app/handler/arches/changedVersions.templ index fb65fc3..6063452 100644 --- a/pkg/app/handler/arches/changedVersions.templ +++ b/pkg/app/handler/arches/changedVersions.templ @@ -45,5 +45,5 @@ func init() { } func renderPage(w http.ResponseWriter, r *http.Request, arch string, content templ.Component) { - layout.TabbedLayout("Architectures", "arches", "Architectures", "fa fa-fw fa-server", "", tabs, arch, content).Render(r.Context(), w) + layout.TabbedLayout("Architectures", layout.Arches, "Architectures", "fa fa-fw fa-server", "", tabs, arch, content).Render(r.Context(), w) } diff --git a/pkg/app/handler/categories/show.templ b/pkg/app/handler/categories/show.templ index cf80fb6..639dd14 100644 --- a/pkg/app/handler/categories/show.templ +++ b/pkg/app/handler/categories/show.templ @@ -72,7 +72,7 @@ templ show(component templ.Component) { } func renderShowPage(w http.ResponseWriter, r *http.Request, currentTab string, category *models.Category, component templ.Component) { - layout.TabbedLayout(category.Name, "packages", category.Name, "fa fa-fw fa-cubes", category.Description, []layout.SubTab{ + layout.TabbedLayout(category.Name, layout.Packages, category.Name, "fa fa-fw fa-cubes", category.Description, []layout.SubTab{ { Name: "Packages", Link: templ.URL("/categories/" + category.Name), diff --git a/pkg/app/handler/categories/utils.go b/pkg/app/handler/categories/utils.go index 7c75819..ee65d9c 100644 --- a/pkg/app/handler/categories/utils.go +++ b/pkg/app/handler/categories/utils.go @@ -36,6 +36,6 @@ var categoriesViewTabs = []layout.SubTab{ } func RenderPage(w http.ResponseWriter, r *http.Request, title string, currentTab string, content templ.Component) { - layout.TabbedLayout(title, "packages", "Packages", "fa fa-fw fa-cubes", "", categoriesViewTabs, + layout.TabbedLayout(title, layout.Packages, "Packages", "fa fa-fw fa-cubes", "", categoriesViewTabs, currentTab, content).Render(r.Context(), w) } diff --git a/pkg/app/handler/index/index.templ b/pkg/app/handler/index/index.templ index 7631bf0..7e23b0f 100644 --- a/pkg/app/handler/index/index.templ +++ b/pkg/app/handler/index/index.templ @@ -107,7 +107,7 @@ func Show(w http.ResponseWriter, r *http.Request) { updatedVersions := getUpdatedVersions(10) - layout.Layout("", "home", page( + layout.Layout("", layout.Home, page( count, packagesList, updatedVersions, utils.GetUserPreferences(r), )).Render(r.Context(), w) } diff --git a/pkg/app/handler/maintainer/browse.templ b/pkg/app/handler/maintainer/browse.templ index f7bc8b6..b217b95 100644 --- a/pkg/app/handler/maintainer/browse.templ +++ b/pkg/app/handler/maintainer/browse.templ @@ -77,7 +77,7 @@ func renderBrowsePage(w http.ResponseWriter, r *http.Request, title string, dbTy return } - layout.TabbedLayout(title, "maintainers", "Maintainers", "fa fa-fw fa-users", "", browseViewTabs, + layout.TabbedLayout(title, layout.Maintainers, "Maintainers", "fa fa-fw fa-users", "", browseViewTabs, title, browsePage(maintainers)).Render(r.Context(), w) } diff --git a/pkg/app/handler/maintainer/show.go b/pkg/app/handler/maintainer/show.go index c6262b1..dc80ec2 100644 --- a/pkg/app/handler/maintainer/show.go +++ b/pkg/app/handler/maintainer/show.go @@ -72,7 +72,7 @@ func ShowChangelog(w http.ResponseWriter, r *http.Request) { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } - layout.Layout(maintainer.Name, "maintainers", + layout.Layout(maintainer.Name, layout.Maintainers, show(packagesCount, &maintainer, "Changelog", components.Changelog("", commits)), ).Render(r.Context(), w) } @@ -134,7 +134,7 @@ func ShowOutdated(w http.ResponseWriter, r *http.Request) { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } - layout.Layout(maintainer.Name, "maintainers", + layout.Layout(maintainer.Name, layout.Maintainers, show(packagesCount, &maintainer, "Outdated", components.Outdated(outdated)), ).Render(r.Context(), w) } @@ -172,7 +172,7 @@ func ShowPullRequests(w http.ResponseWriter, r *http.Request) { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } - layout.Layout(maintainer.Name, "maintainers", + layout.Layout(maintainer.Name, layout.Maintainers, show(packagesCount, &maintainer, "Pull requests", components.PullRequests(pullRequests)), ).Render(r.Context(), w) } @@ -193,7 +193,7 @@ func ShowStabilization(w http.ResponseWriter, r *http.Request) { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } - layout.Layout(maintainer.Name, "maintainers", + layout.Layout(maintainer.Name, layout.Maintainers, show(packagesCount, &maintainer, "Stabilization", components.Stabilizations(results)), ).Render(r.Context(), w) } @@ -224,7 +224,7 @@ func ShowBugs(w http.ResponseWriter, r *http.Request) { return } generalCount, stabilizationCount, keywordingCount := utils.CountBugsCategories(bugs) - layout.Layout(maintainer.Name, "maintainers", + layout.Layout(maintainer.Name, layout.Maintainers, show(packagesCount, &maintainer, "Bugs", components.Bugs("", generalCount, stabilizationCount, keywordingCount, bugs)), ).Render(r.Context(), w) } @@ -250,7 +250,7 @@ func ShowSecurity(w http.ResponseWriter, r *http.Request) { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } - layout.Layout(maintainer.Name, "maintainers", + layout.Layout(maintainer.Name, layout.Maintainers, show(packagesCount, &maintainer, "Security", components.SecurityBugs("", bugs)), ).Render(r.Context(), w) } @@ -310,7 +310,7 @@ func ShowPackages(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } - layout.Layout(maintainer.Name, "maintainers", + layout.Layout(maintainer.Name, layout.Maintainers, show(packagesCount, &maintainer, "Packages", showPackages(gpackages, &maintainer)), ).Render(r.Context(), w) } diff --git a/pkg/app/handler/packages/search.go b/pkg/app/handler/packages/search.go index 5a61ee7..32c93e5 100644 --- a/pkg/app/handler/packages/search.go +++ b/pkg/app/handler/packages/search.go @@ -84,7 +84,7 @@ func Search(w http.ResponseWriter, r *http.Request) { return } - layout.Layout(searchTerm, "packages", search(searchTerm, results)).Render(r.Context(), w) + layout.Layout(searchTerm, layout.Packages, search(searchTerm, results)).Render(r.Context(), w) } // Search renders a template containing a list of search results diff --git a/pkg/app/handler/packages/show.go b/pkg/app/handler/packages/show.go index 27d8b29..b5c017f 100644 --- a/pkg/app/handler/packages/show.go +++ b/pkg/app/handler/packages/show.go @@ -109,7 +109,7 @@ func Show(w http.ResponseWriter, r *http.Request) { sortVersionsDesc(gpackage.Versions) - layout.Layout(gpackage.Atom, "packages", + layout.Layout(gpackage.Atom, layout.Packages, show(&gpackage, currentSubTab, utils.GetUserPreferences(r)), ).Render(r.Context(), w) } diff --git a/pkg/app/handler/useflags/show.templ b/pkg/app/handler/useflags/show.templ index 2beb499..9a2d104 100644 --- a/pkg/app/handler/useflags/show.templ +++ b/pkg/app/handler/useflags/show.templ @@ -170,6 +170,6 @@ func Show(w http.ResponseWriter, r *http.Request) { localUseFlags = useflags } - layout.Layout(useFlagName, "useflags", + layout.Layout(useFlagName, layout.UseFlags, show(useflag, localUseFlags, otherUseExpands, packages)).Render(r.Context(), w) } diff --git a/pkg/app/handler/useflags/utils.go b/pkg/app/handler/useflags/utils.go index 5056792..51225d2 100644 --- a/pkg/app/handler/useflags/utils.go +++ b/pkg/app/handler/useflags/utils.go @@ -16,5 +16,5 @@ var tabs = []layout.SubTab{ } func RenderPage(w http.ResponseWriter, r *http.Request, title string, currentTab string, content templ.Component) { - layout.TabbedLayout(title, "useflags", "USE flags", "fa fa-fw fa-sliders", "", tabs, currentTab, content).Render(r.Context(), w) + layout.TabbedLayout(title, layout.UseFlags, "USE flags", "fa fa-fw fa-sliders", "", tabs, currentTab, content).Render(r.Context(), w) } diff --git a/pkg/app/handler/user/preferences.templ b/pkg/app/handler/user/preferences.templ index 5119635..9fe7031 100644 --- a/pkg/app/handler/user/preferences.templ +++ b/pkg/app/handler/user/preferences.templ @@ -59,7 +59,7 @@ templ sortableScript() { func Preferences(currentSubTab string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - layout.TabbedLayout("User", "preferences", "Preferences", "fa fa-fw fa-cog", "You can customize the page contents to your needs here", viewTabs, + layout.TabbedLayout("User", layout.About, "Preferences", "fa fa-fw fa-cog", "You can customize the page contents to your needs here", viewTabs, currentSubTab, show(currentSubTab, utils.GetUserPreferences(r))).Render(r.Context(), w) } } diff --git a/pkg/app/layout/page.templ b/pkg/app/layout/page.templ index ebfe060..b8dff92 100644 --- a/pkg/app/layout/page.templ +++ b/pkg/app/layout/page.templ @@ -2,6 +2,17 @@ package layout import "soko/pkg/config" +type Page uint + +const ( + Home Page = iota + Packages + Maintainers + UseFlags + Arches + About +) + templ head(title string) { @@ -59,7 +70,7 @@ templ siteTitle() { </div> } -templ navigationBar(tab string) { +templ navigationBar(tab Page) { <nav class="tyrian-navbar navbar navbar-dark navbar-expand-lg bg-primary" role="navigation"> <div class="container"> <div class="navbar-header"> @@ -69,14 +80,14 @@ templ navigationBar(tab string) { </div> <div class="collapse navbar-collapse navbar-main-collapse" id="navbar-main-collapse"> <ul class="navbar-nav mr-auto"> - <li class={ "nav-item", templ.KV("active", tab == "home") }><a class="nav-link" href="/">Home</a></li> - <li class={ "nav-item", templ.KV("active", tab == "packages") }><a class="nav-link" href="/categories">Packages</a></li> - <li class={ "nav-item", templ.KV("active", tab == "maintainers") }><a class="nav-link" href="/maintainers">Maintainers</a></li> - <li class={ "nav-item", templ.KV("active", tab == "useflags") }><a class="nav-link" href="/useflags">USE flags</a></li> - <li class={ "nav-item", templ.KV("active", tab == "arches") }><a class="nav-link" href="/arches">Architectures</a></li> - <li class={ "nav-item", templ.KV("active", tab == "about") }><a class="nav-link" href="/about">About</a></li> + <li class={ "nav-item", templ.KV("active", tab == Home) }><a class="nav-link" href="/">Home</a></li> + <li class={ "nav-item", templ.KV("active", tab == Packages) }><a class="nav-link" href="/categories">Packages</a></li> + <li class={ "nav-item", templ.KV("active", tab == Maintainers) }><a class="nav-link" href="/maintainers">Maintainers</a></li> + <li class={ "nav-item", templ.KV("active", tab == UseFlags) }><a class="nav-link" href="/useflags">USE flags</a></li> + <li class={ "nav-item", templ.KV("active", tab == Arches) }><a class="nav-link" href="/arches">Architectures</a></li> + <li class={ "nav-item", templ.KV("active", tab == About) }><a class="nav-link" href="/about">About</a></li> </ul> - if tab != "home" { + if tab != Home { <form class="form-inline inlinesearch" role="search" action="/packages/search" method="get"> <div class="input-group"> <div class="input-group-prepend"> @@ -122,7 +133,7 @@ templ footer() { </footer> } -templ Layout(title string, tab string, contents templ.Component) { +templ Layout(title string, tab Page, contents templ.Component) { <!DOCTYPE html> <html lang="en"> @head(title) @@ -183,6 +194,6 @@ templ tabbedHeader(subTitle string, icon string, description string, tabs []SubT </div> } -templ TabbedLayout(title string, tab string, subTitle string, icon string, description string, tabs []SubTab, currentSubTab string, contents templ.Component) { +templ TabbedLayout(title string, tab Page, subTitle string, icon string, description string, tabs []SubTab, currentSubTab string, contents templ.Component) { @Layout(title, tab, tabbedHeader(subTitle, icon, description, tabs, currentSubTab, contents)) } -- cgit v1.2.3-65-gdbad