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

80 lines
2 KiB
JavaScript
Raw Normal View History

2016-11-09 17:45:44 -05:00
/* global Vue, gl */
/* eslint-disable no-param-reassign */
2017-02-05 13:17:38 -05:00
window.Vue = require('vue');
require('../lib/utils/datetime_utility');
2017-02-24 14:02:57 -05:00
const iconTimerSvg = require('../../../views/shared/icons/_icon_timer.svg');
2016-11-09 17:45:44 -05:00
((gl) => {
gl.VueTimeAgo = Vue.extend({
data() {
return {
currentTime: new Date(),
2017-02-24 14:02:57 -05:00
iconTimerSvg,
};
},
2017-02-24 14:02:57 -05:00
props: ['pipeline'],
computed: {
2016-12-15 11:40:40 -05:00
timeAgo() {
return gl.utils.getTimeago();
},
localTimeFinished() {
return gl.utils.formatDate(this.pipeline.details.finished_at);
},
2016-11-09 17:45:44 -05:00
timeStopped() {
const changeTime = this.currentTime;
2016-11-09 17:45:44 -05:00
const options = {
weekday: 'long',
year: 'numeric',
month: 'short',
day: 'numeric',
};
options.timeZoneName = 'short';
const finished = this.pipeline.details.finished_at;
if (!finished && changeTime) return false;
2016-12-15 11:40:40 -05:00
return ({ words: this.timeAgo.format(finished) });
2016-11-09 17:45:44 -05:00
},
duration() {
const { duration } = this.pipeline.details;
const date = new Date(duration * 1000);
let hh = date.getUTCHours();
let mm = date.getUTCMinutes();
let ss = date.getSeconds();
if (hh < 10) hh = `0${hh}`;
if (mm < 10) mm = `0${mm}`;
if (ss < 10) ss = `0${ss}`;
if (duration !== null) return `${hh}:${mm}:${ss}`;
return false;
2016-11-09 17:45:44 -05:00
},
},
methods: {
changeTime() {
this.currentTime = new Date();
},
2016-11-09 17:45:44 -05:00
},
template: `
<td>
<p class="duration" v-if='duration'>
2017-02-24 14:02:57 -05:00
<span v-html="iconTimerSvg"></span>
{{duration}}
2016-11-09 17:45:44 -05:00
</p>
<p class="finished-at" v-if='timeStopped'>
2016-11-09 17:45:44 -05:00
<i class="fa fa-calendar"></i>
<time
data-toggle="tooltip"
data-placement="top"
data-container="body"
:data-original-title='localTimeFinished'
2016-11-09 17:45:44 -05:00
>
{{timeStopped.words}}
2016-11-09 17:45:44 -05:00
</time>
</p>
</td>
`,
});
})(window.gl || (window.gl = {}));