Commit 25714603 authored by Regis's avatar Regis

begin pagination logic - add Flash to error - refactor

parent 87d4d235
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
Vue.use(VueResource); Vue.use(VueResource);
new Vue({ return new Vue({
el: '.vue-pipelines-index', el: '.vue-pipelines-index',
data: { data: {
scope: project.dataset.projectId, scope: project.dataset.projectId,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
pipelines: [], pipelines: [],
currentPage: '', currentPage: '',
intervalId: '', intervalId: '',
pageNum: 'page=1',
}; };
}, },
props: [ props: [
...@@ -18,7 +19,10 @@ ...@@ -18,7 +19,10 @@
'store', 'store',
], ],
created() { created() {
this.store.fetchDataLoop.call(this, Vue); const url = window.location.href;
if (url.includes('?')) this.pageNum = url.split('?')[1];
// now fetch page appropriate data
this.store.fetchDataLoop.call(this, Vue, this.pageNum);
}, },
methods: { methods: {
shortSha(pipeline) { shortSha(pipeline) {
...@@ -26,8 +30,7 @@ ...@@ -26,8 +30,7 @@
}, },
changePage() { changePage() {
// clearInterval(this.intervalId); // clearInterval(this.intervalId);
// this.store.fetchCommits.call(this, Vue); // this.store.fetchDataLoop.call(this, Vue, this.pageNum);
// this.store.fetchDataLoop.call(this, Vue);
}, },
}, },
template: ` template: `
......
/* global gl */ /* global gl, Flash */
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
((gl) => { ((gl) => {
const api = '/api/v3/projects'; const api = '/api/v3/projects';
gl.PipelineStore = class { gl.PipelineStore = class {
fetchDataLoop(Vue) { fetchDataLoop(Vue, pageNum) {
const goFetch = () => const goFetch = () =>
this.$http.get( this.$http.get(`${api}/${this.scope}/pipelines?per_page=30&${pageNum}`)
`${api}/${this.scope}/pipelines?per_page=5&page=1`
)
.then((response) => { .then((response) => {
Vue.set(this, 'pipelines', JSON.parse(response.body)); Vue.set(this, 'pipelines', JSON.parse(response.body));
}, () => { }, () => new Flash('Something went wrong on our end.'));
console.error('API Error for Pipelines');
});
// inital fetch and then start timeout loop
goFetch(); goFetch();
// eventually clearInterval(this.intervalId) // eventually clearInterval(this.intervalId)
this.intervalId = setInterval(() => { this.intervalId = setInterval(() => {
console.log('DID IT');
goFetch(); goFetch();
}, 30000); }, 60000);
} }
}; };
})(window.gl || (window.gl = {})); })(window.gl || (window.gl = {}));
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