BigW Consortium Gitlab

Commit d6061b73 by Regis

much simpler time logic - clean up - [ci skip]

parent 004a9c6b
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
/* eslint-disable no-param-reassign, no-bitwise*/ /* eslint-disable no-param-reassign, no-bitwise*/
((gl) => { ((gl) => {
const REALTIME = false;
const SPREAD = '...'; const SPREAD = '...';
const PREV = 'Prev'; const PREV = 'Prev';
const NEXT = 'Next'; const NEXT = 'Next';
...@@ -24,7 +23,7 @@ ...@@ -24,7 +23,7 @@
data() { data() {
return { return {
pipelines: [], pipelines: [],
allTimeIntervals: [], timeLoopInterval: '',
intervalId: '', intervalId: '',
updatedAt: '', updatedAt: '',
pagenum: 1, pagenum: 1,
...@@ -57,7 +56,7 @@ ...@@ -57,7 +56,7 @@
if (text === FIRST) this.pagenum = 1; if (text === FIRST) this.pagenum = 1;
window.history.pushState({}, null, `?p=${this.pagenum}`); window.history.pushState({}, null, `?p=${this.pagenum}`);
if (REALTIME) clearInterval(this.intervalId); clearInterval(this.timeLoopInterval);
this.pageRequest = true; this.pageRequest = true;
this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope); this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope);
}, },
...@@ -113,7 +112,6 @@ ...@@ -113,7 +112,6 @@
<stages :pipeline='pipeline'></stages> <stages :pipeline='pipeline'></stages>
<time-ago <time-ago
:pipeline='pipeline' :pipeline='pipeline'
:addTimeInterval='addTimeInterval'
> >
</time-ago> </time-ago>
<pipeline-actions :pipeline='pipeline'></pipeline-actions> <pipeline-actions :pipeline='pipeline'></pipeline-actions>
......
/* global gl, Flash */ /* global gl, Flash */
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign, no-underscore-dangle */
((gl) => { ((gl) => {
gl.PipelineStore = class { gl.PipelineStore = class {
...@@ -43,25 +43,36 @@ ...@@ -43,25 +43,36 @@
resourceChecker(); resourceChecker();
goFetch(); goFetch();
const removePipelineIntervals = () => { const startTimeLoops = () => {
this.allTimeIntervals.forEach(e => clearInterval(e.id)); this.timeLoopInterval = setInterval(() => {
console.log('TIME LOOP');
this.$children
.filter(e => e.$options._componentTag === 'time-ago')
.forEach(e => e.changeTime());
}, 1000);
};
startTimeLoops();
const removeTimeIntervals = () => {
clearInterval(this.timeLoopInterval);
}; };
const startIntervalLoops = () => { const startIntervalLoops = () => {
this.allTimeIntervals.forEach(e => e.start()); startTimeLoops();
}; };
const removeAll = () => { const removeAll = () => {
removePipelineIntervals(); removeTimeIntervals();
window.removeEventListener('beforeunload', () => {}); window.removeEventListener('beforeunload', removeTimeIntervals);
window.removeEventListener('focus', () => {}); window.removeEventListener('focus', startIntervalLoops);
window.removeEventListener('blur', () => {}); window.removeEventListener('blur', removeTimeIntervals);
document.removeEventListener('page:fetch', () => {}); document.removeEventListener('page:fetch', removeTimeIntervals);
}; };
window.addEventListener('beforeunload', removePipelineIntervals); window.addEventListener('beforeunload', removeTimeIntervals);
window.addEventListener('focus', startIntervalLoops); window.addEventListener('focus', startIntervalLoops);
window.addEventListener('blur', removePipelineIntervals); window.addEventListener('blur', removeTimeIntervals);
document.addEventListener('page:fetch', removeAll); document.addEventListener('page:fetch', removeAll);
} }
}; };
......
...@@ -4,21 +4,12 @@ ...@@ -4,21 +4,12 @@
gl.VueTimeAgo = Vue.extend({ gl.VueTimeAgo = Vue.extend({
data() { data() {
return { return {
timeInterval: '',
currentTime: new Date(), currentTime: new Date(),
}; };
}, },
props: [ props: [
'pipeline', 'pipeline',
'addTimeInterval',
], ],
created() {
this.timeInterval = setInterval(() => {
this.currentTime = new Date();
}, 1000);
this.addTimeInterval(this.timeInterval, this.startInterval);
},
computed: { computed: {
localTimeFinished() { localTimeFinished() {
return gl.utils.formatDate(this.pipeline.details.finished_at); return gl.utils.formatDate(this.pipeline.details.finished_at);
...@@ -44,10 +35,8 @@ ...@@ -44,10 +35,8 @@
if (duration !== null) return duration; if (duration !== null) return duration;
return false; return false;
}, },
startInterval() { changeTime() {
this.timeInterval = setInterval(() => { this.currentTime = new Date();
this.currentTime = new Date();
}, 1000);
}, },
}, },
template: ` template: `
......
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