From 2dd6d2b98a8b56d045e8d7011713f1becd746544 Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Thu, 7 Nov 2024 14:46:37 +0100 Subject: dashboard/app: make coverage period configurable This change makes amount of coverage columns configurable. The default width is 4 columns now (months, days, quarters). Previous default was 12 and was too wide. --- dashboard/app/graphs.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'dashboard/app') diff --git a/dashboard/app/graphs.go b/dashboard/app/graphs.go index b05636431..2b4ab15ca 100644 --- a/dashboard/app/graphs.go +++ b/dashboard/app/graphs.go @@ -211,6 +211,7 @@ func handleHeatmap(c context.Context, w http.ResponseWriter, r *http.Request, f return err } ss := r.FormValue("subsystem") + periodType := r.FormValue("period") if periodType == "" { periodType = coveragedb.DayPeriod @@ -219,7 +220,17 @@ func handleHeatmap(c context.Context, w http.ResponseWriter, r *http.Request, f return fmt.Errorf("only day and month are allowed, but received %s instead, %w", periodType, ErrClientBadRequest) } - periods, err := coveragedb.GenNPeriodsTill(12, civil.DateOf(timeNow(c)), periodType) + + periodCount := r.FormValue("period_count") + if periodCount == "" { + periodCount = "4" + } + nPeriods, err := strconv.Atoi(periodCount) + if err != nil || nPeriods > 12 || nPeriods < 1 { + return fmt.Errorf("periods_count is wrong, expected [1, 12]: %w", err) + } + + periods, err := coveragedb.GenNPeriodsTill(nPeriods, civil.DateOf(timeNow(c)), periodType) if err != nil { return fmt.Errorf("%s: %w", err.Error(), ErrClientBadRequest) } -- cgit mrf-deployment