Skip to content

Commit

Permalink
Merge pull request #1301 from ugent-library/fix_issue_1299
Browse files Browse the repository at this point in the history
fix issue 1299: cap page to last page when out of range
  • Loading branch information
nics authored Nov 6, 2023
2 parents f0287de + b800941 commit 72edfda
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions handlers/datasetsearching/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ func (h *Handler) Search(w http.ResponseWriter, r *http.Request, ctx Context) {
isFirstUse = globalHits.Total == 0
}

// you are on the wrong page: cap page to last available page
if hits.Total > 0 && len(hits.Hits) == 0 {
query := ctx.CurrentURL.Query()
query.Set("page", fmt.Sprintf("%d", hits.TotalPages()))
ctx.CurrentURL.RawQuery = query.Encode()
http.Redirect(w, r, ctx.CurrentURL.String(), http.StatusTemporaryRedirect)
return
}

render.Layout(w, "layouts/default", "dataset/pages/search", YieldSearch{
Context: ctx,
PageTitle: "Overview - Datasets - Biblio",
Expand Down Expand Up @@ -150,6 +159,15 @@ func (h *Handler) CurationSearch(w http.ResponseWriter, r *http.Request, ctx Con
isFirstUse = globalHits.Total == 0
}

// you are on the wrong page: cap page to last available page
if hits.Total > 0 && len(hits.Hits) == 0 {
query := ctx.CurrentURL.Query()
query.Set("page", fmt.Sprintf("%d", hits.TotalPages()))
ctx.CurrentURL.RawQuery = query.Encode()
http.Redirect(w, r, ctx.CurrentURL.String(), http.StatusTemporaryRedirect)
return
}

render.Layout(w, "layouts/default", "dataset/pages/search", YieldSearch{
Context: ctx,
PageTitle: "Overview - Datasets - Biblio",
Expand Down
18 changes: 18 additions & 0 deletions handlers/publicationsearching/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ func (h *Handler) Search(w http.ResponseWriter, r *http.Request, ctx Context) {
isFirstUse = globalHits.Total == 0
}

// you are on the wrong page: cap page to last available page
if hits.Total > 0 && len(hits.Hits) == 0 {
query := ctx.CurrentURL.Query()
query.Set("page", fmt.Sprintf("%d", hits.TotalPages()))
ctx.CurrentURL.RawQuery = query.Encode()
http.Redirect(w, r, ctx.CurrentURL.String(), http.StatusTemporaryRedirect)
return
}

render.Layout(w, "layouts/default", "publication/pages/search", YieldSearch{
Context: ctx,
PageTitle: "Overview - Publications - Biblio",
Expand Down Expand Up @@ -151,6 +160,15 @@ func (h *Handler) CurationSearch(w http.ResponseWriter, r *http.Request, ctx Con
isFirstUse = globalHits.Total == 0
}

// you are on the wrong page: cap page to last available page
if hits.Total > 0 && len(hits.Hits) == 0 {
query := ctx.CurrentURL.Query()
query.Set("page", fmt.Sprintf("%d", hits.TotalPages()))
ctx.CurrentURL.RawQuery = query.Encode()
http.Redirect(w, r, ctx.CurrentURL.String(), http.StatusTemporaryRedirect)
return
}

render.Layout(w, "layouts/default", "publication/pages/search", YieldSearch{
Context: ctx,
PageTitle: "Overview - Publications - Biblio",
Expand Down

0 comments on commit 72edfda

Please sign in to comment.