Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"sort"

"github.com/WeatherGod3218/counters/database"
"github.com/WeatherGod3218/counters/logging"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"

cshAuth "github.com/computersciencehouse/csh-auth/v2"
"go.mongodb.org/mongo-driver/v2/bson"
Expand All @@ -27,12 +29,13 @@ func GetHomePage(c *gin.Context) {
counters, err := database.GetAllCounters(c)

if err != nil {
logging.Logger.WithFields(logrus.Fields{"error": err, "module": "api", "method": "GetHomePage"}).Warn("Unable to load counters!")
c.JSON(http.StatusInternalServerError, gin.H{"error": "Unable to load counters!"})
return
}

sort.Slice(counters, func(i, j int) bool {
return counters[i].LastReset.Timestamp.After(counters[j].LastReset.Timestamp)
return counters[i].LastReset.Timestamp > counters[j].LastReset.Timestamp
})

c.HTML(http.StatusOK, "index.html", gin.H{
Expand Down
2 changes: 1 addition & 1 deletion database/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Reset struct {
UserID string `bson:"uuid"`
Reporter string `bson:"reporter"`
Description string `bson:"description"`
Timestamp time.Time `bson:"timestamp"`
Timestamp int64 `bson:"timestamp"`
}

func (r *Reset) IDHex() string {
Expand Down
2 changes: 1 addition & 1 deletion templates/counter.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
})

document.querySelectorAll(".days-since").forEach(el => {
const days = Math.floor((Date.now() - new Date(el.dataset.timestamp)) / 86400000);
const days = Math.floor((Date.now() - (el.dataset.timestamp*1000)) / 86400000);
el.textContent = days;
});
})();
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h2 class="text-center w-100 mb-3">
'use strict'

document.querySelectorAll(".days-since").forEach(el => {
const days = Math.floor((Date.now() - new Date(el.dataset.timestamp)) / 86400000);
const days = Math.floor((Date.now() - (el.dataset.timestamp*1000)) / 86400000);
el.textContent = days;
});

Expand Down
5 changes: 3 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func IsActiveRTP(user *cshAuth.Claims) bool {
return slices.Contains(user.Groups, "active-rtp")
}

func TranslateTime(inputTime string) time.Time {
func TranslateTime(inputTime string) int64 {
timeZone, _ := time.LoadLocation("America/New_York")

currentTime := time.Now()
Expand All @@ -52,5 +52,6 @@ func TranslateTime(inputTime string) time.Time {
if timeConverted.After(currentTime) {
timeConverted = currentTime
}
return timeConverted

return timeConverted.Unix()
}
Loading