Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pagination for nested modules. #2637

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion frontend/js/components/table/Paginate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
{{ $trans('listing.paginate.rows-per-page') }}
<template v-if="availableOffsets.length > 1">
<a17-dropdown ref="paginateDropdown" position="bottom-right">
<button @click="$refs.paginateDropdown.toggle()" class="paginate__button">{{ newOffset }}</button>
<button @click="$refs.paginateDropdown.toggle()" class="paginate__button">{{ newOffset !== -1 ? newOffset : $trans('listing.paginate.everything') }}</button>
<div slot="dropdown__content">
<button type="button" v-for="availableOffset in availableOffsets" :key="availableOffset" :class="{ 'dropdown__active' : availableOffset === newOffset }" @click="changeOffset(availableOffset)">{{ availableOffset }}</button>
<button type="button" v-if="isShowEverythingEnabled" :class="{ 'dropdown__active' : availableOffset === newOffset }" @click="changeOffset(-1)">
{{ $trans('listing.paginate.everything') }}
</button>
</div>
</a17-dropdown>
</template>
Expand Down Expand Up @@ -34,6 +37,10 @@
type: Number,
default: 60
},
isShowEverythingEnabled: {
type: Boolean,
default: false
},
availableOffsets: {
type: Array,
default: function () { return [] }
Expand Down
40 changes: 40 additions & 0 deletions frontend/js/components/table/nested/NestedDatatable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
:maxDepth="maxDepth"
:draggable="draggable"
/>

<a17-paginate v-if="maxPage > 1 || initialMaxPage > maxPage && !isEmpty" :max="maxPage" :value="page" :isShowEverythingEnabled="true"
:offset="offset" :availableOffsets="[initialOffset,initialOffset*3,initialOffset*6]"
@changePage="updatePage" @changeOffset="updateOffset"
/>
</div>
</div>
</div>
Expand All @@ -27,9 +32,12 @@
<script>
import { DatatableMixin, DraggableMixin, NestedDraggableMixin } from '@/mixins/index'
import { DATATABLE } from '@/store/mutations/index'
import ACTIONS from '@/store/actions'
import { mapState } from 'vuex'

import a17Table from './../Table.vue'
import a17Tablehead from './../TableHead.vue'
import a17Paginate from './../Paginate.vue'
import NestedList from './NestedList'

export default {
Expand All @@ -43,8 +51,35 @@
components: {
'a17-table': a17Table,
'a17-tablehead': a17Tablehead,
'a17-paginate': a17Paginate,
'a17-nested-list': NestedList
},
computed: {
...mapState({
page: state => state.datatable.page,
offset: state => state.datatable.offset,
maxPage: state => state.datatable.maxPage,
initialOffset: state => state.datatable.defaultOffset,
initialMaxPage: state => state.datatable.defaultMaxPage
})
},
methods: {
updateOffset: function (value) {
this.$store.commit(DATATABLE.UPDATE_DATATABLE_PAGE, 1)
this.$store.commit(DATATABLE.UPDATE_DATATABLE_OFFSET, value)

// reload datas
this.$store.dispatch(ACTIONS.GET_DATATABLE)
},
updatePage: function (value) {
if (value !== this.page) {
this.$store.commit(DATATABLE.UPDATE_DATATABLE_PAGE, value)

// reload datas
this.$store.dispatch(ACTIONS.GET_DATATABLE)
}
}
},
beforeMount: function () {
function findBulkColumn (column) {
return column.name === 'bulk'
Expand Down Expand Up @@ -93,5 +128,10 @@
.nested-datatable__table {
position: relative;
width: 100%;

.paginate {
border: 1px solid #F2F2F2;
border-top: 0;
}
}
</style>
4 changes: 4 additions & 0 deletions frontend/js/components/table/nested/NestedList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@
// border:1px solid grey;
padding: 15px 0px 15px 0px;

&:first-child {
padding-bottom: 0px;
}

* {
will-change: auto;
}
Expand Down
1 change: 1 addition & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
'listing-empty-message' => 'There is no item here yet.',
'paginate' => [
'rows-per-page' => 'Rows per page:',
'everything' => 'Everything',
],
'bulk-selected-item' => 'item selected',
'bulk-selected-items' => 'items selected',
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Admin/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ protected function getIndexData(array $prependScope = []): array
'hiddenFilters' => $this->filters(),
'filterLinks' => $this->filterLinks ?? [],
'maxPage' => method_exists($items, 'lastPage') ? $items->lastPage() : 1,
'defaultMaxPage' => method_exists($items, 'total') ? ceil($items->total() / $this->perPage) : 1,
'defaultMaxPage' => ceil((method_exists($items, 'total') ? $items->total() : count($items)) / $this->perPage),
'offset' => method_exists($items, 'perPage') ? $items->perPage() : count($items),
'defaultOffset' => $this->perPage,
] + $this->getIndexUrls($this->moduleName, $this->routePrefix);
Expand Down
5 changes: 5 additions & 0 deletions src/Repositories/ModuleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Kalnoy\Nestedset\NodeTrait;
use ReflectionClass;

abstract class ModuleRepository
Expand Down Expand Up @@ -61,6 +62,10 @@ public function get(
array $appliedFilters = []
): LengthAwarePaginator|Collection {
$query = $this->model->with($with);

if (in_array(NodeTrait::class, class_uses($this->model))) {
$query = $query->where('parent_id', NULL);
}

$query = $this->filter($query, $scopes);
$query = $this->order($query, $orders);
Expand Down
Loading