From b448f459f88e30b2c66e5f6cbc2aba7a7581d9cf Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 19 Oct 2016 10:17:23 +0300 Subject: [PATCH] Fix task timer #1109 --- app/Http/Controllers/TaskController.php | 1 - app/Models/Task.php | 12 ++++++++++++ resources/views/tasks/edit.blade.php | 8 +++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index 7b63ac2779..2450ff51e6 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -182,7 +182,6 @@ class TaskController extends BaseController 'method' => 'PUT', 'url' => 'tasks/'.$task->public_id, 'title' => trans('texts.edit_task'), - 'duration' => $task->is_running ? $task->getCurrentDuration() : $task->getDuration(), 'actions' => $actions, 'timezone' => Auth::user()->account->timezone ? Auth::user()->account->timezone->name : DEFAULT_TIMEZONE, 'datetimeFormat' => Auth::user()->account->getMomentDateTimeFormat(), diff --git a/app/Models/Task.php b/app/Models/Task.php index a56453c437..e65c5e8c85 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -82,6 +82,18 @@ class Task extends EntityModel return self::calcStartTime($this); } + public function getLastStartTime() + { + $parts = json_decode($this->time_log) ?: []; + + if (count($parts)) { + $index = count($parts) - 1; + return $parts[$index][0]; + } else { + return ''; + } + } + /** * @param $task * @return int diff --git a/resources/views/tasks/edit.blade.php b/resources/views/tasks/edit.blade.php index 180563914b..abd9d8b10f 100644 --- a/resources/views/tasks/edit.blade.php +++ b/resources/views/tasks/edit.blade.php @@ -222,12 +222,14 @@ @endif } - function tock(duration) { + function tock(startTime) { + var duration = new Date().getTime() - startTime; + duration = Math.floor(duration / 100) / 10; var str = convertDurationToString(duration); $('#duration-text').html(str); setTimeout(function() { - tock(duration+1); + tock(startTime); }, 1000); } @@ -483,7 +485,7 @@ @if ($task) @if ($task->is_running) - tock({{ $duration }}); + tock({{ $task->getLastStartTime() * 1000 }}); @endif @endif