Commit f41c3c02 authored by Regis's avatar Regis

add update pipelines endpoint checker

parent 38bb3488
......@@ -17,8 +17,8 @@
data() {
return {
pipelines: [],
currentPage: '',
intervalId: '',
updatedAt: '',
pagenum: 1,
count: {
all: 0,
......
......@@ -2,22 +2,58 @@
/* eslint-disable no-param-reassign */
((gl) => {
class PipelineUpdater {
constructor(pipelines) {
this.pipelines = pipelines;
this.updateClone = (update, newPipe) => {
update.forEach((pipe) => {
if (pipe.id === newPipe.id) pipe = Object.assign(pipe, newPipe);
});
};
}
updatePipelines(apiResponse) {
const update = this.pipelines.map(e => e);
apiResponse.pipelines.forEach((newPipe) => {
if (Object.keys(newPipe).length <= 2) return;
if (Object.keys(newPipe).length > 3) {
update.unshift(newPipe);
} else {
this.updateClone(update, newPipe);
}
});
this.pipelines = update;
return this.pipelines;
}
}
gl.PipelineStore = class {
fetchDataLoop(Vue, pageNum, url) {
const goFetch = () =>
this.$http.get(`${url}?page=${pageNum}`)
.then((response) => {
const res = JSON.parse(response.body);
Vue.set(this, 'updatedAt', res.updated_at);
Vue.set(this, 'pipelines', res.pipelines);
Vue.set(this, 'count', res.count);
}, () => new Flash(
'Something went wrong on our end.'
));
const goUpdate = () =>
this.$http.get(`${url}?page=${pageNum}&updated_at=${this.updatedAt}`)
.then((response) => {
const res = JSON.parse(response.body);
const p = new PipelineUpdater(this.pipelines);
Vue.set(this, 'pipelines', p.updatePipelines(res));
}, () => new Flash(
'Something went wrong on our end.'
));
goFetch();
this.intervalId = setInterval(() => {
goFetch();
goUpdate();
}, 3000);
}
};
......
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