From efbcbee37408ef6613812c687e2b2553c073ec6b Mon Sep 17 00:00:00 2001 From: Yader Velasquez Date: Mon, 12 Feb 2024 11:13:25 -0600 Subject: [PATCH] Remove links.PullOrgSlug from analytics modules Improve navigation --- analytics/routes.go | 11 +++++++++-- cmd/links/main.go | 2 +- templates/analytics_detail.html | 7 +++++-- templates/link_short_list.html | 2 +- templates/listing_list.html | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/analytics/routes.go b/analytics/routes.go index a1c839c..80fdd27 100644 --- a/analytics/routes.go +++ b/analytics/routes.go @@ -36,8 +36,10 @@ func (s *Service) Detail(c echo.Context) error { if err != nil { return echo.NotFoundHandler(c) } - - orgSlug := links.PullOrgSlug(c) + orgSlug := c.Param("slug") + if orgSlug == "" { + return echo.NotFoundHandler(c) + } opts := &database.FilterOptions{ Filter: sq.And{ sq.Eq{"o.slug": orgSlug}, @@ -61,6 +63,7 @@ func (s *Service) Detail(c echo.Context) error { showQRList bool isQRDetail bool isLinksDetail bool + back string ) switch aType { @@ -68,9 +71,11 @@ func (s *Service) Detail(c echo.Context) error { isLinksDetail = true case "shorts": showQRList = true + back = c.Echo().Reverse("short:link_short_list", org.Slug) case "lists": showListingLinksList = true showQRList = true + back = c.Echo().Reverse("list:listing_list", org.Slug) case "qr": isQRDetail = true @@ -196,6 +201,7 @@ func (s *Service) Detail(c echo.Context) error { pd.Data["qr_scans"] = lt.Translate("QR Scans") pd.Data["links"] = lt.Translate("Links") pd.Data["no_data"] = lt.Translate("No Data") + pd.Data["back"] = lt.Translate("Back") chart := make(map[string]int) sortedChart := make(map[string]int) chartKey := make([]string, 0) @@ -225,6 +231,7 @@ func (s *Service) Detail(c echo.Context) error { "chart": sortedChart, "title": result.Data.Title, "org": org, + "back": back, } return gctx.Render(http.StatusOK, "analytics_detail.html", gmap) } diff --git a/cmd/links/main.go b/cmd/links/main.go index 5065026..653a2f8 100644 --- a/cmd/links/main.go +++ b/cmd/links/main.go @@ -259,7 +259,7 @@ func run() error { list.NewService(listService) adminService := e.Group("/admin") admin.NewService(adminService) - analyticsService := e.Group("/analytics") + analyticsService := e.Group("/:slug/analytics") analytics.NewService(analyticsService) billingService := e.Group("/billing") billing.NewService(billingService) diff --git a/templates/analytics_detail.html b/templates/analytics_detail.html index 98f6840..7d3119c 100644 --- a/templates/analytics_detail.html +++ b/templates/analytics_detail.html @@ -1,6 +1,9 @@ {{template "base" .}}

{{.pd.Title}} | {{.title}}

+ {{if .back}} + {{.pd.Data.back}} + {{end}}
{{if and .isRestricted (or .isQRDetail .isLinksDetail) }} @@ -65,7 +68,7 @@ {{if .data.QrList}} {{range .data.QrList}} - {{.Title}} + {{.Title}} {{.Clicks}} {{end}} @@ -84,7 +87,7 @@ {{if .data.ListingLink}} {{range .data.ListingLink}} - {{.Title}} + {{.Title}} {{.Clicks}} {{end}} diff --git a/templates/link_short_list.html b/templates/link_short_list.html index bcc58de..25beb4e 100644 --- a/templates/link_short_list.html +++ b/templates/link_short_list.html @@ -42,7 +42,7 @@ {{if eq .UserID $.currentUserID}}

{{$.pd.Data.edit}}

{{$.pd.Data.delete}}

-

{{$.pd.Data.analytics}}

+

{{$.pd.Data.analytics}}

{{end}} diff --git a/templates/listing_list.html b/templates/listing_list.html index 82e8ba7..f1bdf15 100644 --- a/templates/listing_list.html +++ b/templates/listing_list.html @@ -43,7 +43,7 @@

{{$.pd.Data.manage_links}}

{{$.pd.Data.edit}}

{{$.pd.Data.delete}}

-

{{$.pd.Data.analytics}}

+

{{$.pd.Data.analytics}}

{{end}} -- 2.45.2