From 5da24d2d4fc639dee1f7249b0ee5da004680514f Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 18 Nov 2018 15:39:43 +0100 Subject: [PATCH] Added first version of calendar (closes #42) --- controllers/CalendarController.php | 81 ++++++++++++++++++++++ localization/en/component_translations.php | 3 +- localization/en/strings.php | 6 +- package.json | 3 +- public/viewjs/calendar.js | 11 +++ routes.php | 3 + views/calendar.blade.php | 32 +++++++++ views/layout/default.blade.php | 6 ++ yarn.lock | 14 +++- 9 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 controllers/CalendarController.php create mode 100644 public/viewjs/calendar.js create mode 100644 views/calendar.blade.php diff --git a/controllers/CalendarController.php b/controllers/CalendarController.php new file mode 100644 index 00000000..7bfcd9cc --- /dev/null +++ b/controllers/CalendarController.php @@ -0,0 +1,81 @@ +StockService = new StockService(); + $this->TasksService = new TasksService(); + $this->ChoresService = new ChoresService(); + $this->BatteriesService = new BatteriesService(); + } + + protected $StockService; + protected $TasksService; + protected $ChoresService; + protected $BatteriesService; + + public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + $products = $this->Database->products(); + $titlePrefix = $this->LocalizationService->Localize('Product expires') . ': '; + $stockEvents = array(); + foreach($this->StockService->GetCurrentStock() as $currentStockEntry) + { + $stockEvents[] = array( + 'title' => $titlePrefix . FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name, + 'start' => $currentStockEntry->best_before_date + ); + } + + $titlePrefix = $this->LocalizationService->Localize('Task due') . ': '; + $taskEvents = array(); + foreach($this->TasksService->GetCurrent() as $currentTaskEntry) + { + $taskEvents[] = array( + 'title' => $titlePrefix . $currentTaskEntry->name, + 'start' => $currentTaskEntry->due_date + ); + } + + $chores = $this->Database->chores(); + $titlePrefix = $this->LocalizationService->Localize('Chore due') . ': '; + $choreEvents = array(); + foreach($this->ChoresService->GetCurrent() as $currentChoreEntry) + { + $choreEvents[] = array( + 'title' => $titlePrefix . FindObjectInArrayByPropertyValue($chores, 'id', $currentChoreEntry->chore_id)->name, + 'start' => $currentChoreEntry->next_estimated_execution_time + ); + } + + $batteries = $this->Database->batteries(); + $titlePrefix = $this->LocalizationService->Localize('Battery charge cycle due') . ': '; + $batteryEvents = array(); + foreach($this->BatteriesService->GetCurrent() as $currentBatteryEntry) + { + $batteryEvents[] = array( + 'title' => $titlePrefix . FindObjectInArrayByPropertyValue($batteries, 'id', $currentBatteryEntry->battery_id)->name, + 'start' => $currentBatteryEntry->next_estimated_charge_time + ); + } + + $fullcalendarEventSources = array(); + $fullcalendarEventSources[] = $stockEvents; + $fullcalendarEventSources[] = $taskEvents; + $fullcalendarEventSources[] = $choreEvents; + $fullcalendarEventSources[] = $batteryEvents; + + return $this->AppContainer->view->render($response, 'calendar', [ + 'fullcalendarEventSources' => $fullcalendarEventSources + ]); + } +} diff --git a/localization/en/component_translations.php b/localization/en/component_translations.php index 0bc023d1..21eead19 100644 --- a/localization/en/component_translations.php +++ b/localization/en/component_translations.php @@ -5,5 +5,6 @@ return array( 'timeago_nan' => 'NaN years ago', 'moment_locale' => 'x', 'datatables_localization' => '{"sEmptyTable":"No data available in table","sInfo":"Showing _START_ to _END_ of _TOTAL_ entries","sInfoEmpty":"Showing 0 to 0 of 0 entries","sInfoFiltered":"(filtered from _MAX_ total entries)","sInfoPostFix":"","sInfoThousands":",","sLengthMenu":"Show _MENU_ entries","sLoadingRecords":"Loading...","sProcessing":"Processing...","sSearch":"Search:","sZeroRecords":"No matching records found","oPaginate":{"sFirst":"First","sLast":"Last","sNext":"Next","sPrevious":"Previous"},"oAria":{"sSortAscending":": activate to sort column ascending","sSortDescending":": activate to sort column descending"}}', - 'summernote_locale' => 'x' + 'summernote_locale' => 'x', + 'fullcalendar_locale' => 'x' ); diff --git a/localization/en/strings.php b/localization/en/strings.php index bf960a48..b611241a 100644 --- a/localization/en/strings.php +++ b/localization/en/strings.php @@ -318,5 +318,9 @@ return array( 'Not opened' => 'Not opened', 'Opened' => 'Opened', 'Mark #3 #1 of #2 as open' => 'Mark #3 #1 of #2 as open', - '#1 opened' => '#1 opened' + '#1 opened' => '#1 opened', + 'Product expires' => 'Product expires', + 'Task due' => 'Task due', + 'Chore due' => 'Chore due', + 'Battery charge cycle due' => 'Battery charge cycle due' ); diff --git a/package.json b/package.json index 8ced7e9c..62e5b8d8 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "tagmanager": "https://github.com/max-favilli/tagmanager.git#3.0.2", "tempusdominus-bootstrap-4": "^5.1.2", "timeago": "^1.6.3", - "toastr": "^2.1.4" + "toastr": "^2.1.4", + "fullcalendar": "^3.9.0" } } diff --git a/public/viewjs/calendar.js b/public/viewjs/calendar.js new file mode 100644 index 00000000..a16b27b4 --- /dev/null +++ b/public/viewjs/calendar.js @@ -0,0 +1,11 @@ +$("#calendar").fullCalendar({ + "themeSystem": "bootstrap4", + "header": { + "left": "month,basicWeek", + "center": "title", + "right": "prev,next" + }, + "weekNumbers": true, + "eventLimit": true, + "eventSources": fullcalendarEventSources +}); diff --git a/routes.php b/routes.php index 44f9c1a2..2b924cd4 100644 --- a/routes.php +++ b/routes.php @@ -68,6 +68,9 @@ $app->group('', function() $this->get('/equipment', '\Grocy\Controllers\EquipmentController:Overview'); $this->get('/equipment/{equipmentId}', '\Grocy\Controllers\EquipmentController:EditForm'); + // Other routes + $this->get('/calendar', '\Grocy\Controllers\CalendarController:Overview'); + // OpenAPI routes $this->get('/api', '\Grocy\Controllers\OpenApiController:DocumentationUi'); $this->get('/manageapikeys', '\Grocy\Controllers\OpenApiController:ApiKeysList'); diff --git a/views/calendar.blade.php b/views/calendar.blade.php new file mode 100644 index 00000000..9a09b6ca --- /dev/null +++ b/views/calendar.blade.php @@ -0,0 +1,32 @@ +@extends('layout.default') + +@section('title', $L('Calendar')) +@section('activeNav', 'calendar') +@section('viewJsName', 'calendar') + +@push('pageScripts') + + @if(!empty($L('fullcalendar_locale')))@endif +@endpush + +@push('pageStyles') + +@endpush + +@section('content') +
+
+

@yield('title')

+
+
+ + + +
+
+
+
+
+@stop diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index e6d8ff5d..ca6dd9b7 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -131,6 +131,12 @@ {{ $L('Battery tracking') }} +