Commit 64e8ab95 authored by Regis's avatar Regis

pagination logic almost complete - active and inactive elements next - page gap not working

parent 77b0d605
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
pipelines: [], pipelines: [],
currentPage: '', currentPage: '',
intervalId: '', intervalId: '',
pageNum: 1, pagenum: 1,
}; };
}, },
props: [ props: [
...@@ -27,19 +27,19 @@ ...@@ -27,19 +27,19 @@
], ],
created() { created() {
const url = window.location.toString(); const url = window.location.toString();
if (~url.indexOf('?')) this.pageNum = url.split('?')[1].split('=')[1]; if (~url.indexOf('?')) this.pagenum = url.split('?')[1].split('=')[1];
this.store.fetchDataLoop.call(this, Vue, this.pageNum); this.store.fetchDataLoop.call(this, Vue, this.pagenum);
}, },
methods: { methods: {
shortsha(pipeline) { shortsha(pipeline) {
return pipeline.sha.slice(0, 8); return pipeline.sha.slice(0, 8);
}, },
changepage(event) { changepage(event) {
this.pageNum = +event.target.innerText; this.pagenum = +event.target.innerText;
// use p instead of page to avoid rails tyring to make an actual request // use p instead of page to avoid rails tyring to make an actual request
window.history.pushState({}, null, `?p=${this.pageNum}`); window.history.pushState({}, null, `?p=${this.pagenum}`);
clearInterval(this.intervalId); clearInterval(this.intervalId);
this.store.fetchDataLoop.call(this, Vue, this.pageNum); this.store.fetchDataLoop.call(this, Vue, this.pagenum);
}, },
pipelineurl(id) { pipelineurl(id) {
return `pipelines/${id}`; return `pipelines/${id}`;
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
</table> </table>
</div> </div>
<vue-gl-pagination <vue-gl-pagination
:pagenum='pagenum'
:changepage='changepage' :changepage='changepage'
:pages='pipelines.length' :pages='pipelines.length'
:count='count' :count='count'
......
...@@ -3,55 +3,61 @@ ...@@ -3,55 +3,61 @@
((gl) => { ((gl) => {
gl.VueGlPagination = Vue.extend({ gl.VueGlPagination = Vue.extend({
data() {
return {
last: Math.ceil(+this.count / 5),
};
},
props: [ props: [
'changepage', 'changepage',
'pages', 'pages',
'count', 'count',
'pagenum',
], ],
methods: {
pagenumberstatus(n) {
if (n - 1 === +this.pagenum) return 'page active';
return '';
},
},
computed: { computed: {
lastpage() { lastpage() {
const lastPage = Math.ceil(+this.count / 5); return `pipelines?p=${this.last}`;
return `pipelines?page=${lastPage}`; },
upcount() {
return +this.last + 1;
},
prev() {
if (this.pagenum === 1) return 1;
return this.pagenum - 1;
},
next() {
if (this.pagenum === this.last) return `pipelines?p=${this.pagenum}`;
return `pipelines?p=${this.pagenum + 1}`;
}, },
}, },
template: ` template: `
<div class="gl-pagination"> <div class="gl-pagination">
<ul class="pagination clearfix"> <ul
<li class="prev disabled"> class="pagination clearfix"
v-for='n in upcount'
>
<li class="prev disabled" v-if='n === 1'>
<span>Prev</span> <span>Prev</span>
</li> </li>
<li class="page active"> <li :class='pagenumberstatus(n)' v-else>
<a @click='changepage($event)'>1</a> <a @click='changepage($event)'>{{(n - 1)}}</a>
</li>
<li class="page">
<a
rel="next"
@click='changepage($event)'
>
2
</a>
</li>
<li class="page">
<a @click='changepage($event)'>3</a>
</li>
<li class="page">
<a @click='changepage($event)'>4</a>
</li>
<li class="page">
<a @click='changepage($event)'>5</a>
</li>
<li class="page">
<span class="page gap">…</span>
</li> </li>
<li class="next"> <!--
<a still working on this bit
rel="next" <li class="page" v-if='n === upcount - 1'>
href="pipelines?page=2" <span class="page gap">…</span>
> </li>
Next -->
</a> <li class="next" v-if='n === upcount'>
<a rel="next" :href='next'>Next</a>
</li> </li>
<li class="last"> <li class="last" v-if='n === upcount'>
<a :href='lastpage'>Last »</a> <a :href='lastpage'>Last »</a>
</li> </li>
</ul> </ul>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment