Skip to content

Commit

Permalink
Merge Pagination.vue fix from dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardhanna committed Aug 14, 2024
1 parent ad4d491 commit 611425b
Showing 1 changed file with 70 additions and 72 deletions.
142 changes: 70 additions & 72 deletions resources/js/components/Pagination.vue
Original file line number Diff line number Diff line change
@@ -1,89 +1,87 @@
<template>

<nav class="codeweek-pagination" role="navigation" aria-label="pagination">
<ul>
<li>
<a class="back"
@click.prevent="changePage(pagination.current_page - 1)"
:disabled="pagination.current_page <= 1">
{{$t('pagination.previous')}}
</a>
</li>
<li v-for="page in pages">
<a v-if="pagination.current_page != page"
class="page"
@click.prevent="changePage(page)">
{{ page }}
</a>
<a v-else
class="page current">
{{ page }}
</a>
</li>
<li>
<a class="next"
@click.prevent="changePage(pagination.current_page + 1)"
:disabled="pagination.current_page >= pagination.last_page">
{{$t('pagination.next')}}
</a>
</li>
</ul>
</nav>

<nav class="codeweek-pagination" role="navigation" aria-label="pagination">
<ul>
<li>
<a
class="back"
@click.prevent="changePage(pagination.current_page - 1)"
:disabled="pagination.current_page <= 1"
>
{{ $t('pagination.previous') }}
</a>
</li>
<li v-for="page in pages">
<a
v-if="pagination.current_page != page"
class="page"
@click.prevent="changePage(page)"
>
{{ page }}
</a>
<a v-else class="page current">
{{ page }}
</a>
</li>
<li>
<a
class="next"
@click.prevent="changePage(pagination.current_page + 1)"
:disabled="pagination.current_page >= pagination.last_page"
>
{{ $t('pagination.next') }}
</a>
</li>
</ul>
</nav>
</template>

<style>
.pagination {
margin-top: 40px;
}
.pagination {
margin-top: 40px;
}
</style>

<script>
export default {
props: ['pagination', 'offset'],
methods: {
isCurrentPage(page) {
return this.pagination.current_page === page;
},
export default {
props: ['pagination', 'offset'],
changePage(page) {
if (page === 0 || (page > this.pagination.last_page)){
return;
}
methods: {
isCurrentPage(page) {
return this.pagination.current_page === page;
},
if (page > this.pagination.last_page) {
page = this.pagination.last_page;
}
this.pagination.current_page = page;
this.$dispatch('paginate');
}
},
changePage(page) {
if (page < 1 || page > this.pagination.last_page) {
return;
}
this.pagination.current_page = page;
this.$emit('paginate', page); // Emit the event with the new page number
}
},
computed: {
pages() {
let pages = [];
computed: {
pages() {
let pages = [];
let from = this.pagination.current_page - Math.floor(this.offset / 2);
let from = this.pagination.current_page - Math.floor(this.offset / 2);
if (from < 1) {
from = 1;
}
if (from < 1) {
from = 1;
}
let to = from + this.offset - 1;
let to = from + this.offset - 1;
if (to > this.pagination.last_page) {
to = this.pagination.last_page;
}
if (to > this.pagination.last_page) {
to = this.pagination.last_page;
}
while (from <= to) {
pages.push(from);
from++;
}
while (from <= to) {
pages.push(from);
from++;
}
return pages;
}
}
return pages;
}
</script>
}
};
</script>

0 comments on commit 611425b

Please sign in to comment.