From 94d8fbfdb94b36f971e64661150f72db49e52dc1 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 24 Sep 2017 23:35:33 +0300 Subject: [PATCH] Working on time tracker --- resources/views/tasks/time_tracker.blade.php | 2 +- .../tasks/time_tracker_knockout.blade.php | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/resources/views/tasks/time_tracker.blade.php b/resources/views/tasks/time_tracker.blade.php index e88c54e2e428..57010aa2d495 100644 --- a/resources/views/tasks/time_tracker.blade.php +++ b/resources/views/tasks/time_tracker.blade.php @@ -202,7 +202,7 @@
-
+

diff --git a/resources/views/tasks/time_tracker_knockout.blade.php b/resources/views/tasks/time_tracker_knockout.blade.php index 03e55e434b98..d99f4581e9a0 100644 --- a/resources/views/tasks/time_tracker_knockout.blade.php +++ b/resources/views/tasks/time_tracker_knockout.blade.php @@ -366,7 +366,7 @@ } setTimeout(function() { self.isStartEnabled(true); - }, 2000); + }, 2000); }, }); } @@ -545,15 +545,14 @@ return time.age(); }); - self.duration = ko.computed(function() { - model.clock(); // bind to the clock + self.calcDuration = function(total) { if (! self.time_log().length) { return '0:00:00'; } var time = self.lastTime(); var now = new Date().getTime(); var duration = 0; - if (time.isRunning()) { + if (time.isRunning() && ! total) { var duration = now - (time.startTime() * 1000); duration = Math.floor(duration / 100) / 10; } else { @@ -564,6 +563,16 @@ var duration = moment.duration(duration * 1000); return Math.floor(duration.asHours()) + moment.utc(duration.asMilliseconds()).format(":mm:ss"); + } + + self.totalDuration = ko.computed(function() { + model.clock(); // bind to the clock + return self.calcDuration(true); + }); + + self.duration = ko.computed(function() { + model.clock(); // bind to the clock + return self.calcDuration(false); }); } @@ -662,7 +671,8 @@ }); self.duration = ko.computed(function() { - return self.endTime() - self.startTime(); + model.clock(); // bind to the clock + return (self.endTime() || moment().unix()) - self.startTime(); });