Skip to content

Commit

Permalink
fix: update positions on sort
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Jul 4, 2023
1 parent eeb4e9d commit 8bedca6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions resources/js/app/components/relation-view/relation-view.js
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions resources/js/app/mixins/paginated-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ export const PaginatedContentMixin = {
if (order.indexOf('position') >= 0) {
const ascending = order === 'position';
const { count, page_size, page } = json.meta.pagination;
let i = ascending ?
(page_size * (page - 1) + 1) :
(count - (page_size * (page - 1)));
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 8bedca6

Please sign in to comment.