Skip to content

Commit

Permalink
✨ : add component to display timer
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubuisson committed Oct 25, 2019
1 parent 9cb9514 commit 1d7acb3
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
<artifactId>momentjs</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>moment-duration-format</artifactId>
<version>1.3.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
63 changes: 63 additions & 0 deletions src/main/resources/templates/vue_templates/job/job-timer.vue
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>

0 comments on commit 1d7acb3

Please sign in to comment.