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 = '
'+date+' | '+reps+' | '+weight+' |
';
+ html_code = ''+i+'. | '+date+' | '+reps+' | '+weight+' |
';
document.getElementById('stats-table').insertAdjacentHTML('beforeend', html_code);
};
-function setStatsPage(sets, hcolor) {
- let dates = [], ws = []; reps = [];
+function setStatsPage(sets, hcolor, off, step) {
+ let start = 0, end = 0;
+ let dates = [], ws = [], reps = [], exs = [];
let ex = document.getElementById("ex-value").value;
- console.log("EX =", ex);
+ for (let i = 0; i < sets.length; i++) {
+ if (sets[i].Name === ex) {
+ exs.push(sets[i]);
+ }
+ };
- let start = 0;
- let end = sets.length;
+ sOffset = sOffset + off;
+ if (sOffset<0) {
+ sOffset = 0;
+ };
+
+ let arrayLength = exs.length;
+ let move = step + sOffset*step;
+
+ if (arrayLength > move) {
+ start = arrayLength - move;
+ end = start + step;
+ } else {
+ sOffset = sOffset - 1;
+ if (arrayLength > step) {
+ end = step;
+ } else {
+ end = arrayLength;
+ }
+ };
document.getElementById('stats-table').innerHTML = "";
+
for (let i = start ; i < end; i++) {
- if (sets[i].Name === ex) {
- addSet(sets[i].Date, sets[i].Reps, sets[i].Weight);
+ addSet(i+1, exs[i].Date, exs[i].Reps, exs[i].Weight);
- dates.push(sets[i].Date);
- reps.push(sets[i].Reps);
- ws.push(sets[i].Weight);
- };
+ dates.push(exs[i].Date);
+ reps.push(exs[i].Reps);
+ ws.push(exs[i].Weight);
};
- console.log("REPS =", reps);
-
statsChart('stats-reps', dates, reps, hcolor, true);
weightChart('stats-weight', dates, ws, hcolor, true);
};
diff --git a/internal/web/public/js/weight.js b/internal/web/public/js/weight.js
index 2ff0e74..cb16514 100644
--- a/internal/web/public/js/weight.js
+++ b/internal/web/public/js/weight.js
@@ -13,8 +13,8 @@ function addWeight(i, date, weight, id) {
document.getElementById('weightList').insertAdjacentHTML('beforeend', html_code);
};
-function setWeights(weights, wcolor, off) {
- let start = 0, end = 0, step = 10;
+function setWeights(weights, wcolor, off, step) {
+ let start = 0, end = 0;
let dates = [], ws = [];
offset = offset + off;
diff --git a/internal/web/templates/config.html b/internal/web/templates/config.html
index dddeaf1..bd1b62f 100644
--- a/internal/web/templates/config.html
+++ b/internal/web/templates/config.html
@@ -41,6 +41,10 @@
+
+ Page Step |
+ |
+
|
|
@@ -62,6 +66,7 @@
● 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
diff --git a/internal/web/templates/stats.html b/internal/web/templates/stats.html
index f370c0e..c26a753 100644
--- a/internal/web/templates/stats.html
+++ b/internal/web/templates/stats.html
@@ -7,12 +7,12 @@
-
+
-
+
@@ -52,7 +57,7 @@
{{ template "footer.html" }}
diff --git a/internal/web/templates/weight.html b/internal/web/templates/weight.html
index 93dcc76..481b2d9 100644
--- a/internal/web/templates/weight.html
+++ b/internal/web/templates/weight.html
@@ -21,8 +21,8 @@
-
-
+
+
@@ -53,7 +53,7 @@
{{ template "footer.html" }}