Jonatan Nilsson
71b1725655
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed
39 lines
1 KiB
JavaScript
39 lines
1 KiB
JavaScript
const Paginator = {
|
|
view: function(vnode) {
|
|
let total = vnode.attrs.total
|
|
let currentPage = vnode.attrs.page
|
|
let perPage = vnode.attrs.perPage || 10
|
|
let maxPage = total / perPage + 1
|
|
|
|
if (total <= perPage) return null
|
|
|
|
return m('paginator', [
|
|
currentPage > 1
|
|
? [
|
|
m(m.route.Link, {
|
|
href: vnode.attrs.base,
|
|
}, 'First'),
|
|
m(m.route.Link, {
|
|
href: vnode.attrs.base + (currentPage > 2
|
|
? '?page=' + (currentPage - 1)
|
|
: ''
|
|
),
|
|
}, 'Previous'),
|
|
]
|
|
: [ m('div'), m('div')],
|
|
m('div', 'Page ' + currentPage),
|
|
currentPage < maxPage
|
|
? [
|
|
m(m.route.Link, {
|
|
href: vnode.attrs.base + '?page=' + (currentPage + 1),
|
|
}, 'Next'),
|
|
m(m.route.Link, {
|
|
href: vnode.attrs.base + '?page=' + maxPage,
|
|
}, 'Last')
|
|
]
|
|
: [ m('div'), m('div')],
|
|
])
|
|
},
|
|
}
|
|
|
|
module.exports = Paginator
|