]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5877 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 9 Jun 2023 18:18:35 +0000 (20:18 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 9 Jun 2023 18:18:35 +0000 (20:18 +0200)
app/Fluidbook/Stats.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php
resources/views/fluidbook_stats/loader.blade.php
resources/views/fluidbook_stats/summary.blade.php

index 29344b40e387d49da9d68cb4b15123ce5c2d38cb..e90380b19b1ce25d00c37ade11870a3524d61429 100644 (file)
@@ -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 .= '<span class="heading-subtitle">' . Carbon::parse($this->viewData->start_date)->isoFormat('MMMM YYYY') . '</span>';
 
-        } 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
index 3de818811503d72f0f662d3fe454320810600f1f..a65b399273992aabf113d891f560f01ca89a943a 100644 (file)
@@ -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;
index 3c52853f3ec919f202ae46e987976832fe249ab5..bd183460fc8916c2bf489c626d712bf6da0c0270 100644 (file)
@@ -10,7 +10,7 @@
             crossorigin="anonymous" referrerpolicy="no-referrer"></script>
 
     {{-- Date Range picker: https://www.daterangepicker.com/ --}}
-    <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
+    <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment-with-locales.min.js"></script>
     <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
 
     {{-- Simple Table Sorter --}}
index 3a6737e2df8481d3433232c9bac80bcbcde4d723..0b70ff8c8bfffff7d12f70087ae44005a628e04d 100644 (file)
             });
             @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();
 
                 "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'));
             });
 
             {{--============================================================================================================--}}