Commit d11a298c authored by Regis's avatar Regis

on focus - blur - and page closed -- intervals are taken care of for time ago and realtime

parent 649d1eb2
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
data() { data() {
return { return {
pipelines: [], pipelines: [],
allTimeIntervals: [],
intervalId: '', intervalId: '',
updatedAt: '', updatedAt: '',
pagenum: 1, pagenum: 1,
...@@ -65,6 +66,9 @@ ...@@ -65,6 +66,9 @@
if (author) return author; if (author) return author;
return ({}); return ({});
}, },
addTimeInterval(id, that) {
this.allTimeIntervals.push({ id: id, component: that });
},
}, },
template: ` template: `
<div> <div>
...@@ -90,7 +94,11 @@ ...@@ -90,7 +94,11 @@
</commit> </commit>
</td> </td>
<stages :pipeline='pipeline'></stages> <stages :pipeline='pipeline'></stages>
<time-ago :pipeline='pipeline'></time-ago> <time-ago
:pipeline='pipeline'
:addTimeInterval='addTimeInterval'
>
</time-ago>
<pipeline-actions :pipeline='pipeline'></pipeline-actions> <pipeline-actions :pipeline='pipeline'></pipeline-actions>
</tr> </tr>
</tbody> </tbody>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
((gl) => { ((gl) => {
const REALTIME = false; const REALTIME = true;
const PAGINATION_LIMIT = 31; const PAGINATION_LIMIT = 31;
const SLICE_LIMIT = 29; const SLICE_LIMIT = 29;
...@@ -33,11 +33,10 @@ ...@@ -33,11 +33,10 @@
const addToVueResources = () => { Vue.activeResources += 1; }; const addToVueResources = () => { Vue.activeResources += 1; };
const subtractFromVueResources = () => { Vue.activeResources -= 1; }; const subtractFromVueResources = () => { Vue.activeResources -= 1; };
resetVueResources(); // set Vue.resources to 0 resetVueResources();
const updatePipelineNums = (count) => { const updatePipelineNums = (count) => {
const { all } = count; const { all } = count;
// cannot define non camel case, so not using destructuring for running
const running = count.running_or_pending; const running = count.running_or_pending;
document.querySelector('.js-totalbuilds-count').innerHTML = all; document.querySelector('.js-totalbuilds-count').innerHTML = all;
document.querySelector('.js-running-count').innerHTML = running; document.querySelector('.js-running-count').innerHTML = running;
...@@ -82,7 +81,7 @@ ...@@ -82,7 +81,7 @@
resourceChecker(); resourceChecker();
goFetch(); goFetch();
if (REALTIME) { const poller = () => {
this.intervalId = setInterval(() => { this.intervalId = setInterval(() => {
if (this.updatedAt) { if (this.updatedAt) {
resourceChecker(); resourceChecker();
...@@ -90,11 +89,31 @@ ...@@ -90,11 +89,31 @@
goUpdate(); goUpdate();
} }
}, 3000); }, 3000);
};
if (REALTIME) poller();
const removePipelineInterval = () => {
this.allTimeIntervals.forEach(e => clearInterval(e.id));
if (REALTIME) clearInterval(this.intervalId);
};
const startIntervalLoops = () => {
this.allTimeIntervals.forEach(e => e.component.startInterval());
if (REALTIME) poller();
};
window.onbeforeunload = function removePipelineInterval() { window.onbeforeunload = function onClose() {
clearInterval(this.intervalId); removePipelineInterval();
}; };
}
window.onblur = function remove() {
removePipelineInterval();
};
window.onfocus = function start() {
startIntervalLoops();
};
} }
}; };
})(window.gl || (window.gl = {})); })(window.gl || (window.gl = {}));
/* global Vue, gl */ /* global Vue, gl */
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
((gl) => { ((gl) => {
const REALTIME = false;
gl.VueTimeAgo = Vue.extend({ gl.VueTimeAgo = Vue.extend({
data() {
return {
timeInterval: '',
currentTime: new Date(),
};
},
props: [ props: [
'pipeline', 'pipeline',
'addTimeInterval',
], ],
created() {
if (!REALTIME) {
this.timeInterval = setInterval(() => {
this.currentTime = new Date();
}, 1000);
this.addTimeInterval(this.timeInterval, this);
}
},
computed: { computed: {
localTimeFinished() { localTimeFinished() {
return gl.utils.formatDate(this.pipeline.details.finished_at); return gl.utils.formatDate(this.pipeline.details.finished_at);
}, },
},
methods: {
timeStopped() { timeStopped() {
const changeTime = this.currentTime;
const options = { const options = {
weekday: 'long', weekday: 'long',
year: 'numeric', year: 'numeric',
...@@ -23,18 +41,22 @@ ...@@ -23,18 +41,22 @@
const finished = this.pipeline.details.finished_at; const finished = this.pipeline.details.finished_at;
if (!finished) return false; if (!finished && changeTime) return false;
return ({ words: gl.utils.getTimeago().format(finished) });
return {
words: gl.utils.getTimeago().format(finished),
};
}, },
},
methods: {
duration() { duration() {
const { duration } = this.pipeline.details; const { duration } = this.pipeline.details;
if (duration === 0) return '00:00:00'; if (duration === 0) return '00:00:00';
if (duration !== null) return duration; if (duration !== null) return duration;
return false; return false;
}, },
startInterval() {
this.timeInterval = setInterval(() => {
this.currentTime = new Date();
}, 1000);
},
}, },
template: ` template: `
<td> <td>
...@@ -51,7 +73,7 @@ ...@@ -51,7 +73,7 @@
</svg> </svg>
{{duration()}} {{duration()}}
</p> </p>
<p class="finished-at" v-if='timeStopped()'> <p class="finished-at" v-if='timeStopped'>
<i class="fa fa-calendar"></i> <i class="fa fa-calendar"></i>
<time <time
data-toggle="tooltip" data-toggle="tooltip"
...@@ -59,7 +81,7 @@ ...@@ -59,7 +81,7 @@
data-container="body" data-container="body"
:data-original-title='localTimeFinished' :data-original-title='localTimeFinished'
> >
{{timeStopped().words}} {{timeStopped.words}}
</time> </time>
</p> </p>
</td> </td>
......
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