gitlab-org--gitlab-foss/app/assets/javascripts/vue_pagination/index.js.es6

51 lines
1.3 KiB
JavaScript
Raw Normal View History

/* global Vue, gl */
/* eslint-disable no-param-reassign */
((gl) => {
gl.VueGlPagination = Vue.extend({
props: [
'changepage',
'count',
'pagenum',
],
methods: {
2016-11-08 20:04:30 +00:00
pagestatus(n) {
if (n - 1 === +this.pagenum) return true;
return false;
},
prevstatus(index) {
if (index > 0) return false;
if (+this.pagenum < 2) return true;
return false;
},
2016-11-08 19:23:29 +00:00
createSection(n) { return Array.from(Array(n)).map((e, i) => i); },
},
computed: {
2016-11-08 19:23:29 +00:00
last() { return Math.ceil(+this.count / 5); },
getItems() {
const items = [];
const pages = this.createSection(+this.last + 1);
pages.shift();
2016-11-08 20:04:30 +00:00
items.push({ text: 'Prev', class: this.prevstatus() });
2016-11-08 19:23:29 +00:00
pages.forEach(i => items.push({ text: i }));
if (+this.pagenum < this.last) items.push({ text: 'Next' });
if (+this.pagenum !== this.last) items.push({ text: 'Last »' });
return items;
},
},
template: `
<div class="gl-pagination">
2016-11-08 20:04:30 +00:00
<ul class="pagination clearfix" v-for='(item, i) in getItems'>
<li :class="{active: pagestatus(i + 1), disabled: prevstatus(i)}">
2016-11-08 19:23:29 +00:00
<span @click='changepage($event, last)'>{{item.text}}</span>
</li>
</ul>
</div>
`,
});
})(window.gl || (window.gl = {}));