1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Properly redraw charts.

Add pre-defined interval for today.
Fix week interval.
This commit is contained in:
Ferdinand Muetsch
2019-05-23 08:14:32 +02:00
parent e23e7520d0
commit 899b2fff64
3 changed files with 25 additions and 8 deletions

View File

@ -13,6 +13,7 @@ import (
)
const (
IntervalToday string = "today"
IntervalLastDay string = "day"
IntervalLastWeek string = "week"
IntervalLastMonth string = "month"
@ -44,10 +45,12 @@ func (h *SummaryHandler) Get(w http.ResponseWriter, r *http.Request) {
user := r.Context().Value(models.UserKey).(*models.User)
params := r.URL.Query()
interval := params.Get("interval")
from, err := utils.ParseDate(params.Get("from"))
if err != nil {
interval := params.Get("interval")
switch interval {
case IntervalToday:
from = utils.StartOfDay()
case IntervalLastDay:
from = utils.StartOfDay().Add(-24 * time.Hour)
case IntervalLastWeek:
@ -63,7 +66,7 @@ func (h *SummaryHandler) Get(w http.ResponseWriter, r *http.Request) {
}
}
live := params.Get("live") != "" && params.Get("live") != "false"
live := (params.Get("live") != "" && params.Get("live") != "false") || interval == IntervalToday
to := utils.StartOfDay()
if live {
to = time.Now()