From b3648912542217e2910867d47e85dc5e8af068be Mon Sep 17 00:00:00 2001 From: aceberg <1502200+aceberg@users.noreply.github.com> Date: Mon, 22 Jan 2024 03:07:42 +0700 Subject: [PATCH] Stats pagination --- internal/conf/getconfig.go | 3 ++ internal/models/models.go | 1 + internal/web/config.go | 4 +++ internal/web/public/js/stats.js | 50 +++++++++++++++++++++--------- internal/web/public/js/weight.js | 4 +-- internal/web/templates/config.html | 5 +++ internal/web/templates/stats.html | 19 +++++++----- internal/web/templates/weight.html | 6 ++-- 8 files changed, 65 insertions(+), 27 deletions(-) diff --git a/internal/conf/getconfig.go b/internal/conf/getconfig.go index b9061d8..a506dff 100644 --- a/internal/conf/getconfig.go +++ b/internal/conf/getconfig.go @@ -16,6 +16,7 @@ func Get(path string) models.Conf { viper.SetDefault("THEME", "grass") viper.SetDefault("COLOR", "light") viper.SetDefault("HEATCOLOR", "#03a70c") + viper.SetDefault("PAGESTEP", 10) viper.SetConfigFile(path) viper.SetConfigType("yaml") @@ -29,6 +30,7 @@ func Get(path string) models.Conf { config.Theme, _ = viper.Get("THEME").(string) config.Color, _ = viper.Get("COLOR").(string) config.HeatColor, _ = viper.Get("HEATCOLOR").(string) + config.PageStep = viper.GetInt("PAGESTEP") return config } @@ -44,6 +46,7 @@ func Write(config models.Conf) { viper.Set("theme", config.Theme) viper.Set("color", config.Color) viper.Set("heatcolor", config.HeatColor) + viper.Set("pagestep", config.PageStep) err := viper.WriteConfig() check.IfError(err) diff --git a/internal/models/models.go b/internal/models/models.go index 0ba2df8..cb2ea52 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -12,6 +12,7 @@ type Conf struct { ConfPath string NodePath string HeatColor string + PageStep int } // Exercise - one exercise diff --git a/internal/web/config.go b/internal/web/config.go index 3119226..3204fcf 100644 --- a/internal/web/config.go +++ b/internal/web/config.go @@ -3,6 +3,7 @@ package web import ( "log" "net/http" + "strconv" "github.com/gin-gonic/gin" @@ -34,6 +35,9 @@ func saveConfigHandler(c *gin.Context) { appConfig.Theme = c.PostForm("theme") appConfig.Color = c.PostForm("color") appConfig.HeatColor = c.PostForm("heatcolor") + pagestep := c.PostForm("pagestep") + + appConfig.PageStep, _ = strconv.Atoi(pagestep) conf.Write(appConfig) diff --git a/internal/web/public/js/stats.js b/internal/web/public/js/stats.js index 5345e4b..89b312d 100644 --- a/internal/web/public/js/stats.js +++ b/internal/web/public/js/stats.js @@ -1,36 +1,56 @@ var sChart = null; +var sOffset = 0; -function addSet(date, reps, weight) { +function addSet(i, date, reps, weight) { - html_code = '
● After changing Host or Port the app must be restarted
+● Page Step - how many items to show on one page (for Stats and Weight)
● Please, check out my other apps on GitHub
● Want your own Self-Hosted app written in Go? Contact and prices here