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

125 lines
3.5 KiB
JavaScript
Raw Normal View History

/* global Vue, gl */
/* eslint-disable no-param-reassign */
((gl) => {
gl.VueGlPagination = Vue.extend({
props: [
'changepage',
'count',
'pagenum',
],
2016-11-07 21:16:57 +00:00
data() {
return {
nslice: +this.pagenum,
endcount: this.last,
2016-11-07 21:16:57 +00:00
};
},
methods: {
pagenumberstatus(n) {
2016-11-03 17:42:12 +00:00
if (n - 1 === +this.pagenum) return 'active';
return '';
},
prevstatus() {
if (+this.pagenum > 1) return '';
return 'disabled';
},
createSection(n) {
return Array.from(Array(n)).map((e, i) => i);
},
},
computed: {
2016-11-07 21:16:57 +00:00
dynamicpage() {
const section = this.createSection(this.upcount);
2016-11-07 21:16:57 +00:00
section.shift();
this.nslice = +this.pagenum;
this.endcount = +this.pagenum + 5;
2016-11-07 21:43:11 +00:00
if (+this.pagenum + 5 <= this.last) {
return section.slice(+this.pagenum, +this.pagenum + 5);
}
if (+this.pagenum + 5 > this.last) {
return section.slice(this.last - 5, this.last);
}
2016-11-07 21:16:57 +00:00
},
paginationsection() {
if (this.last < 6 && this.pagenum < 6) {
const pageArray = this.createSection(6);
pageArray.shift();
return pageArray.slice(0, this.upcount);
}
2016-11-07 21:16:57 +00:00
return this.dynamicpage;
},
2016-11-03 17:34:18 +00:00
last() {
return Math.ceil(+this.count / 5);
2016-11-03 17:34:18 +00:00
},
upcount() {
return +this.last + 1;
},
endspread() {
2016-11-07 21:43:11 +00:00
if (+this.pagenum < this.last) return true;
2016-11-06 20:56:08 +00:00
return false;
},
begspread() {
if (+this.pagenum > 5 && +this.pagenum < this.last) return true;
2016-11-06 20:56:08 +00:00
return false;
},
},
template: `
<div class="gl-pagination">
<ul class="pagination clearfix" v-for='n in paginationsection'>
2016-11-07 21:43:11 +00:00
<li
:class='prevstatus(n)'
v-if='n - 1 === 1 || n - 1 === nslice || n - 1 === this.last - 5'
>
<span @click='changepage($event, {where: pagenum - 1})'>Prev</span>
</li>
2016-11-07 21:43:11 +00:00
<li v-if='n - 1 === last && upcount > 4 && begspread'>
<span class="gap"></span>
</li>
<li :class='pagenumberstatus(n)' v-if='n >= 2'>
<span @click='changepage($event)'>{{(n - 1)}}</span>
</li>
2016-11-07 21:43:11 +00:00
<li v-if='(n === upcount || n === endcount) && +pagenum + 5 !== last'>
2016-11-03 17:42:12 +00:00
<span class="gap"></span>
2016-11-03 17:32:22 +00:00
</li>
2016-11-06 21:00:36 +00:00
<li
class="next"
v-if='(n === upcount || n === endcount) && pagenum !== last'
>
<span @click='changepage($event,{where: +pagenum + 1})'>Next</span>
</li>
2016-11-06 21:00:36 +00:00
<li
class="last"
2016-11-07 21:16:57 +00:00
v-if='(n === upcount || n === endcount) && +pagenum !== last'
2016-11-06 21:00:36 +00:00
>
<span @click='changepage($event, {where: last})'>Last »</span>
</li>
</ul>
</div>
`,
// render(createElement) {
// return createElement('div', {
// class: {
// 'gl-pagination': true,
// },
// }, [createElement('ul', {
// class: {
// pagination: true,
// clearfix: true,
// },
// }, this.paginationsection.map((e, i) => {
// if (!i) return createElement('li', [createElement('span', {
// class: {
// prev: this.prevstatus,
// },
// }, 'Prev')]);
// if (i) {
// return createElement('li',
// [createElement('span', i)]
// );
// }
// })),
// ]);
// },
});
})(window.gl || (window.gl = {}));