mirror of
https://github.com/getredash/redash.git
synced 2026-03-22 10:00:17 -04:00
31 lines
794 B
JavaScript
31 lines
794 B
JavaScript
import moment from 'moment';
|
|
|
|
function rdTimer() {
|
|
return {
|
|
restrict: 'E',
|
|
scope: { timestamp: '=' },
|
|
template: '{{currentTime}}',
|
|
controller($scope) {
|
|
$scope.currentTime = '00:00:00';
|
|
|
|
// We're using setInterval directly instead of $timeout, to avoid using $apply, to
|
|
// prevent the digest loop being run every second.
|
|
let currentTimer = setInterval(() => {
|
|
$scope.currentTime = moment(moment() - moment($scope.timestamp)).utc().format('HH:mm:ss');
|
|
$scope.$digest();
|
|
}, 1000);
|
|
|
|
$scope.$on('$destroy', () => {
|
|
if (currentTimer) {
|
|
clearInterval(currentTimer);
|
|
currentTimer = null;
|
|
}
|
|
});
|
|
},
|
|
};
|
|
}
|
|
|
|
export default function (ngModule) {
|
|
ngModule.directive('rdTimer', rdTimer);
|
|
}
|