2016-10-31 17:51:24 -04:00
|
|
|
/* global gl, Flash */
|
2016-12-02 17:05:01 -05:00
|
|
|
/* eslint-disable no-param-reassign, no-underscore-dangle */
|
2016-10-30 03:28:57 -04:00
|
|
|
|
|
|
|
((gl) => {
|
2016-12-16 17:50:28 -05:00
|
|
|
const pageValues = headers => ({
|
|
|
|
perPage: +headers['X-Per-Page'],
|
|
|
|
page: +headers['X-Page'],
|
|
|
|
total: +headers['X-Total'],
|
|
|
|
totalPages: +headers['X-Total-Pages'],
|
|
|
|
nextPage: +headers['X-Next-Page'],
|
|
|
|
previousPage: +headers['X-Prev-Page'],
|
|
|
|
});
|
2016-12-07 15:35:26 -05:00
|
|
|
|
2016-10-30 03:28:57 -04:00
|
|
|
gl.PipelineStore = class {
|
2016-12-05 15:17:23 -05:00
|
|
|
fetchDataLoop(Vue, pageNum, url, apiScope) {
|
2016-11-18 17:33:41 -05:00
|
|
|
const updatePipelineNums = (count) => {
|
|
|
|
const { all } = count;
|
|
|
|
const running = count.running_or_pending;
|
|
|
|
document.querySelector('.js-totalbuilds-count').innerHTML = all;
|
2016-11-15 16:06:26 -05:00
|
|
|
document.querySelector('.js-running-count').innerHTML = running;
|
|
|
|
};
|
|
|
|
|
2016-10-31 17:06:25 -04:00
|
|
|
const goFetch = () =>
|
2016-12-05 15:17:23 -05:00
|
|
|
this.$http.get(`${url}?scope=${apiScope}&page=${pageNum}`)
|
2016-10-31 17:06:25 -04:00
|
|
|
.then((response) => {
|
2016-12-07 15:35:26 -05:00
|
|
|
const pageInfo = pageValues(response.headers);
|
|
|
|
Vue.set(this, 'pageInfo', pageInfo);
|
|
|
|
|
2016-11-10 14:22:16 -05:00
|
|
|
const res = JSON.parse(response.body);
|
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-12-07 15:35:26 -05:00
|
|
|
|
2016-11-18 17:33:41 -05:00
|
|
|
updatePipelineNums(this.count);
|
2016-11-11 00:21:09 -05:00
|
|
|
this.pageRequest = false;
|
2016-12-16 17:37:18 -05:00
|
|
|
}, () => {
|
|
|
|
this.pageRequest = false;
|
|
|
|
return new Flash('Something went wrong on our end.');
|
|
|
|
});
|
2016-11-10 15:17:33 -05:00
|
|
|
|
2016-10-31 17:06:25 -04:00
|
|
|
goFetch();
|
|
|
|
|
2016-12-02 17:05:01 -05:00
|
|
|
const startTimeLoops = () => {
|
|
|
|
this.timeLoopInterval = setInterval(() => {
|
|
|
|
this.$children
|
|
|
|
.filter(e => e.$options._componentTag === 'time-ago')
|
|
|
|
.forEach(e => e.changeTime());
|
|
|
|
}, 1000);
|
|
|
|
};
|
|
|
|
|
|
|
|
startTimeLoops();
|
|
|
|
|
|
|
|
const removeTimeIntervals = () => {
|
|
|
|
clearInterval(this.timeLoopInterval);
|
2016-11-30 03:23:51 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const startIntervalLoops = () => {
|
2016-12-02 17:05:01 -05:00
|
|
|
startTimeLoops();
|
2016-11-30 03:23:51 -05:00
|
|
|
};
|
2016-11-12 03:57:23 -05:00
|
|
|
|
2016-12-02 13:42:26 -05:00
|
|
|
const removeAll = () => {
|
2016-12-16 17:42:05 -05:00
|
|
|
window.removeEventListener('beforeunload', removeTimeIntervals);
|
|
|
|
window.removeEventListener('focus', startIntervalLoops);
|
|
|
|
window.removeEventListener('blur', removeTimeIntervals);
|
2016-12-15 12:04:26 -05:00
|
|
|
|
|
|
|
// turbolinks event handler
|
2016-12-02 17:10:31 -05:00
|
|
|
document.removeEventListener('page:fetch', () => {});
|
2016-11-30 03:23:51 -05:00
|
|
|
};
|
|
|
|
|
2016-12-02 17:05:01 -05:00
|
|
|
window.addEventListener('beforeunload', removeTimeIntervals);
|
2016-12-02 13:42:26 -05:00
|
|
|
window.addEventListener('focus', startIntervalLoops);
|
2016-12-02 17:05:01 -05:00
|
|
|
window.addEventListener('blur', removeTimeIntervals);
|
2016-12-15 12:04:26 -05:00
|
|
|
|
|
|
|
// turbolinks event handler
|
2016-12-02 13:42:26 -05:00
|
|
|
document.addEventListener('page:fetch', removeAll);
|
2016-10-31 00:11:57 -04:00
|
|
|
}
|
2016-10-30 03:28:57 -04:00
|
|
|
};
|
|
|
|
})(window.gl || (window.gl = {}));
|