diff --git a/controllers/HabitsController.php b/controllers/HabitsController.php index 304d1764..745b0e97 100644 --- a/controllers/HabitsController.php +++ b/controllers/HabitsController.php @@ -50,6 +50,15 @@ class HabitsController extends BaseController ]); } + public function Analysis(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->AppContainer->view->render($response, 'habitsanalysis', [ + 'habitsLog' => $this->Database->habits_log()->orderBy('tracked_time', 'DESC'), + 'habits' => $this->Database->habits()->orderBy('name'), + 'users' => $this->Database->users()->orderBy('username') + ]); + } + public function HabitEditForm(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { if ($args['habitId'] == 'new') diff --git a/localization/de.php b/localization/de.php index a129cd05..1f78b123 100644 --- a/localization/de.php +++ b/localization/de.php @@ -184,6 +184,8 @@ return array( 'Done by' => 'Ausgeführt von', 'Last done by' => 'Zuletzt ausgeführt von', 'Unknown' => 'Unbekannt', + 'Filter by habit' => 'Nach Gewohnheit filtern', + 'Habits analysis' => 'Gewohnheiten Analyse', //Constants 'manually' => 'Manuell', diff --git a/public/viewjs/habitsanalysis.js b/public/viewjs/habitsanalysis.js new file mode 100644 index 00000000..4361f10e --- /dev/null +++ b/public/viewjs/habitsanalysis.js @@ -0,0 +1,37 @@ +var habitsAnalysisTable = $('#habits-analysis-table').DataTable({ + 'paginate': false, + 'order': [[1, 'desc']], + 'language': JSON.parse(L('datatables_localization')), + 'scrollY': false, + 'colReorder': true, + 'stateSave': true +}); + +$("#habit-filter").on("change", function() +{ + var value = $(this).val(); + var text = $("#habit-filter option:selected").text(); + if (value === "all") + { + text = ""; + } + + habitsAnalysisTable.column(0).search(text).draw(); +}); + +$("#search").on("keyup", function() +{ + var value = $(this).val(); + if (value === "all") + { + value = ""; + } + + habitsAnalysisTable.search(value).draw(); +}); + +if (typeof GetUriParam("habit") !== "undefined") +{ + $("#habit-filter").val(GetUriParam("habit")); + $("#habit-filter").trigger("change"); +} diff --git a/routes.php b/routes.php index 5476cf67..c01f2d3a 100644 --- a/routes.php +++ b/routes.php @@ -41,6 +41,7 @@ $app->group('', function() // Habit routes $this->get('/habitsoverview', '\Grocy\Controllers\HabitsController:Overview'); $this->get('/habittracking', '\Grocy\Controllers\HabitsController:TrackHabitExecution'); + $this->get('/habitsanalysis', '\Grocy\Controllers\HabitsController:Analysis'); $this->get('/habits', '\Grocy\Controllers\HabitsController:HabitsList'); $this->get('/habit/{habitId}', '\Grocy\Controllers\HabitsController:HabitEditForm'); diff --git a/views/habitsanalysis.blade.php b/views/habitsanalysis.blade.php new file mode 100644 index 00000000..2798e07a --- /dev/null +++ b/views/habitsanalysis.blade.php @@ -0,0 +1,63 @@ +@extends('layout.default') + +@section('title', $L('Habits analysis')) +@section('activeNav', 'habitsanalysis') +@section('viewJsName', 'habitsanalysis') + +@section('content') +
+
+

@yield('title')

+
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + + + + + + + + + @foreach($habitsLog as $habitLogEntry) + + + + + + @endforeach + +
{{ $L('Habit') }}{{ $L('Tracked time') }}{{ $L('Done by') }}
+ {{ FindObjectInArrayByPropertyValue($habits, 'id', $habitLogEntry->habit_id)->name }} + + {{ $habitLogEntry->tracked_time }} + + + @if ($habitLogEntry->done_by_user_id !== null && !empty($habitLogEntry->done_by_user_id)) + {{ GetUserDisplayName(FindObjectInArrayByPropertyValue($users, 'id', $habitLogEntry->done_by_user_id)) }} + @else + {{ $L('Unknown') }} + @endif +
+
+
+@stop diff --git a/views/habitsoverview.blade.php b/views/habitsoverview.blade.php index b203a1a1..931a8343 100644 --- a/views/habitsoverview.blade.php +++ b/views/habitsoverview.blade.php @@ -44,6 +44,9 @@ data-habit-name="{{ FindObjectInArrayByPropertyValue($habits, 'id', $curentHabitEntry->habit_id)->name }}"> + + + {{ FindObjectInArrayByPropertyValue($habits, 'id', $curentHabitEntry->habit_id)->name }}