Skip to content

Commit

Permalink
Actor pagination fixes (xbapps#1435)
Browse files Browse the repository at this point in the history
* Fix Arrow Key scrolling Actor List

* Change JumpTo Actors by a Letter
  • Loading branch information
toshski authored Nov 5, 2023
1 parent 2f83e97 commit 9ccbff2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
20 changes: 16 additions & 4 deletions pkg/models/model_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type ResponseActorList struct {
CountDownloaded int `json:"count_downloaded"`
CountNotDownloaded int `json:"count_not_downloaded"`
CountHidden int `json:"count_hidden"`
Offset int `json:"offset"`
}

type ActorLink struct {
Expand Down Expand Up @@ -346,10 +347,6 @@ func QueryActors(r RequestActorList, enablePreload bool) ResponseActorList {
tx = tx.Where("actors.name NOT IN (?)", excludedCast)
}

if r.JumpTo.OrElse("") != "" {
tx = tx.Where("actors.name > ?", r.JumpTo.OrElse(""))
}

if r.MinAge.OrElse(0) > 18 || r.MaxAge.OrElse(100) < 100 {
startRange := time.Now().AddDate(r.MinAge.OrElse(0)*-1, 0, 0)
endRange := time.Now().AddDate(r.MaxAge.OrElse(0)*-1, 0, 0)
Expand Down Expand Up @@ -476,6 +473,21 @@ func QueryActors(r RequestActorList, enablePreload bool) ResponseActorList {
return db.Order("release_date DESC").Where("is_hidden = 0")
})

if r.JumpTo.OrElse("") != "" {
// if we want to jump to actors starting with a specific letter, then we need to work out the offset to them
cnt := 0
txList := tx.Select(`distinct actors.name`)
txList.Find(&out.Actors)
for idx, actor := range out.Actors {
if strings.ToLower(actor.Name) >= strings.ToLower(r.JumpTo.OrElse("")) {
break
}
cnt = idx
}
offset = (cnt / limit) * limit
}
out.Offset = offset

tx = tx.Select(`distinct actors.*,
(select AVG(s.star_rating) scene_avg from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 ) as scene_rating_average
`)
Expand Down
3 changes: 2 additions & 1 deletion ui/src/store/actorList.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,14 @@ const actions = {
.json()

state.isLoading = false
state.filters.jumpTo = "" // clear the jumpto value now that we have the data

if (iOffset === 0) {
commit('setActors', [])
}

commit('setActors', state.actors=data.actors)
state.offset = iOffset + state.limit
state.offset = data.offset + state.limit
state.total = data.results
}
}
Expand Down
6 changes: 6 additions & 0 deletions ui/src/views/actors/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ export default {
if (this.$store.state.overlay.actordetails.show){
return
}
if (this.$store.state.overlay.details.show){
return
}
if (this.current * this.limit >= this.total) {
this.current = 1
} else {
Expand All @@ -267,6 +270,9 @@ export default {
if (this.$store.state.overlay.actordetails.show){
return
}
if (this.$store.state.overlay.details.show){
return
}
if (this.current > 1) {
this.current -= 1
} else {
Expand Down

0 comments on commit 9ccbff2

Please sign in to comment.