-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cb9514
commit 1d7acb3
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/resources/templates/vue_templates/job/job-timer.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template id="job-timer-template"> | ||
<span :class="cssClass"> | ||
{{timer | format}} | ||
</span> | ||
</template> | ||
|
||
<script> | ||
Vue.component('job-timer', { | ||
template: '#job-timer-template', | ||
data: () => ({ | ||
timer: 0, | ||
intervalId: null | ||
}), | ||
props: { | ||
startTime: { | ||
type: Date | moment | String, | ||
default: () => moment() | ||
}, | ||
endTime: { | ||
type: Date | moment | String, | ||
default: () => null | ||
}, | ||
cssClass: { | ||
type: String, | ||
default: '' | ||
} | ||
}, | ||
created: function () { | ||
if (!!this.endTime) { | ||
this.interval(moment(this.endTime)); | ||
return; | ||
} | ||
this.start(); | ||
}, | ||
watch: { | ||
endTime: function (newValue) { | ||
if (newValue == null) { | ||
this.start(); | ||
return; | ||
} | ||
this.interval(moment(newValue)); | ||
this.end(); | ||
}, | ||
}, | ||
methods: { | ||
start: function () { | ||
this.intervalId = setInterval(() => this.interval(moment()), 1000); | ||
}, | ||
end: function () { | ||
clearInterval(this.intervalId); | ||
}, | ||
interval: function (endTime) { | ||
this.timer = moment.duration(endTime.diff(this.startTime)); | ||
} | ||
}, | ||
filters: { | ||
format: function (value) { | ||
if (!moment.isDuration(value)) return ''; | ||
return value.format("h [hr] m [min] s [sec]"); | ||
} | ||
} | ||
}); | ||
</script> |