2016-10-31 17:51:24 -04:00
|
|
|
/* global gl, Flash */
|
2016-10-30 03:28:57 -04:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-30 03:28:57 -04:00
|
|
|
gl.PipelineStore = class {
|
2016-11-10 12:16:27 -05:00
|
|
|
fetchDataLoop(Vue, pageNum, url) {
|
2016-10-31 17:06:25 -04:00
|
|
|
const goFetch = () =>
|
2016-11-10 12:16:27 -05:00
|
|
|
this.$http.get(`${url}?page=${pageNum}`)
|
2016-10-31 17:06:25 -04:00
|
|
|
.then((response) => {
|
2016-11-10 14:22:16 -05:00
|
|
|
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);
|
2016-11-10 14:46:29 -05:00
|
|
|
Vue.set(this, 'count', res.count);
|
2016-10-31 18:10:50 -04:00
|
|
|
}, () => new Flash(
|
|
|
|
'Something went wrong on our end.'
|
|
|
|
));
|
2016-10-31 17:06:25 -04:00
|
|
|
|
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.'
|
|
|
|
));
|
|
|
|
|
2016-10-31 17:06:25 -04:00
|
|
|
goFetch();
|
|
|
|
|
2016-10-31 15:02:34 -04:00
|
|
|
this.intervalId = setInterval(() => {
|
2016-11-10 15:17:33 -05:00
|
|
|
goUpdate();
|
2016-11-08 14:23:29 -05:00
|
|
|
}, 3000);
|
2016-10-31 00:11:57 -04:00
|
|
|
}
|
2016-10-30 03:28:57 -04:00
|
|
|
};
|
|
|
|
})(window.gl || (window.gl = {}));
|