From 97adc27ba1c7e13c145f60ce2dcff0ec6ac1d7ee Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 14 Jun 2015 17:03:37 +0300 Subject: [PATCH] Added resume option to tasks --- app/Http/Controllers/TaskController.php | 3 ++- app/Ninja/Repositories/TaskRepository.php | 6 ++++++ .../migrations/2015_06_14_093410_enable_resuming_tasks.php | 4 +++- resources/lang/en/texts.php | 1 + resources/views/tasks/edit.blade.php | 7 ++----- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index cddb2b866f..31685ab6de 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -163,7 +163,8 @@ class TaskController extends BaseController 'clientPublicId' => $task->client ? $task->client->public_id : 0, 'method' => 'PUT', 'url' => 'tasks/'.$publicId, - 'title' => trans('texts.edit_task') + 'title' => trans('texts.edit_task'), + 'duration' => $task->resume_time ? ($task->duration + strtotime('now') - strtotime($task->resume_time)) : (strtotime('now') - strtotime($task->start_time)) ]; $data = array_merge($data, self::getViewModel()); diff --git a/app/Ninja/Repositories/TaskRepository.php b/app/Ninja/Repositories/TaskRepository.php index 2f9fd79c56..1faa233ff3 100644 --- a/app/Ninja/Repositories/TaskRepository.php +++ b/app/Ninja/Repositories/TaskRepository.php @@ -60,13 +60,17 @@ class TaskRepository $task->description = trim($data['description']); } + $timeLog = $task->time_log ? json_decode($task->time_log) : []; + if ($data['action'] == 'start') { $task->start_time = Carbon::now()->toDateTimeString(); $task->is_running = true; + $timeLog[] = [strtotime('now'), false]; } else if ($data['action'] == 'resume') { $task->break_duration = strtotime('now') - strtotime($task->start_time) + $task->duration; $task->resume_time = Carbon::now()->toDateTimeString(); $task->is_running = true; + $timeLog[] = [strtotime('now'), false]; } else if ($data['action'] == 'stop' && $task->is_running) { if ($task->resume_time) { $task->duration = $task->duration + strtotime('now') - strtotime($task->resume_time); @@ -74,6 +78,7 @@ class TaskRepository } else { $task->duration = strtotime('now') - strtotime($task->start_time); } + $timeLog[count($timeLog)-1][1] = strtotime('now'); $task->is_running = false; } else if ($data['action'] == 'save' && !$task->is_running) { $task->start_time = $data['start_time']; @@ -83,6 +88,7 @@ class TaskRepository $task->duration = max($task->duration, 0); $task->break_duration = max($task->break_duration, 0); + $task->time_log = json_encode($timeLog); $task->save(); diff --git a/database/migrations/2015_06_14_093410_enable_resuming_tasks.php b/database/migrations/2015_06_14_093410_enable_resuming_tasks.php index 7af1b83b41..a08aa1eb38 100644 --- a/database/migrations/2015_06_14_093410_enable_resuming_tasks.php +++ b/database/migrations/2015_06_14_093410_enable_resuming_tasks.php @@ -13,10 +13,11 @@ class EnableResumingTasks extends Migration { public function up() { Schema::table('tasks', function($table) - { + { $table->boolean('is_running')->default(false); $table->integer('break_duration')->nullable(); $table->timestamp('resume_time')->nullable(); + $table->text('time_log')->nullable(); }); $tasks = DB::table('tasks') @@ -49,6 +50,7 @@ class EnableResumingTasks extends Migration { $table->dropColumn('is_running'); $table->dropColumn('resume_time'); $table->dropColumn('break_duration'); + $table->dropColumn('time_log'); }); } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index dfe0899175..25204764ae 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -690,5 +690,6 @@ return array( 'resume' => 'Resume', 'break_duration' => 'Break', 'edit_details' => 'Edit Details', + 'work' => 'Work', ); diff --git a/resources/views/tasks/edit.blade.php b/resources/views/tasks/edit.blade.php index 8c93c238a2..67bca25041 100644 --- a/resources/views/tasks/edit.blade.php +++ b/resources/views/tasks/edit.blade.php @@ -55,9 +55,6 @@ @if ($task->duration) {{ trans('texts.duration') }}:
@endif - @if ($task->break_duration) - {{ trans('texts.break_duration') }}:
- @endif

{!! Button::primary(trans('texts.edit_details'))->withAttributes(['onclick'=>'showTimeDetails()'])->small() !!}

@@ -94,7 +91,7 @@
start_time) }}; @if ($task->is_running) - tock({{ $task->duration ?: strtotime('now') - strtotime($task->start_time) }}); + tock({{ $duration }}); @else var date = new Date(NINJA.startTime * 1000); var hours = date.getHours();