From 4a49f297d6d9c8c13e585a3ec6f3145b9f439916 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 9 Jun 2023 20:18:35 +0200 Subject: [PATCH] wip #5877 @0.5 --- app/Fluidbook/Stats.php | 17 +++++++++-------- .../FluidbookPublication/StatsOperation.php | 3 +++ .../views/fluidbook_stats/loader.blade.php | 2 +- .../views/fluidbook_stats/summary.blade.php | 3 +++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/Fluidbook/Stats.php b/app/Fluidbook/Stats.php index 29344b40e..e90380b19 100644 --- a/app/Fluidbook/Stats.php +++ b/app/Fluidbook/Stats.php @@ -159,11 +159,12 @@ class Stats extends Reporting $this->viewData->chart_heading = __('Détails :period', ['period' => $this->viewData->period_map[$this->viewData->period]['periodic']]); $this->viewData->report_timespan = ''; + // Which mode are we in? - if (isset($dates['start_date']) && isset($dates['end_date'])) { // Custom date range + if (isset($this->viewData->dates['start_date']) && isset($this->viewData->dates['end_date'])) { // Custom date range $this->viewData->mode = 'range'; - $this->viewData->start_date = $dates['start_date']; - $this->viewData->end_date = $dates['end_date']; + $this->viewData->start_date = $this->viewData->dates['start_date']; + $this->viewData->end_date = $this->viewData->dates['end_date']; $date_range = "{$this->viewData->start_date},{$this->viewData->end_date}"; // Human-friendly representation of the time span @@ -176,19 +177,19 @@ class Stats extends Reporting 'parts' => 3, // How many levels of detail to go into (ie. years, months, days, hours, etc) 'join' => true, // Join string with natural language separators for the locale ]); - } elseif (!empty($dates['start_year']) && !empty($dates['start_month'])) { // Month view + } elseif (!empty($this->viewData->dates['start_year']) && !empty($this->viewData->dates['start_month'])) { // Month view $this->viewData->mode = 'month'; - $month = $dates['start_month']; - $year = $dates['start_year']; + $month = $this->viewData->dates['start_month']; + $year = $this->viewData->dates['start_year']; $last_day_of_month = cal_days_in_month(CAL_GREGORIAN, $month, $year); $this->viewData->start_date = "{$year}-{$month}-01"; $date_range = "{$this->viewData->start_date},{$year}-{$month}-{$last_day_of_month}"; $this->viewData->end_date = ($month == date('m') && $year == date('Y')) ? date('Y-m-d') : "{$year}-{$month}-{$last_day_of_month}"; $this->viewData->chart_heading .= '' . Carbon::parse($this->viewData->start_date)->isoFormat('MMMM YYYY') . ''; - } elseif (!empty($dates['start_year'])) { // Year view + } elseif (!empty($this->viewData->dates['start_year'])) { // Year view $this->viewData->mode = 'year'; - $year = $dates['start_year']; + $year = $this->viewData->dates['start_year']; $this->viewData->start_date = "{$year}-01-01"; $date_range = "{$this->viewData->start_date},{$year}-12-31"; // Full range of specified year (guarantees a full chart, even if it's early in the current year) $this->viewData->end_date = $year == date('Y') ? date('Y-m-d') : "{$year}-12-31"; // If it's the current year, don't count future dates diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php index 3de818811..a65b39927 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php @@ -37,6 +37,9 @@ trait StatsOperation { $fluidbook = FluidbookPublication::withoutGlobalScopes()->where('id', $fluidbook_id)->where('hash', $hash)->firstOrFail(); $stats = new Stats($fluidbook); + if (null !== $date) { + $stats->setDate($date); + } $data = $stats->processData($period_override); $data['locale'] = app()->getLocale(); $data['fluidbook'] = $fluidbook; diff --git a/resources/views/fluidbook_stats/loader.blade.php b/resources/views/fluidbook_stats/loader.blade.php index 3c52853f3..bd183460f 100644 --- a/resources/views/fluidbook_stats/loader.blade.php +++ b/resources/views/fluidbook_stats/loader.blade.php @@ -10,7 +10,7 @@ crossorigin="anonymous" referrerpolicy="no-referrer"> {{-- Date Range picker: https://www.daterangepicker.com/ --}} - + {{-- Simple Table Sorter --}} diff --git a/resources/views/fluidbook_stats/summary.blade.php b/resources/views/fluidbook_stats/summary.blade.php index 3a6737e2d..0b70ff8c8 100644 --- a/resources/views/fluidbook_stats/summary.blade.php +++ b/resources/views/fluidbook_stats/summary.blade.php @@ -267,6 +267,8 @@ }); @endif + let baseURL = '{!! route('stats', compact('fluidbook_id', 'hash') + ['date' => '--range--', 'period_override' => $period]) !!}'; + let creationDate = moment('{{ $fluidbook->created_at->isoFormat('YYYY-MM-DD') }}'); let now = moment(); @@ -319,6 +321,7 @@ "alwaysShowCalendars": true, }, function (start, end) { $('[data-daterangepicker] span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY')); + window.location = baseURL.replace('--range--', start.format('YYYY-MM-DD') + "," + end.format('YYYY-MM-DD')); }); {{--============================================================================================================--}} -- 2.39.5