gitlab-org--gitlab-foss/app/assets/javascripts/vue_pipelines_index/store.js.es6

61 lines
1.8 KiB
JavaScript
Raw Normal View History

/* global gl, Flash */
/* eslint-disable no-param-reassign */
((gl) => {
2016-11-10 15:17:33 -05:00
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 {
2016-11-10 12:16:27 -05:00
fetchDataLoop(Vue, pageNum, url) {
const goFetch = () =>
2016-11-10 12:16:27 -05:00
this.$http.get(`${url}?page=${pageNum}`)
.then((response) => {
const res = JSON.parse(response.body);
2016-11-10 15:17:33 -05:00
Vue.set(this, 'updatedAt', res.updated_at);
2016-11-10 12:16:27 -05:00
Vue.set(this, 'pipelines', res.pipelines);
Vue.set(this, 'count', res.count);
2016-10-31 18:10:50 -04:00
}, () => new Flash(
'Something went wrong on our end.'
));
2016-11-10 15:17:33 -05:00
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(() => {
2016-11-10 15:17:33 -05:00
goUpdate();
2016-11-08 14:23:29 -05:00
}, 3000);
}
};
})(window.gl || (window.gl = {}));