Skip to content
Open
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
80 changes: 68 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,13 +1427,31 @@ func getNetworkCounts(networks []db.Network) map[uint]uint64 {

func viewNetworks(c *gin.Context) {
var networks []db.Network
var total int64
var err error

// Pagination parameters
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
if page < 1 {
page = 1
}
pageSize := 100
offset := (page - 1) * pageSize

run := c.Param("run")
run = strings.TrimPrefix(run, "/")

// Get total count and paginated results
if run == "" {
err = db.GetDB().Order("id desc").Find(&networks).Error
err = db.GetDB().Model(&db.Network{}).Count(&total).Error
if err == nil {
err = db.GetDB().Order("id desc").Offset(offset).Limit(pageSize).Find(&networks).Error
}
} else {
err = db.GetDB().Order("id desc").Where("training_run_id = ?", run).Find(&networks).Error
err = db.GetDB().Model(&db.Network{}).Where("training_run_id = ?", run).Count(&total).Error
if err == nil {
err = db.GetDB().Order("id desc").Where("training_run_id = ?", run).Offset(offset).Limit(pageSize).Find(&networks).Error
}
}
if err != nil {
log.Println(err)
Expand All @@ -1459,9 +1477,6 @@ func viewNetworks(c *gin.Context) {

counts := getNetworkCounts(networks)
json := []gin.H{}
if c.DefaultQuery("show_all", "1") == "0" {
networks = networks[0:99]
}
for _, network := range networks {
json = append(json, gin.H{
"id": network.ID,
Expand All @@ -1478,8 +1493,21 @@ func viewNetworks(c *gin.Context) {
})
}

// Calculate pagination info
totalPages := int((total + int64(pageSize) - 1) / int64(pageSize))
hasPrev := page > 1
hasNext := page < totalPages

c.HTML(http.StatusOK, "networks", gin.H{
"networks": json,
"networks": json,
"page": page,
"totalPages": totalPages,
"total": total,
"hasPrev": hasPrev,
"hasNext": hasNext,
"prevPage": page - 1,
"nextPage": page + 1,
"run": run,
})
}

Expand Down Expand Up @@ -1578,16 +1606,31 @@ func viewStats(c *gin.Context) {

func viewMatches(c *gin.Context) {
var matches []db.Match
var total int64
var err error

// Pagination parameters
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
if page < 1 {
page = 1
}
pageSize := 100
offset := (page - 1) * pageSize

run := c.Param("run")
run = strings.TrimPrefix(run, "/")

// Get total count and paginated results for matches
if run == "" {
err = db.GetDB().Order("id desc").Find(&matches).Error
err = db.GetDB().Model(&db.Match{}).Count(&total).Error
if err == nil {
err = db.GetDB().Order("id desc").Offset(offset).Limit(pageSize).Find(&matches).Error
}
} else {
err = db.GetDB().Order("id desc").Where("training_run_id = ?", run).Find(&matches).Error
}
if c.DefaultQuery("show_all", "1") == "0" {
matches = matches[0:99]
err = db.GetDB().Model(&db.Match{}).Where("training_run_id = ?", run).Count(&total).Error
if err == nil {
err = db.GetDB().Order("id desc").Where("training_run_id = ?", run).Offset(offset).Limit(pageSize).Find(&matches).Error
}
}
if err != nil {
log.Println(err)
Expand Down Expand Up @@ -1656,8 +1699,21 @@ func viewMatches(c *gin.Context) {
})
}

// Calculate pagination info
totalPages := int((total + int64(pageSize) - 1) / int64(pageSize))
hasPrev := page > 1
hasNext := page < totalPages

c.HTML(http.StatusOK, "matches", gin.H{
"matches": json,
"matches": json,
"page": page,
"totalPages": totalPages,
"total": total,
"hasPrev": hasPrev,
"hasNext": hasNext,
"prevPage": page - 1,
"nextPage": page + 1,
"run": run,
})
}

Expand Down
46 changes: 45 additions & 1 deletion templates/matches.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,51 @@
{{end}}
</tbody>
</table>
<a href="?show_all=1">show all matches (warning: large page)</a>

<!-- Pagination -->
<nav aria-label="Match pagination">
<ul class="pagination justify-content-center">
{{if .hasPrev}}
<li class="page-item">
{{if .run}}
<a class="page-link" href="/matches/{{.run}}?page={{.prevPage}}" aria-label="Previous">
{{else}}
<a class="page-link" href="/matches?page={{.prevPage}}" aria-label="Previous">
{{end}}
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{{else}}
<li class="page-item disabled">
<span class="page-link" aria-hidden="true">&laquo;</span>
</li>
{{end}}

<li class="page-item active">
<span class="page-link">Page {{.page}} of {{.totalPages}}</span>
</li>

{{if .hasNext}}
<li class="page-item">
{{if .run}}
<a class="page-link" href="/matches/{{.run}}?page={{.nextPage}}" aria-label="Next">
{{else}}
<a class="page-link" href="/matches?page={{.nextPage}}" aria-label="Next">
{{end}}
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{{else}}
<li class="page-item disabled">
<span class="page-link" aria-hidden="true">&raquo;</span>
</li>
{{end}}
</ul>
</nav>

<div class="text-center mt-2">
<small class="text-muted">Showing {{len .matches}} matches per page out of {{.total}} matches.</small>
</div>
</div>
{{end}}

Expand Down
48 changes: 46 additions & 2 deletions templates/networks.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,53 @@
{{end}}
</tbody>
</table>
<a href="?show_all=1">show all networks (warning: large page)</a>

<!-- Pagination -->
<nav aria-label="Network pagination">
<ul class="pagination justify-content-center">
{{if .hasPrev}}
<li class="page-item">
{{if .run}}
<a class="page-link" href="/training_run/{{.run}}?page={{.prevPage}}" aria-label="Previous">
{{else}}
<a class="page-link" href="/training_run?page={{.prevPage}}" aria-label="Previous">
{{end}}
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{{else}}
<li class="page-item disabled">
<span class="page-link" aria-hidden="true">&laquo;</span>
</li>
{{end}}

<li class="page-item active">
<span class="page-link">Page {{.page}} of {{.totalPages}}</span>
</li>

{{if .hasNext}}
<li class="page-item">
{{if .run}}
<a class="page-link" href="/training_run/{{.run}}?page={{.nextPage}}" aria-label="Next">
{{else}}
<a class="page-link" href="/training_run?page={{.nextPage}}" aria-label="Next">
{{end}}
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{{else}}
<li class="page-item disabled">
<span class="page-link" aria-hidden="true">&raquo;</span>
</li>
{{end}}
</ul>
</nav>

<div class="text-center mt-2">
<small class="text-muted">Showing {{len .networks}} networks per page out of {{.total}} networks.</small>
</div>
</div>
{{end}}

{{define "scripts"}}
{{end}}
{{end}}