From bdfbea3883eb9628061ed97143bc7098b42d2be7 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 5 Mar 2017 22:14:36 +0200 Subject: [PATCH] Enable setting task duration --- resources/views/tasks/edit.blade.php | 45 ++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/resources/views/tasks/edit.blade.php b/resources/views/tasks/edit.blade.php index a2fb0e679b58..b78ca3c09cc3 100644 --- a/resources/views/tasks/edit.blade.php +++ b/resources/views/tasks/edit.blade.php @@ -124,8 +124,8 @@ class="form-control time-input time-input-end" placeholder="{{ trans('texts.end_time') }}"/> - -
+ + {{ trans('texts.set_now') }} @@ -350,23 +350,27 @@ self.endTime(moment.tz(timezone).unix()); } - self.duration.pretty = ko.computed(function() { - var duration = false; - var start = self.startTime(); - var end = self.endTime(); + self.duration.pretty = ko.computed({ + read: function() { + var duration = false; + var start = self.startTime(); + var end = self.endTime(); - if (start && end) { - var duration = end - start; + if (start && end) { + var duration = end - start; + } + + var duration = moment.duration(duration * 1000); + return Math.floor(duration.asHours()) + moment.utc(duration.asMilliseconds()).format(":mm:ss") + }, + write: function(data) { + self.endTime(self.startTime() + convertToSeconds(data)); } - - var duration = moment.duration(duration * 1000); - return Math.floor(duration.asHours()) + moment.utc(duration.asMilliseconds()).format(":mm:ss") - }, self); + }); /* - self.isEmpty = function() { - return false; - }; + self.duration.pretty = ko.computed(function() { + }, self); */ self.hideActions = function() { @@ -378,6 +382,17 @@ }; } + function convertToSeconds(str) { + if (!str) { + return 0; + } + if (str.indexOf(':') >= 0) { + return moment.duration(str).asSeconds(); + } else { + return parseFloat(str) * 60 * 60; + } + } + function loadTimeLog(data) { model.time_log.removeAll(); data = JSON.parse(data);