Skip to content

Commit 54e1480

Browse files
committed
Using moment
1 parent 1991682 commit 54e1480

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/Pulse.Host/app/js/directives.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,25 @@
55

66
angular.module('sc.directives', []).
77
directive('moment', ['$timeout', function($timeout) {
8-
return {
9-
restrict: 'C',
10-
link: function(scope, element, attr) {
11-
//$timeout.setTimeout();
8+
9+
return function (scope, element, attrs) {
10+
var timeoutId;
11+
12+
function updateText() {
13+
element.text(moment(attrs.moment).fromNow());
1214
}
15+
16+
function updateLoop() {
17+
timeoutId = $timeout(function () {
18+
updateText();
19+
updateLoop();
20+
}, 5000);
21+
}
22+
23+
element.on('$destroy', function () {
24+
$timeout.cancel(timeoutId);
25+
});
26+
27+
updateLoop();
1328
};
1429
}]);

src/Pulse.Host/app/partials/heartbeats.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ <h2>Heartbeats List</h2>
33
<div class="col-6 col-sm-6 col-lg-4" ng-repeat="heartbeat in model">
44
<div style="margin: 5px;" ng-class="{'alert-success': heartbeat.failing == false, 'alert-danger': heartbeat.failing == true}">
55
<h2>{{heartbeat.endpoint}}</h2>
6-
<p>Last Updated At: {{heartbeat.last_heartbeat_sent_at | moment}}</p>
6+
<p>Last Updated: <span moment="{{heartbeat.last_heartbeat_sent_at}}"></span></p>
77
</div>
88
</div>
99
</div>

0 commit comments

Comments
 (0)