From 50fdf3112120b790a88fa4e9257a651f87f9fb73 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 26 Sep 2017 10:12:03 +0300 Subject: [PATCH] Working on time tracker --- app/Http/Controllers/HomeController.php | 8 ++++++++ app/Http/routes.php | 1 + resources/lang/en/texts.php | 2 +- resources/views/tasks/time_tracker.blade.php | 19 +++++++++++++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 716d96860b7e..9ad5e3efa679 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -126,6 +126,14 @@ class HomeController extends BaseController return RESULT_SUCCESS; } + /** + * @return mixed + */ + public function loggedIn() + { + return RESULT_SUCCESS; + } + /** * @return mixed */ diff --git a/app/Http/routes.php b/app/Http/routes.php index 2f59b05692a5..615fcac7a900 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -121,6 +121,7 @@ if (Utils::isTravis()) { } Route::group(['middleware' => ['lookup:user', 'auth:user']], function () { + Route::get('logged_in', 'HomeController@loggedIn'); Route::get('dashboard', 'DashboardController@index'); Route::get('dashboard_chart_data/{group_by}/{start_date}/{end_date}/{currency_id}/{include_expenses}', 'DashboardController@chartData'); Route::get('set_entity_filter/{entity_type}/{filter?}', 'AccountController@setEntityFilter'); diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 07e4f949917d..4a10c0f807ef 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2460,7 +2460,7 @@ $LANG = array( 'started_task' => 'Successfully started task', 'create_client' => 'Create Client', - 'download_app' => 'Download the desktop app', + 'download_desktop_app' => 'Download the desktop app', ); diff --git a/resources/views/tasks/time_tracker.blade.php b/resources/views/tasks/time_tracker.blade.php index e51479052a4a..59b87170c6ac 100644 --- a/resources/views/tasks/time_tracker.blade.php +++ b/resources/views/tasks/time_tracker.blade.php @@ -318,6 +318,20 @@ projectsForClientMap[client.public_id].push(project); } + function sendKeepAlive() { + setTimeout(function() { + $.get('{{ URL::to('/keep_alive') }}', function (response) { + if (response == '{{ RESULT_SUCCESS }}') { + sendKeepAlive() + } else { + location.reload(); + } + }).fail(function() { + location.reload(); + }); + }, 1000 * 60 * 15); + } + $(function() { // setup clients and project comboboxes @@ -436,14 +450,15 @@ window.open('{{ config('ninja.time_tracker') }}', '_blank'); } }; - toastr.info("{{ trans('texts.download_app') }}", false, options); + toastr.info("{{ trans('texts.download_desktop_app') }}", false, options); } + sendKeepAlive(); + $(window).on('beforeunload', function () { if (navigator.userAgent == 'Time Tracker') { return undefined; } - if (model.selectedTask() && model.formChanged()) { return "{{ trans('texts.save_or_discard') }}"; } else {