From bd09500dfccea4a9a00a171eff661eef6c9b5960 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Fri, 16 Feb 2024 13:13:49 +0100 Subject: [PATCH] auto month pre select --- internal/server/handle_reports.go | 2 +- internal/views/reports.templ | 8 +++- internal/views/reports_templ.go | 78 +++++++++++++++++++++---------- 3 files changed, 60 insertions(+), 28 deletions(-) diff --git a/internal/server/handle_reports.go b/internal/server/handle_reports.go index d105492..cea6ab4 100644 --- a/internal/server/handle_reports.go +++ b/internal/server/handle_reports.go @@ -31,7 +31,7 @@ func handleReportsPage() echo.HandlerFunc { if err != nil { yearStr = time.Now().Format("2006") } - return renderTempl(c, http.StatusOK, views.Reports(constants.Months, yearStr)) + return renderTempl(c, http.StatusOK, views.Reports(constants.Months, month, yearStr)) } } diff --git a/internal/views/reports.templ b/internal/views/reports.templ index 1db3dfb..f5e8094 100644 --- a/internal/views/reports.templ +++ b/internal/views/reports.templ @@ -4,7 +4,7 @@ import ( "strconv" ) -templ Reports(months []string, year string) { +templ Reports(months []string, m int, year string) { @BaseLayout() {

Reports

@@ -30,7 +30,11 @@ templ Reports(months []string, year string) { Month diff --git a/internal/views/reports_templ.go b/internal/views/reports_templ.go index 78044a2..947f5db 100644 --- a/internal/views/reports_templ.go +++ b/internal/views/reports_templ.go @@ -14,7 +14,7 @@ import ( "strconv" ) -func Reports(months []string, year string) templ.Component { +func Reports(months []string, m int, year string) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -46,30 +46,58 @@ func Reports(months []string, year string) templ.Component { return templ_7745c5c3_Err } for i, month := range months { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err + if i+1 == m { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } } } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")