Commit f41c3c02 authored by Regis's avatar Regis

add update pipelines endpoint checker

parent 38bb3488
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
data() { data() {
return { return {
pipelines: [], pipelines: [],
currentPage: '',
intervalId: '', intervalId: '',
updatedAt: '',
pagenum: 1, pagenum: 1,
count: { count: {
all: 0, all: 0,
......
...@@ -2,22 +2,58 @@ ...@@ -2,22 +2,58 @@
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
((gl) => { ((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 { gl.PipelineStore = class {
fetchDataLoop(Vue, pageNum, url) { fetchDataLoop(Vue, pageNum, url) {
const goFetch = () => const goFetch = () =>
this.$http.get(`${url}?page=${pageNum}`) this.$http.get(`${url}?page=${pageNum}`)
.then((response) => { .then((response) => {
const res = JSON.parse(response.body); const res = JSON.parse(response.body);
Vue.set(this, 'updatedAt', res.updated_at);
Vue.set(this, 'pipelines', res.pipelines); Vue.set(this, 'pipelines', res.pipelines);
Vue.set(this, 'count', res.count); Vue.set(this, 'count', res.count);
}, () => new Flash( }, () => new Flash(
'Something went wrong on our end.' '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(); goFetch();
this.intervalId = setInterval(() => { this.intervalId = setInterval(() => {
goFetch(); goUpdate();
}, 3000); }, 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