back interdiff of round #1 and #0

appview: improve pagination.Page usage #519

closed
opened by ptr.pet targeting master from ptr.pet/core: pipeline-paginated
files
appview
db
issues
middleware
pages
templates
repo
issues
pagination
repo
ERROR
appview/issues/issues.go

Failed to calculate interdiff for this file.

REBASED
appview/issues/router.go

This patch was likely rebased, as context lines do not match.

ERROR
appview/middleware/middleware.go

Failed to calculate interdiff for this file.

ERROR
appview/pagination/page.go

Failed to calculate interdiff for this file.

NEW
appview/db/issues.go
···
// get next issue_id
var newIssueId int
err := tx.QueryRow(`
-
update repo_issue_seqs
-
set next_issue_id = next_issue_id + 1
-
where repo_at = ?
returning next_issue_id - 1
`, issue.RepoAt).Scan(&newIssueId)
if err != nil {
···
whereClause = " where " + strings.Join(conditions, " and ")
}
-
pLower := FilterGte("row_num", page.Offset+1)
-
pUpper := FilterLte("row_num", page.Offset+page.Limit)
args = append(args, pLower.Arg()...)
args = append(args, pUpper.Arg()...)
···
}
func GetIssues(e Execer, filters ...filter) ([]Issue, error) {
-
return GetIssuesPaginated(e, pagination.FirstPage(), filters...)
}
func GetIssue(e Execer, repoAt syntax.ATURI, issueId int) (*Issue, error) {
···
// get next issue_id
var newIssueId int
err := tx.QueryRow(`
+
update repo_issue_seqs
+
set next_issue_id = next_issue_id + 1
+
where repo_at = ?
returning next_issue_id - 1
`, issue.RepoAt).Scan(&newIssueId)
if err != nil {
···
whereClause = " where " + strings.Join(conditions, " and ")
}
+
pLower := FilterGte("row_num", page.Count*page.No+1)
+
pUpper := FilterLte("row_num", page.Count*(page.No+1))
args = append(args, pLower.Arg()...)
args = append(args, pUpper.Arg()...)
···
}
func GetIssues(e Execer, filters ...filter) ([]Issue, error) {
+
return GetIssuesPaginated(e, pagination.Page{No: 0, Count: 10}, filters...)
}
func GetIssue(e Execer, repoAt syntax.ATURI, issueId int) (*Issue, error) {
NEW
appview/pages/pages.go
···
RepoInfo repoinfo.RepoInfo
Active string
Issues []db.Issue
-
Page pagination.Page
FilteringByOpen bool
}
···
RepoInfo repoinfo.RepoInfo
Active string
Issues []db.Issue
+
Pagination pagination.Pagination
FilteringByOpen bool
}
NEW
appview/pages/templates/repo/issues/issues.html
···
{{ end }}
{{ define "pagination" }}
<div class="flex justify-end mt-4 gap-2">
{{ $currentState := "closed" }}
{{ if .FilteringByOpen }}
{{ $currentState = "open" }}
{{ end }}
-
{{ if gt .Page.Offset 0 }}
-
{{ $prev := .Page.Previous }}
<a
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
hx-boost="true"
-
href = "/{{ $.RepoInfo.FullName }}/issues?state={{ $currentState }}&offset={{ $prev.Offset }}&limit={{ $prev.Limit }}"
>
{{ i "chevron-left" "w-4 h-4" }}
previous
···
<div></div>
{{ end }}
-
{{ if eq (len .Issues) .Page.Limit }}
-
{{ $next := .Page.Next }}
<a
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
hx-boost="true"
-
href = "/{{ $.RepoInfo.FullName }}/issues?state={{ $currentState }}&offset={{ $next.Offset }}&limit={{ $next.Limit }}"
>
next
{{ i "chevron-right" "w-4 h-4" }}
···
{{ end }}
{{ define "pagination" }}
+
{{ $currentPage := .Pagination.CurrentPage }}
<div class="flex justify-end mt-4 gap-2">
{{ $currentState := "closed" }}
{{ if .FilteringByOpen }}
{{ $currentState = "open" }}
{{ end }}
+
{{ if gt $currentPage.No 0 }}
+
{{ $prev := .Pagination.PreviousPage }}
<a
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
hx-boost="true"
+
href = "/{{ $.RepoInfo.FullName }}/issues?state={{ $currentState }}&page={{ add $prev.No 1 }}&count={{ $prev.Count }}"
>
{{ i "chevron-left" "w-4 h-4" }}
previous
···
<div></div>
{{ end }}
+
{{ if lt (add $currentPage.No 1) .Pagination.TotalPageCount }}
+
{{ $next := .Pagination.NextPage }}
<a
class="btn flex items-center gap-2 no-underline hover:no-underline dark:text-white dark:hover:bg-gray-700"
hx-boost="true"
+
href = "/{{ $.RepoInfo.FullName }}/issues?state={{ $currentState }}&page={{ add $next.No 1 }}&count={{ $next.Count }}"
>
next
{{ i "chevron-right" "w-4 h-4" }}
NEW
appview/repo/feed.go
···
issues, err := db.GetIssuesPaginated(
rp.db,
-
pagination.Page{Limit: feedLimitPerType},
db.FilterEq("repo_at", f.RepoAt()),
)
if err != nil {
···
issues, err := db.GetIssuesPaginated(
rp.db,
+
pagination.Page{No: 0, Count: feedLimitPerType},
db.FilterEq("repo_at", f.RepoAt()),
)
if err != nil {