Skip to content

Commit

Permalink
Merge pull request #1022 from bedita/fix-paginated-position
Browse files Browse the repository at this point in the history
Fix paginated position
  • Loading branch information
didoda committed Jul 4, 2023
2 parents 5612a42 + 8bedca6 commit 745efa6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions resources/js/app/components/relation-view/relation-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ export default {
},

objects(newObjects) {
this.positions = newObjects.reduce((positions, object, index) => {
positions[object.id] = index + 1;
this.positions = newObjects.reduce((positions, object) => {
positions[object.id] = object.meta?.relation?.position || '';
return positions;
}, {});
this.priorities = newObjects.reduce((priorities, object) => {
priorities[object.id] = object?.meta?.relation?.priority || '';
priorities[object.id] = object.meta?.relation?.priority || '';
return priorities;
}, {});
},
Expand Down Expand Up @@ -341,8 +341,10 @@ export default {
this.objects.splice(newIndex, 0, this.objects.splice(oldIndex, 1)[0]);

this.objects = this.objects.map((object, index) => {
object.meta.relation.position = ascending ? index + 1 : this.pagination.count - index;
object.meta.relation.position += this.pagination.page_size * (this.pagination.page - 1);
const { count, page_size, page } = this.pagination;
object.meta.relation.position = ascending
? (page_size * (page - 1) + 1 + index)
: (count - (page_size * (page - 1)) - index);
this.modifyRelation(object);

return object;
Expand Down
5 changes: 4 additions & 1 deletion resources/js/app/mixins/paginated-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export const PaginatedContentMixin = {
}
if (order.indexOf('position') >= 0) {
const ascending = order === 'position';
let i = ascending ? 1 : json.meta.pagination.count;
const { count, page_size, page } = json.meta.pagination;
let i = ascending
? (page_size * (page - 1) + 1)
: (count - (page_size * (page - 1)));
for (let obj of objects) {
obj.meta.relation.position = i;
i = ascending ? i+1 : i-1;
Expand Down

0 comments on commit 745efa6

Please sign in to comment.