From f090dd4de6af7d3abdca97685a49f0a60d78d065 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 27 Jan 2024 20:57:54 -0500 Subject: [PATCH 01/37] Bug Squashing: Fixed manual user creation with default Has Ever Logged In value --- app/Nova/User.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Nova/User.php b/app/Nova/User.php index 9b87cb74e..a0eafeab9 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -34,6 +34,7 @@ use Laravel\Nova\Fields\Email; use Laravel\Nova\Fields\File; use Laravel\Nova\Fields\HasMany; +use Laravel\Nova\Fields\Hidden; use Laravel\Nova\Fields\MorphMany; use Laravel\Nova\Fields\MorphToMany; use Laravel\Nova\Fields\Number; @@ -97,6 +98,10 @@ class User extends Resource public function fields(NovaRequest $request): array { return [ + Hidden::make('Has Ever Logged In') + ->showOnCreating() + ->default(fn (Request $r) => 0), + Text::make('Username', 'uid') ->sortable() ->rules('required', 'max:127') From ef4d218677d20d7521f6415ead22f91d344fee4f Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 23 Mar 2024 22:39:36 -0400 Subject: [PATCH 02/37] Made RsvpSourceBreakdown match TravelAuthorityRequestReceivedForTravel, getting 404 when on main dashboard --- app/Nova/Dashboards/Main.php | 15 ++++++++++++++ app/Nova/Event.php | 3 +++ app/Nova/Metrics/RsvpSourceBreakdown.php | 25 ++++++++++++++++++++---- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index a5c9ca5ba..07a990e1e 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -7,6 +7,7 @@ namespace App\Nova\Dashboards; +use App\Models\Event; use App\Models\Travel; use App\Models\TravelAssignment; use App\Nova\Metrics\ActiveAttendanceBreakdown; @@ -15,6 +16,7 @@ use App\Nova\Metrics\MembersByFiscalYear; use App\Nova\Metrics\PaymentReceivedForTravel; use App\Nova\Metrics\PaymentsPerDay; +use App\Nova\Metrics\RsvpSourceBreakdown; use App\Nova\Metrics\TransactionsByDuesPackage; use App\Nova\Metrics\TravelAuthorityRequestReceivedForTravel; use Carbon\Carbon; @@ -92,6 +94,19 @@ public function cards(): array ); } + foreach (Event::all() as $event) { + $should_include = false; + + if ($event->rsvps()->count() > 0) { + $should_include = true; + } + if (!$should_include) { + continue; + } + $cards[] = (new RsvpSourceBreakdown($event->id)) + ->canSee(static fn (Request $request): bool => $request->user()->can('read-rsvps')); + } + return $cards; } diff --git a/app/Nova/Event.php b/app/Nova/Event.php index 78e72bfed..22c749fbc 100644 --- a/app/Nova/Event.php +++ b/app/Nova/Event.php @@ -73,7 +73,10 @@ class Event extends Resource */ public function fields(Request $request): array { + return [ + Text::make('Event ID', 'id') + ->onlyOnDetail(), Text::make('Event Name', 'name') ->sortable() ->rules('required', 'max:255') diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index d43bf3c62..e53e1f2c4 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -9,6 +9,7 @@ use Illuminate\Http\Request; use Laravel\Nova\Metrics\Partition; use Laravel\Nova\Metrics\PartitionResult; +use Laravel\Nova\Http\Requests\NovaRequest; class RsvpSourceBreakdown extends Partition { @@ -17,15 +18,31 @@ class RsvpSourceBreakdown extends Partition * * @var string */ - public $name = 'RSVP Sources'; + public function name(): string + { + return $this->resourceId === -1 ? 'RSVP Sources' : 'RSVP Sources For '.Rsvp::where( + 'id', + $this->resourceId + )->sole()->name; + } /** * Calculate the value of the metric. */ - public function calculate(Request $request): PartitionResult + + protected int $resourceId; + + public function __construct(int $resourceId = -1) + { + parent::__construct(); + $this->resourceId = $resourceId; + } + + public function calculate(NovaRequest $request): PartitionResult { + $resourceId = $request->resourceId ?? $this->resourceId; return $this->result( - Rsvp::where('event_id', $request->resourceId) + Rsvp::where('event_id', $resourceId) ->leftJoin('recruiting_visits', 'source', '=', 'visit_token') ->when( config('database.default') === 'mysql', @@ -53,6 +70,6 @@ static function (Builder $query): void { */ public function uriKey(): string { - return 'rsvp-source-breakdown'; + return $this->resourceId === -1 ? 'rsvp-source-breakdown' : 'rsvp-source-breakdown-'.$this->resourceId; } } From 3fa5363ba3c6c072f64d0ff072e90ee19f24b978 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sun, 31 Mar 2024 23:23:57 -0400 Subject: [PATCH 03/37] Added cards for RSVPs and Attendance of events to main dashboard --- app/Nova/Dashboards/Main.php | 34 ++++++++++++++ .../Metrics/ActiveAttendanceBreakdown.php | 44 ++++++++++++++++--- app/Nova/Metrics/RsvpSourceBreakdown.php | 3 +- 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index 07a990e1e..418c658a5 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -96,15 +96,29 @@ public function cards(): array foreach (Event::all() as $event) { $should_include = false; + $attributes = $event->getAttributes(); if ($event->rsvps()->count() > 0) { $should_include = true; } + if ($event->attendance()->count() > 0) { + $should_include = true; + } + if ($attributes['end_time'] === null) { + if ($attributes['start_time'] === null || $attributes['start_time'] < Carbon::now()) { + $should_include = false; + } + } else if ($attributes['end_time'] < Carbon::now()) { + $should_include = false; + } if (!$should_include) { continue; } + $cards[] = (new RsvpSourceBreakdown($event->id)) ->canSee(static fn (Request $request): bool => $request->user()->can('read-rsvps')); + $cards[] = (new ActiveAttendanceBreakdown(true, $event->id, "event")) + ->canSee(static fn (Request $request): bool => $request->user()->can('read-attendance')); } return $cards; @@ -127,6 +141,26 @@ public function cards(): array } } + if (request()->is('nova-api/metrics/rsvp-source-breakdown-*')) { + $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); + $id = intval($parts->last()); + return [ + (new RsvpSourceBreakdown($id))->canSee( + static fn (Request $request): bool => $request->user()->can('read-rsvps') + ), + ]; + } + + if (request()->is('nova-api/metrics/active-attendance-breakdown-event-*')) { + $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); + $id = intval($parts->last()); + return [ + (new ActiveAttendanceBreakdown(true, 1, "event"))->canSee( + static fn (Request $request): bool => $request->user()->can('read-attendance') + ) + ]; + } + return $cards; } } diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 9952f06e4..264164171 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -5,8 +5,10 @@ namespace App\Nova\Metrics; use App\Models\Attendance; +use App\Models\Event; use App\Models\User; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; use Laravel\Nova\Metrics\Partition; use Laravel\Nova\Metrics\PartitionResult; @@ -17,7 +19,11 @@ class ActiveAttendanceBreakdown extends Partition */ public function name(): string { - return $this->showAllTime ? 'Active Attendees' : 'Attendees Last 4 Weeks'; + $ret = $this->showAllTime ? 'Active Attendees' : 'Attendees Last 4 Weeks'; + if ($this->resourceId != -1) { + $ret .= ' for '.Event::where('id', $this->resourceId)->sole()->name; + } + return $ret; } /** @@ -27,13 +33,30 @@ public function name(): string */ protected $showAllTime = false; + /** + * If displaying on the main dashboard, this indicates the event to get attendance from. + * + * @var int + */ + private int $resourceId; + + /** + * If displaying on a page different from the type of attendable you are showing. + * This indicates the morphClass of the attendable (for example, an event). + * + * @var string + */ + private string $attendableType; + /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(bool $showAllTime = false) + public function __construct(bool $showAllTime = false, int $resourceId = -1, string $attendableType = "") { parent::__construct(); + $this->resourceId = $resourceId; $this->showAllTime = $showAllTime; + $this->attendableType = $attendableType; } /** @@ -41,6 +64,12 @@ public function __construct(bool $showAllTime = false) */ public function calculate(Request $request): PartitionResult { + $resourceId; + if ($this->resourceId != -1) { + $resourceId = $this->resourceId; + } else if (isset($request->resourceId)) { + $resourceId = $request->resourceId; + } // If a user is found, this will give "Active" in the active column, otherwise the column will be null $query = Attendance::selectRaw('count(distinct gtid) as aggregate') ->selectSub( @@ -50,10 +79,12 @@ public function calculate(Request $request): PartitionResult 'active' ); - if (isset($request->resourceId)) { + if (isset($resourceId)) { $query = $query - ->where('attendable_id', $request->resourceId) - ->where('attendable_type', $request->model()->getMorphClass()); + ->where('attendable_id', $resourceId) + ->where('attendable_type', + $this->attendableType != "" ? $this->attendableType + : $request->model()->getMorphClass()); } if (! $this->showAllTime) { @@ -81,6 +112,7 @@ public function calculate(Request $request): PartitionResult */ public function uriKey(): string { - return 'active-attendance-breakdown'; + return $this->resourceId === -1 ? 'active-attendance-breakdown' + : 'active-attendance-breakdown-'.$this->attendableType.'-'.$this->resourceId; } } diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index e53e1f2c4..714abbc55 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -4,6 +4,7 @@ namespace App\Nova\Metrics; +use App\Models\Event; use App\Models\Rsvp; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; @@ -20,7 +21,7 @@ class RsvpSourceBreakdown extends Partition */ public function name(): string { - return $this->resourceId === -1 ? 'RSVP Sources' : 'RSVP Sources For '.Rsvp::where( + return $this->resourceId === -1 ? 'RSVP Sources' : 'RSVP Sources for '.Event::where( 'id', $this->resourceId )->sole()->name; From 357338054bf037657a914df2d3273bade3c6cdad Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sun, 31 Mar 2024 23:57:27 -0400 Subject: [PATCH 04/37] StyleCI appeasement --- app/Nova/Dashboards/Main.php | 10 ++++++---- app/Nova/Event.php | 1 - .../Metrics/ActiveAttendanceBreakdown.php | 18 ++++++++++-------- app/Nova/Metrics/RsvpSourceBreakdown.php | 19 ++++++++++++------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index 418c658a5..c0abc1d2e 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -108,16 +108,16 @@ public function cards(): array if ($attributes['start_time'] === null || $attributes['start_time'] < Carbon::now()) { $should_include = false; } - } else if ($attributes['end_time'] < Carbon::now()) { + } elseif ($attributes['end_time'] < Carbon::now()) { $should_include = false; } - if (!$should_include) { + if (! $should_include) { continue; } $cards[] = (new RsvpSourceBreakdown($event->id)) ->canSee(static fn (Request $request): bool => $request->user()->can('read-rsvps')); - $cards[] = (new ActiveAttendanceBreakdown(true, $event->id, "event")) + $cards[] = (new ActiveAttendanceBreakdown(true, $event->id, 'event')) ->canSee(static fn (Request $request): bool => $request->user()->can('read-attendance')); } @@ -144,6 +144,7 @@ public function cards(): array if (request()->is('nova-api/metrics/rsvp-source-breakdown-*')) { $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); $id = intval($parts->last()); + return [ (new RsvpSourceBreakdown($id))->canSee( static fn (Request $request): bool => $request->user()->can('read-rsvps') @@ -154,10 +155,11 @@ public function cards(): array if (request()->is('nova-api/metrics/active-attendance-breakdown-event-*')) { $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); $id = intval($parts->last()); + return [ (new ActiveAttendanceBreakdown(true, 1, "event"))->canSee( static fn (Request $request): bool => $request->user()->can('read-attendance') - ) + ), ]; } diff --git a/app/Nova/Event.php b/app/Nova/Event.php index 22c749fbc..fb4bf93e8 100644 --- a/app/Nova/Event.php +++ b/app/Nova/Event.php @@ -73,7 +73,6 @@ class Event extends Resource */ public function fields(Request $request): array { - return [ Text::make('Event ID', 'id') ->onlyOnDetail(), diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 264164171..5b69f80ff 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -8,7 +8,6 @@ use App\Models\Event; use App\Models\User; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Log; use Laravel\Nova\Metrics\Partition; use Laravel\Nova\Metrics\PartitionResult; @@ -23,6 +22,7 @@ public function name(): string if ($this->resourceId != -1) { $ret .= ' for '.Event::where('id', $this->resourceId)->sole()->name; } + return $ret; } @@ -35,7 +35,7 @@ public function name(): string /** * If displaying on the main dashboard, this indicates the event to get attendance from. - * + * * @var int */ private int $resourceId; @@ -43,7 +43,7 @@ public function name(): string /** * If displaying on a page different from the type of attendable you are showing. * This indicates the morphClass of the attendable (for example, an event). - * + * * @var string */ private string $attendableType; @@ -51,7 +51,7 @@ public function name(): string /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(bool $showAllTime = false, int $resourceId = -1, string $attendableType = "") + public function __construct(bool $showAllTime = false, int $resourceId = -1, string $attendableType = '') { parent::__construct(); $this->resourceId = $resourceId; @@ -64,11 +64,13 @@ public function __construct(bool $showAllTime = false, int $resourceId = -1, str */ public function calculate(Request $request): PartitionResult { - $resourceId; + $attach_to_resource_id = false; if ($this->resourceId != -1) { $resourceId = $this->resourceId; - } else if (isset($request->resourceId)) { + $attach_to_resource_id = true; + } elseif (isset($request->resourceId)) { $resourceId = $request->resourceId; + $attach_to_resource_id = true; } // If a user is found, this will give "Active" in the active column, otherwise the column will be null $query = Attendance::selectRaw('count(distinct gtid) as aggregate') @@ -79,11 +81,11 @@ public function calculate(Request $request): PartitionResult 'active' ); - if (isset($resourceId)) { + if ($attach_to_resource_id) { $query = $query ->where('attendable_id', $resourceId) ->where('attendable_type', - $this->attendableType != "" ? $this->attendableType + $this->attendableType != '' ? $this->attendableType : $request->model()->getMorphClass()); } diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index 714abbc55..2671a60d1 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -7,10 +7,9 @@ use App\Models\Event; use App\Models\Rsvp; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Http\Request; +use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Metrics\Partition; use Laravel\Nova\Metrics\PartitionResult; -use Laravel\Nova\Http\Requests\NovaRequest; class RsvpSourceBreakdown extends Partition { @@ -22,15 +21,17 @@ class RsvpSourceBreakdown extends Partition public function name(): string { return $this->resourceId === -1 ? 'RSVP Sources' : 'RSVP Sources for '.Event::where( - 'id', - $this->resourceId - )->sole()->name; + 'id', + $this->resourceId + )->sole()->name; } /** - * Calculate the value of the metric. + * The resource ID attached to this metric. + * Used when the resource ID cannot be inferred from the Nova page. + * + * @var int */ - protected int $resourceId; public function __construct(int $resourceId = -1) @@ -39,9 +40,13 @@ public function __construct(int $resourceId = -1) $this->resourceId = $resourceId; } + /** + * Calculate the value of the metric. + */ public function calculate(NovaRequest $request): PartitionResult { $resourceId = $request->resourceId ?? $this->resourceId; + return $this->result( Rsvp::where('event_id', $resourceId) ->leftJoin('recruiting_visits', 'source', '=', 'visit_token') From a666f1b4d782ed7d3094ba3e4606e30d7c62bbfa Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sun, 31 Mar 2024 23:58:42 -0400 Subject: [PATCH 05/37] StyleCI Appeasement --- app/Nova/Dashboards/Main.php | 2 +- app/Nova/Metrics/RsvpSourceBreakdown.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index c0abc1d2e..64cbd7a42 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -157,7 +157,7 @@ public function cards(): array $id = intval($parts->last()); return [ - (new ActiveAttendanceBreakdown(true, 1, "event"))->canSee( + (new ActiveAttendanceBreakdown(true, 1, 'event'))->canSee( static fn (Request $request): bool => $request->user()->can('read-attendance') ), ]; diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index 2671a60d1..52da5d7d0 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -46,7 +46,7 @@ public function __construct(int $resourceId = -1) public function calculate(NovaRequest $request): PartitionResult { $resourceId = $request->resourceId ?? $this->resourceId; - + return $this->result( Rsvp::where('event_id', $resourceId) ->leftJoin('recruiting_visits', 'source', '=', 'visit_token') From 583c5f8ba108719a52c2cf28c91594fbe6cda478 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 27 Jan 2024 20:57:54 -0500 Subject: [PATCH 06/37] Bug Squashing: Fixed manual user creation with default Has Ever Logged In value --- app/Nova/User.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Nova/User.php b/app/Nova/User.php index 1565bff95..f2eb3497a 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -34,6 +34,7 @@ use Laravel\Nova\Fields\Email; use Laravel\Nova\Fields\File; use Laravel\Nova\Fields\HasMany; +use Laravel\Nova\Fields\Hidden; use Laravel\Nova\Fields\MorphMany; use Laravel\Nova\Fields\MorphToMany; use Laravel\Nova\Fields\Number; @@ -112,6 +113,10 @@ class User extends Resource public function fields(NovaRequest $request): array { return [ + Hidden::make('Has Ever Logged In') + ->showOnCreating() + ->default(fn (Request $r) => 0), + Text::make('Username', 'uid') ->sortable() ->rules('required', 'max:127') From 621fb94e5573dedad4181a67a4d546b00ee8d835 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 23 Mar 2024 22:39:36 -0400 Subject: [PATCH 07/37] Made RsvpSourceBreakdown match TravelAuthorityRequestReceivedForTravel, getting 404 when on main dashboard --- app/Nova/Dashboards/Main.php | 15 ++++++++++++++ app/Nova/Event.php | 3 +++ app/Nova/Metrics/RsvpSourceBreakdown.php | 25 ++++++++++++++++++++---- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index 752b984e6..f4feee544 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -7,6 +7,7 @@ namespace App\Nova\Dashboards; +use App\Models\Event; use App\Models\Travel; use App\Models\TravelAssignment; use App\Nova\Metrics\ActiveAttendanceBreakdown; @@ -16,6 +17,7 @@ use App\Nova\Metrics\MembersByFiscalYear; use App\Nova\Metrics\PaymentReceivedForTravel; use App\Nova\Metrics\PaymentsPerDay; +use App\Nova\Metrics\RsvpSourceBreakdown; use App\Nova\Metrics\TransactionsByDuesPackage; use App\Nova\Metrics\TravelAuthorityRequestReceivedForTravel; use Carbon\Carbon; @@ -98,6 +100,19 @@ public function cards(): array $cards[] = new EmergencyContactInformationForTravel($travel->id); } + foreach (Event::all() as $event) { + $should_include = false; + + if ($event->rsvps()->count() > 0) { + $should_include = true; + } + if (!$should_include) { + continue; + } + $cards[] = (new RsvpSourceBreakdown($event->id)) + ->canSee(static fn (Request $request): bool => $request->user()->can('read-rsvps')); + } + return $cards; } diff --git a/app/Nova/Event.php b/app/Nova/Event.php index c7101cccf..de56a42fc 100644 --- a/app/Nova/Event.php +++ b/app/Nova/Event.php @@ -80,7 +80,10 @@ class Event extends Resource */ public function fields(Request $request): array { + return [ + Text::make('Event ID', 'id') + ->onlyOnDetail(), Text::make('Event Name', 'name') ->sortable() ->rules('required', 'max:255') diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index d43bf3c62..e53e1f2c4 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -9,6 +9,7 @@ use Illuminate\Http\Request; use Laravel\Nova\Metrics\Partition; use Laravel\Nova\Metrics\PartitionResult; +use Laravel\Nova\Http\Requests\NovaRequest; class RsvpSourceBreakdown extends Partition { @@ -17,15 +18,31 @@ class RsvpSourceBreakdown extends Partition * * @var string */ - public $name = 'RSVP Sources'; + public function name(): string + { + return $this->resourceId === -1 ? 'RSVP Sources' : 'RSVP Sources For '.Rsvp::where( + 'id', + $this->resourceId + )->sole()->name; + } /** * Calculate the value of the metric. */ - public function calculate(Request $request): PartitionResult + + protected int $resourceId; + + public function __construct(int $resourceId = -1) + { + parent::__construct(); + $this->resourceId = $resourceId; + } + + public function calculate(NovaRequest $request): PartitionResult { + $resourceId = $request->resourceId ?? $this->resourceId; return $this->result( - Rsvp::where('event_id', $request->resourceId) + Rsvp::where('event_id', $resourceId) ->leftJoin('recruiting_visits', 'source', '=', 'visit_token') ->when( config('database.default') === 'mysql', @@ -53,6 +70,6 @@ static function (Builder $query): void { */ public function uriKey(): string { - return 'rsvp-source-breakdown'; + return $this->resourceId === -1 ? 'rsvp-source-breakdown' : 'rsvp-source-breakdown-'.$this->resourceId; } } From fd5c93c18a9c133fd3d8cd65f9c0bbe3a8049306 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sun, 31 Mar 2024 23:23:57 -0400 Subject: [PATCH 08/37] Added cards for RSVPs and Attendance of events to main dashboard --- app/Nova/Dashboards/Main.php | 65 +++++++++++++++++++ .../Metrics/ActiveAttendanceBreakdown.php | 44 +++++++++++-- app/Nova/Metrics/RsvpSourceBreakdown.php | 3 +- 3 files changed, 105 insertions(+), 7 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index f4feee544..d9b2575e0 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -102,15 +102,29 @@ public function cards(): array foreach (Event::all() as $event) { $should_include = false; + $attributes = $event->getAttributes(); if ($event->rsvps()->count() > 0) { $should_include = true; } + if ($event->attendance()->count() > 0) { + $should_include = true; + } + if ($attributes['end_time'] === null) { + if ($attributes['start_time'] === null || $attributes['start_time'] < Carbon::now()) { + $should_include = false; + } + } else if ($attributes['end_time'] < Carbon::now()) { + $should_include = false; + } if (!$should_include) { continue; } + $cards[] = (new RsvpSourceBreakdown($event->id)) ->canSee(static fn (Request $request): bool => $request->user()->can('read-rsvps')); + $cards[] = (new ActiveAttendanceBreakdown(true, $event->id, "event")) + ->canSee(static fn (Request $request): bool => $request->user()->can('read-attendance')); } return $cards; @@ -142,6 +156,57 @@ public function cards(): array ]; } + if (request()->is('nova-api/metrics/rsvp-source-breakdown-*')) { + $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); + $id = intval($parts->last()); + return [ + (new RsvpSourceBreakdown($id))->canSee( + static fn (Request $request): bool => $request->user()->can('read-rsvps') + ), + ]; + } + + if (request()->is('nova-api/metrics/active-attendance-breakdown-event-*')) { + $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); + $id = intval($parts->last()); + return [ + (new ActiveAttendanceBreakdown(true, 1, "event"))->canSee( + static fn (Request $request): bool => $request->user()->can('read-attendance') + ) + ]; + } + + + if (request()->is('nova-api/metrics/emergency-contact-*')) { + $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); + $id = intval($parts->last()); + + return [ + new EmergencyContactInformationForTravel($id), + ]; + } + + + if (request()->is('nova-api/metrics/rsvp-source-breakdown-*')) { + $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); + $id = intval($parts->last()); + return [ + (new RsvpSourceBreakdown($id))->canSee( + static fn (Request $request): bool => $request->user()->can('read-rsvps') + ), + ]; + } + + if (request()->is('nova-api/metrics/active-attendance-breakdown-event-*')) { + $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); + $id = intval($parts->last()); + return [ + (new ActiveAttendanceBreakdown(true, 1, "event"))->canSee( + static fn (Request $request): bool => $request->user()->can('read-attendance') + ) + ]; + } + return $cards; } } diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 9952f06e4..264164171 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -5,8 +5,10 @@ namespace App\Nova\Metrics; use App\Models\Attendance; +use App\Models\Event; use App\Models\User; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; use Laravel\Nova\Metrics\Partition; use Laravel\Nova\Metrics\PartitionResult; @@ -17,7 +19,11 @@ class ActiveAttendanceBreakdown extends Partition */ public function name(): string { - return $this->showAllTime ? 'Active Attendees' : 'Attendees Last 4 Weeks'; + $ret = $this->showAllTime ? 'Active Attendees' : 'Attendees Last 4 Weeks'; + if ($this->resourceId != -1) { + $ret .= ' for '.Event::where('id', $this->resourceId)->sole()->name; + } + return $ret; } /** @@ -27,13 +33,30 @@ public function name(): string */ protected $showAllTime = false; + /** + * If displaying on the main dashboard, this indicates the event to get attendance from. + * + * @var int + */ + private int $resourceId; + + /** + * If displaying on a page different from the type of attendable you are showing. + * This indicates the morphClass of the attendable (for example, an event). + * + * @var string + */ + private string $attendableType; + /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(bool $showAllTime = false) + public function __construct(bool $showAllTime = false, int $resourceId = -1, string $attendableType = "") { parent::__construct(); + $this->resourceId = $resourceId; $this->showAllTime = $showAllTime; + $this->attendableType = $attendableType; } /** @@ -41,6 +64,12 @@ public function __construct(bool $showAllTime = false) */ public function calculate(Request $request): PartitionResult { + $resourceId; + if ($this->resourceId != -1) { + $resourceId = $this->resourceId; + } else if (isset($request->resourceId)) { + $resourceId = $request->resourceId; + } // If a user is found, this will give "Active" in the active column, otherwise the column will be null $query = Attendance::selectRaw('count(distinct gtid) as aggregate') ->selectSub( @@ -50,10 +79,12 @@ public function calculate(Request $request): PartitionResult 'active' ); - if (isset($request->resourceId)) { + if (isset($resourceId)) { $query = $query - ->where('attendable_id', $request->resourceId) - ->where('attendable_type', $request->model()->getMorphClass()); + ->where('attendable_id', $resourceId) + ->where('attendable_type', + $this->attendableType != "" ? $this->attendableType + : $request->model()->getMorphClass()); } if (! $this->showAllTime) { @@ -81,6 +112,7 @@ public function calculate(Request $request): PartitionResult */ public function uriKey(): string { - return 'active-attendance-breakdown'; + return $this->resourceId === -1 ? 'active-attendance-breakdown' + : 'active-attendance-breakdown-'.$this->attendableType.'-'.$this->resourceId; } } diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index e53e1f2c4..714abbc55 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -4,6 +4,7 @@ namespace App\Nova\Metrics; +use App\Models\Event; use App\Models\Rsvp; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; @@ -20,7 +21,7 @@ class RsvpSourceBreakdown extends Partition */ public function name(): string { - return $this->resourceId === -1 ? 'RSVP Sources' : 'RSVP Sources For '.Rsvp::where( + return $this->resourceId === -1 ? 'RSVP Sources' : 'RSVP Sources for '.Event::where( 'id', $this->resourceId )->sole()->name; From 445e51a3098e35ca71bbe5e701ec80f638309e6c Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sun, 31 Mar 2024 23:57:27 -0400 Subject: [PATCH 09/37] StyleCI appeasement --- app/Nova/Dashboards/Main.php | 10 ++++++---- app/Nova/Event.php | 1 - .../Metrics/ActiveAttendanceBreakdown.php | 18 ++++++++++-------- app/Nova/Metrics/RsvpSourceBreakdown.php | 19 ++++++++++++------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index d9b2575e0..c07a26bf1 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -114,16 +114,16 @@ public function cards(): array if ($attributes['start_time'] === null || $attributes['start_time'] < Carbon::now()) { $should_include = false; } - } else if ($attributes['end_time'] < Carbon::now()) { + } elseif ($attributes['end_time'] < Carbon::now()) { $should_include = false; } - if (!$should_include) { + if (! $should_include) { continue; } $cards[] = (new RsvpSourceBreakdown($event->id)) ->canSee(static fn (Request $request): bool => $request->user()->can('read-rsvps')); - $cards[] = (new ActiveAttendanceBreakdown(true, $event->id, "event")) + $cards[] = (new ActiveAttendanceBreakdown(true, $event->id, 'event')) ->canSee(static fn (Request $request): bool => $request->user()->can('read-attendance')); } @@ -190,6 +190,7 @@ public function cards(): array if (request()->is('nova-api/metrics/rsvp-source-breakdown-*')) { $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); $id = intval($parts->last()); + return [ (new RsvpSourceBreakdown($id))->canSee( static fn (Request $request): bool => $request->user()->can('read-rsvps') @@ -200,10 +201,11 @@ public function cards(): array if (request()->is('nova-api/metrics/active-attendance-breakdown-event-*')) { $parts = Str::of(Str::of(request()->path())->explode('/')->last())->explode('-'); $id = intval($parts->last()); + return [ (new ActiveAttendanceBreakdown(true, 1, "event"))->canSee( static fn (Request $request): bool => $request->user()->can('read-attendance') - ) + ), ]; } diff --git a/app/Nova/Event.php b/app/Nova/Event.php index de56a42fc..9b1a7a5be 100644 --- a/app/Nova/Event.php +++ b/app/Nova/Event.php @@ -80,7 +80,6 @@ class Event extends Resource */ public function fields(Request $request): array { - return [ Text::make('Event ID', 'id') ->onlyOnDetail(), diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 264164171..5b69f80ff 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -8,7 +8,6 @@ use App\Models\Event; use App\Models\User; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Log; use Laravel\Nova\Metrics\Partition; use Laravel\Nova\Metrics\PartitionResult; @@ -23,6 +22,7 @@ public function name(): string if ($this->resourceId != -1) { $ret .= ' for '.Event::where('id', $this->resourceId)->sole()->name; } + return $ret; } @@ -35,7 +35,7 @@ public function name(): string /** * If displaying on the main dashboard, this indicates the event to get attendance from. - * + * * @var int */ private int $resourceId; @@ -43,7 +43,7 @@ public function name(): string /** * If displaying on a page different from the type of attendable you are showing. * This indicates the morphClass of the attendable (for example, an event). - * + * * @var string */ private string $attendableType; @@ -51,7 +51,7 @@ public function name(): string /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(bool $showAllTime = false, int $resourceId = -1, string $attendableType = "") + public function __construct(bool $showAllTime = false, int $resourceId = -1, string $attendableType = '') { parent::__construct(); $this->resourceId = $resourceId; @@ -64,11 +64,13 @@ public function __construct(bool $showAllTime = false, int $resourceId = -1, str */ public function calculate(Request $request): PartitionResult { - $resourceId; + $attach_to_resource_id = false; if ($this->resourceId != -1) { $resourceId = $this->resourceId; - } else if (isset($request->resourceId)) { + $attach_to_resource_id = true; + } elseif (isset($request->resourceId)) { $resourceId = $request->resourceId; + $attach_to_resource_id = true; } // If a user is found, this will give "Active" in the active column, otherwise the column will be null $query = Attendance::selectRaw('count(distinct gtid) as aggregate') @@ -79,11 +81,11 @@ public function calculate(Request $request): PartitionResult 'active' ); - if (isset($resourceId)) { + if ($attach_to_resource_id) { $query = $query ->where('attendable_id', $resourceId) ->where('attendable_type', - $this->attendableType != "" ? $this->attendableType + $this->attendableType != '' ? $this->attendableType : $request->model()->getMorphClass()); } diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index 714abbc55..2671a60d1 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -7,10 +7,9 @@ use App\Models\Event; use App\Models\Rsvp; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Http\Request; +use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Metrics\Partition; use Laravel\Nova\Metrics\PartitionResult; -use Laravel\Nova\Http\Requests\NovaRequest; class RsvpSourceBreakdown extends Partition { @@ -22,15 +21,17 @@ class RsvpSourceBreakdown extends Partition public function name(): string { return $this->resourceId === -1 ? 'RSVP Sources' : 'RSVP Sources for '.Event::where( - 'id', - $this->resourceId - )->sole()->name; + 'id', + $this->resourceId + )->sole()->name; } /** - * Calculate the value of the metric. + * The resource ID attached to this metric. + * Used when the resource ID cannot be inferred from the Nova page. + * + * @var int */ - protected int $resourceId; public function __construct(int $resourceId = -1) @@ -39,9 +40,13 @@ public function __construct(int $resourceId = -1) $this->resourceId = $resourceId; } + /** + * Calculate the value of the metric. + */ public function calculate(NovaRequest $request): PartitionResult { $resourceId = $request->resourceId ?? $this->resourceId; + return $this->result( Rsvp::where('event_id', $resourceId) ->leftJoin('recruiting_visits', 'source', '=', 'visit_token') From 6ae5d6972d71956e28d6fc2a927b14a6aa5c9901 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sun, 31 Mar 2024 23:58:42 -0400 Subject: [PATCH 10/37] StyleCI Appeasement --- app/Nova/Dashboards/Main.php | 2 +- app/Nova/Metrics/RsvpSourceBreakdown.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index c07a26bf1..9240af686 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -203,7 +203,7 @@ public function cards(): array $id = intval($parts->last()); return [ - (new ActiveAttendanceBreakdown(true, 1, "event"))->canSee( + (new ActiveAttendanceBreakdown(true, 1, 'event'))->canSee( static fn (Request $request): bool => $request->user()->can('read-attendance') ), ]; diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index 2671a60d1..52da5d7d0 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -46,7 +46,7 @@ public function __construct(int $resourceId = -1) public function calculate(NovaRequest $request): PartitionResult { $resourceId = $request->resourceId ?? $this->resourceId; - + return $this->result( Rsvp::where('event_id', $resourceId) ->leftJoin('recruiting_visits', 'source', '=', 'visit_token') From a05f688e2a3a2d17e1cb8e6292b08ec3496a600b Mon Sep 17 00:00:00 2001 From: jvogt23 <91633361+jvogt23@users.noreply.github.com> Date: Wed, 3 Apr 2024 08:28:08 -0400 Subject: [PATCH 11/37] FixStyle after rebase --- app/Nova/Dashboards/Main.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index af8bbf7dc..aaa29557b 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -178,8 +178,6 @@ public function cards(): array ]; } - - return $cards; } } From 9443816e8d0088f515a6c722e5f2b02000ecd046 Mon Sep 17 00:00:00 2001 From: jvogt23 <91633361+jvogt23@users.noreply.github.com> Date: Wed, 3 Apr 2024 08:35:32 -0400 Subject: [PATCH 12/37] Style fixes --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 4 ---- app/Nova/Metrics/RsvpSourceBreakdown.php | 2 -- 2 files changed, 6 deletions(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 5b69f80ff..9693d8bc3 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -35,16 +35,12 @@ public function name(): string /** * If displaying on the main dashboard, this indicates the event to get attendance from. - * - * @var int */ private int $resourceId; /** * If displaying on a page different from the type of attendable you are showing. * This indicates the morphClass of the attendable (for example, an event). - * - * @var string */ private string $attendableType; diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index 52da5d7d0..d5f1ed9dc 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -15,8 +15,6 @@ class RsvpSourceBreakdown extends Partition { /** * The displayable name of the metric. - * - * @var string */ public function name(): string { From 38c2d7c66dafa887134f4991298efc2ca71fe07a Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Fri, 5 Apr 2024 02:24:09 -0400 Subject: [PATCH 13/37] Linter appeasement --- app/Nova/Metrics/RsvpSourceBreakdown.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index d5f1ed9dc..b7cb10667 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -27,8 +27,6 @@ public function name(): string /** * The resource ID attached to this metric. * Used when the resource ID cannot be inferred from the Nova page. - * - * @var int */ protected int $resourceId; From 42b6ad041c4ce76d2f60312fb7252067e85e93ae Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Fri, 5 Apr 2024 02:36:57 -0400 Subject: [PATCH 14/37] Linter appeasement --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 16 +++++++++------- app/Nova/User.php | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 9693d8bc3..1f3fa4786 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -19,7 +19,7 @@ class ActiveAttendanceBreakdown extends Partition public function name(): string { $ret = $this->showAllTime ? 'Active Attendees' : 'Attendees Last 4 Weeks'; - if ($this->resourceId != -1) { + if ($this->resourceId !== -1) { $ret .= ' for '.Event::where('id', $this->resourceId)->sole()->name; } @@ -61,7 +61,7 @@ public function __construct(bool $showAllTime = false, int $resourceId = -1, str public function calculate(Request $request): PartitionResult { $attach_to_resource_id = false; - if ($this->resourceId != -1) { + if ($this->resourceId !== -1) { $resourceId = $this->resourceId; $attach_to_resource_id = true; } elseif (isset($request->resourceId)) { @@ -80,9 +80,11 @@ public function calculate(Request $request): PartitionResult if ($attach_to_resource_id) { $query = $query ->where('attendable_id', $resourceId) - ->where('attendable_type', - $this->attendableType != '' ? $this->attendableType - : $request->model()->getMorphClass()); + ->where( + 'attendable_type', + $this->attendableType != '' ? $this->attendableType : + $request->model()->getMorphClass() + ); } if (! $this->showAllTime) { @@ -110,7 +112,7 @@ public function calculate(Request $request): PartitionResult */ public function uriKey(): string { - return $this->resourceId === -1 ? 'active-attendance-breakdown' - : 'active-attendance-breakdown-'.$this->attendableType.'-'.$this->resourceId; + return $this->resourceId === -1 ? 'active-attendance-breakdown' : + 'active-attendance-breakdown-'.$this->attendableType.'-'.$this->resourceId; } } diff --git a/app/Nova/User.php b/app/Nova/User.php index f2eb3497a..2dd5c5039 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -115,7 +115,7 @@ public function fields(NovaRequest $request): array return [ Hidden::make('Has Ever Logged In') ->showOnCreating() - ->default(fn (Request $r) => 0), + ->default(static fn (Request $r) => 0), Text::make('Username', 'uid') ->sortable() From 56722bb6576c1ac6bc70fb76d8c4c9d573f6e64a Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Fri, 5 Apr 2024 02:38:28 -0400 Subject: [PATCH 15/37] Linter appeasement --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 1f3fa4786..a5f0e976b 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -82,7 +82,7 @@ public function calculate(Request $request): PartitionResult ->where('attendable_id', $resourceId) ->where( 'attendable_type', - $this->attendableType != '' ? $this->attendableType : + $this->attendableType !== '' ? $this->attendableType : $request->model()->getMorphClass() ); } From 3710eade84eae712aa6d84467e16a5e963dfd8dd Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Fri, 5 Apr 2024 02:42:11 -0400 Subject: [PATCH 16/37] Linter appeasement --- app/Nova/Dashboards/Main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index aaa29557b..412e48495 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -161,7 +161,7 @@ public function cards(): array $id = intval($parts->last()); return [ - (new ActiveAttendanceBreakdown(true, 1, 'event'))->canSee( + (new ActiveAttendanceBreakdown(true, $id, 'event'))->canSee( static fn (Request $request): bool => $request->user()->can('read-attendance') ), ]; From 17220bd7e90c2c4dcaebfb02a171d345c235063c Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Fri, 5 Apr 2024 17:28:47 -0400 Subject: [PATCH 17/37] Linter appeasement --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index a5f0e976b..ca7e01b68 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -36,7 +36,7 @@ public function name(): string /** * If displaying on the main dashboard, this indicates the event to get attendance from. */ - private int $resourceId; + private int $resourceId = -1; /** * If displaying on a page different from the type of attendable you are showing. From d84022d50cba7cdc272ca2445c2236bc0fbbcf35 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Fri, 5 Apr 2024 17:33:30 -0400 Subject: [PATCH 18/37] Linter appeasement --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index ca7e01b68..462dd0a8a 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -60,6 +60,7 @@ public function __construct(bool $showAllTime = false, int $resourceId = -1, str */ public function calculate(Request $request): PartitionResult { + $resourceId = -1; $attach_to_resource_id = false; if ($this->resourceId !== -1) { $resourceId = $this->resourceId; From c356f7728b2d99319d3448b9d04ed663f9e9da7f Mon Sep 17 00:00:00 2001 From: jvogt23 <91633361+jvogt23@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:00:41 -0400 Subject: [PATCH 19/37] Update app/Nova/Dashboards/Main.php Co-authored-by: Kristaps Berzinch --- app/Nova/Dashboards/Main.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index 412e48495..68d857169 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -110,11 +110,11 @@ public function cards(): array if ($event->attendance()->count() > 0) { $should_include = true; } - if ($attributes['end_time'] === null) { - if ($attributes['start_time'] === null || $attributes['start_time'] < Carbon::now()) { + if ($event->end_time === null) { + if ($event->start_time === null || $event->start_time < Carbon::now()) { $should_include = false; } - } elseif ($attributes['end_time'] < Carbon::now()) { + } elseif ($event->end_time < Carbon::now()) { $should_include = false; } if (! $should_include) { From 962165e19a790429931e2bcceda1b53ee6d19a55 Mon Sep 17 00:00:00 2001 From: jvogt23 <91633361+jvogt23@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:01:20 -0400 Subject: [PATCH 20/37] Update app/Nova/Metrics/ActiveAttendanceBreakdown.php Co-authored-by: Kristaps Berzinch --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 462dd0a8a..cb18243e3 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -114,6 +114,6 @@ public function calculate(Request $request): PartitionResult public function uriKey(): string { return $this->resourceId === -1 ? 'active-attendance-breakdown' : - 'active-attendance-breakdown-'.$this->attendableType.'-'.$this->resourceId; + '../'.$this->attendableType.'/'.$this->resourceId.'/metrics/active-attendance-breakdown'; } } From f56e33210d10eca47cc40c4a1e469d2bce5380ba Mon Sep 17 00:00:00 2001 From: jvogt23 <91633361+jvogt23@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:13:01 -0400 Subject: [PATCH 21/37] Update app/Nova/User.php Co-authored-by: Kristaps Berzinch --- app/Nova/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Nova/User.php b/app/Nova/User.php index 2dd5c5039..635f38d8e 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -115,7 +115,7 @@ public function fields(NovaRequest $request): array return [ Hidden::make('Has Ever Logged In') ->showOnCreating() - ->default(static fn (Request $r) => 0), + ->default(static fn (Request $r): false => false), Text::make('Username', 'uid') ->sortable() From aca2593a11009c86029a079da7d499333016bddd Mon Sep 17 00:00:00 2001 From: jvogt23 <91633361+jvogt23@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:16:00 -0400 Subject: [PATCH 22/37] Update app/Nova/Metrics/ActiveAttendanceBreakdown.php Co-authored-by: Kristaps Berzinch --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index cb18243e3..404b7143d 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -60,15 +60,7 @@ public function __construct(bool $showAllTime = false, int $resourceId = -1, str */ public function calculate(Request $request): PartitionResult { - $resourceId = -1; - $attach_to_resource_id = false; - if ($this->resourceId !== -1) { - $resourceId = $this->resourceId; - $attach_to_resource_id = true; - } elseif (isset($request->resourceId)) { - $resourceId = $request->resourceId; - $attach_to_resource_id = true; - } + $resourceId = $request->resourceId ?? $this->resourceId; // If a user is found, this will give "Active" in the active column, otherwise the column will be null $query = Attendance::selectRaw('count(distinct gtid) as aggregate') ->selectSub( From 5c61d436b6aa80d9658f4772b46f67604f3c4885 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 13 Apr 2024 23:16:27 -0400 Subject: [PATCH 23/37] Remove unnecessary variable --- app/Nova/Dashboards/Main.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index 68d857169..a25bb3a81 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -102,7 +102,6 @@ public function cards(): array foreach (Event::all() as $event) { $should_include = false; - $attributes = $event->getAttributes(); if ($event->rsvps()->count() > 0) { $should_include = true; From 4a33a8ba89f8e68cf0558628e507e1ad2c2e5630 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 13 Apr 2024 23:19:00 -0400 Subject: [PATCH 24/37] Remove debug attributes --- app/Nova/Event.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Nova/Event.php b/app/Nova/Event.php index 9b1a7a5be..c7101cccf 100644 --- a/app/Nova/Event.php +++ b/app/Nova/Event.php @@ -81,8 +81,6 @@ class Event extends Resource public function fields(Request $request): array { return [ - Text::make('Event ID', 'id') - ->onlyOnDetail(), Text::make('Event Name', 'name') ->sortable() ->rules('required', 'max:255') From fed518a43b4282e1e5aac4ee6902b195ddb01aee Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 13 Apr 2024 23:25:51 -0400 Subject: [PATCH 25/37] Changed to constructor property promotion --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 404b7143d..acd931254 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -36,7 +36,7 @@ public function name(): string /** * If displaying on the main dashboard, this indicates the event to get attendance from. */ - private int $resourceId = -1; + private ?int $resourceId; /** * If displaying on a page different from the type of attendable you are showing. @@ -47,12 +47,9 @@ public function name(): string /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(bool $showAllTime = false, int $resourceId = -1, string $attendableType = '') + public function __construct(bool $showAllTime = false, int $resourceId, string $attendableType = '') { parent::__construct(); - $this->resourceId = $resourceId; - $this->showAllTime = $showAllTime; - $this->attendableType = $attendableType; } /** From 083fe021437257f6263ea025808b1728cb140ce9 Mon Sep 17 00:00:00 2001 From: jvogt23 <91633361+jvogt23@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:26:10 -0400 Subject: [PATCH 26/37] Update app/Nova/Metrics/ActiveAttendanceBreakdown.php Co-authored-by: Kristaps Berzinch --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index acd931254..b69468807 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -67,7 +67,7 @@ public function calculate(Request $request): PartitionResult 'active' ); - if ($attach_to_resource_id) { + if ($resourceId !== null) { $query = $query ->where('attendable_id', $resourceId) ->where( From e2915718384fa6478082071fc4a1f6d8bbc5036c Mon Sep 17 00:00:00 2001 From: jvogt23 <91633361+jvogt23@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:26:17 -0400 Subject: [PATCH 27/37] Update app/Nova/Metrics/ActiveAttendanceBreakdown.php Co-authored-by: Kristaps Berzinch --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index b69468807..eda0645de 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -72,8 +72,7 @@ public function calculate(Request $request): PartitionResult ->where('attendable_id', $resourceId) ->where( 'attendable_type', - $this->attendableType !== '' ? $this->attendableType : - $request->model()->getMorphClass() + $request?->model()?->getMorphClass() ?? $this->attendableType ); } From 4e417398eb9944a663b6d93e2cd3a027e5d8e9b7 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 13 Apr 2024 23:28:28 -0400 Subject: [PATCH 28/37] Made attributes nullable, defaulting to null --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 4 ++-- app/Nova/Metrics/RsvpSourceBreakdown.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index eda0645de..e57cd32df 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -42,12 +42,12 @@ public function name(): string * If displaying on a page different from the type of attendable you are showing. * This indicates the morphClass of the attendable (for example, an event). */ - private string $attendableType; + private ?string $attendableType; /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(bool $showAllTime = false, int $resourceId, string $attendableType = '') + public function __construct(bool $showAllTime = false, ?int $resourceId = null, ?string $attendableType = null) { parent::__construct(); } diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index b7cb10667..7187dda6a 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -28,9 +28,9 @@ public function name(): string * The resource ID attached to this metric. * Used when the resource ID cannot be inferred from the Nova page. */ - protected int $resourceId; + protected ?int $resourceId; - public function __construct(int $resourceId = -1) + public function __construct(?int $resourceId = null) { parent::__construct(); $this->resourceId = $resourceId; From a0215de8167849073448df77ae7e6812b4466f9b Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 13 Apr 2024 23:58:36 -0400 Subject: [PATCH 29/37] resolved requested changes, needs debugging --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 6 +++--- app/Nova/Metrics/RsvpSourceBreakdown.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index e57cd32df..08be4ed9b 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -36,18 +36,18 @@ public function name(): string /** * If displaying on the main dashboard, this indicates the event to get attendance from. */ - private ?int $resourceId; + private $resourceId = null; /** * If displaying on a page different from the type of attendable you are showing. * This indicates the morphClass of the attendable (for example, an event). */ - private ?string $attendableType; + private $attendableType = null; /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(bool $showAllTime = false, ?int $resourceId = null, ?string $attendableType = null) + public function __construct(bool $showAllTime = false, $resourceId = null, $attendableType = null) { parent::__construct(); } diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index 7187dda6a..de4db6d79 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -28,7 +28,7 @@ public function name(): string * The resource ID attached to this metric. * Used when the resource ID cannot be inferred from the Nova page. */ - protected ?int $resourceId; + protected $resourceId; public function __construct(?int $resourceId = null) { From 51c118cbcaaea8764c887fbf5d6b0e9ee3e71eff Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Tue, 13 Aug 2024 22:37:30 -0400 Subject: [PATCH 30/37] Fixed most of the nitpicks - The remaining ones need troubleshooting --- app/Nova/Dashboards/Main.php | 7 ++-- app/Nova/Event.php | 2 - .../Metrics/ActiveAttendanceBreakdown.php | 37 +++++-------------- app/Nova/Metrics/RsvpSourceBreakdown.php | 12 ++---- app/Nova/User.php | 2 +- 5 files changed, 16 insertions(+), 44 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index d9b2575e0..276de10f3 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -102,7 +102,6 @@ public function cards(): array foreach (Event::all() as $event) { $should_include = false; - $attributes = $event->getAttributes(); if ($event->rsvps()->count() > 0) { $should_include = true; @@ -110,11 +109,11 @@ public function cards(): array if ($event->attendance()->count() > 0) { $should_include = true; } - if ($attributes['end_time'] === null) { - if ($attributes['start_time'] === null || $attributes['start_time'] < Carbon::now()) { + if ($event->end_time === null) { + if ($event->start_time === null || $event->start_time < Carbon::now()) { $should_include = false; } - } else if ($attributes['end_time'] < Carbon::now()) { + } else if ($event->end_time < Carbon::now()) { $should_include = false; } if (!$should_include) { diff --git a/app/Nova/Event.php b/app/Nova/Event.php index de56a42fc..6e0de2132 100644 --- a/app/Nova/Event.php +++ b/app/Nova/Event.php @@ -82,8 +82,6 @@ public function fields(Request $request): array { return [ - Text::make('Event ID', 'id') - ->onlyOnDetail(), Text::make('Event Name', 'name') ->sortable() ->rules('required', 'max:255') diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 264164171..157e127d9 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -26,37 +26,16 @@ public function name(): string return $ret; } - /** - * Whether to show based on all attendance records or only those from the last two weeks. - * - * @var bool - */ - protected $showAllTime = false; - - /** - * If displaying on the main dashboard, this indicates the event to get attendance from. - * - * @var int - */ - private int $resourceId; - - /** - * If displaying on a page different from the type of attendable you are showing. - * This indicates the morphClass of the attendable (for example, an event). - * - * @var string - */ - private string $attendableType; /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(bool $showAllTime = false, int $resourceId = -1, string $attendableType = "") + public function __construct(public bool $showAllTime = false, public int $resourceId = -1, public ?string $attendableType = null) { parent::__construct(); - $this->resourceId = $resourceId; - $this->showAllTime = $showAllTime; - $this->attendableType = $attendableType; + // $this->resourceId = $resourceId; + // $this->showAllTime = $showAllTime; + // $this->attendableType = $attendableType; } /** @@ -64,7 +43,7 @@ public function __construct(bool $showAllTime = false, int $resourceId = -1, str */ public function calculate(Request $request): PartitionResult { - $resourceId; + $resourceId ;//= $request->resourceId ?? $this->resourceId; if ($this->resourceId != -1) { $resourceId = $this->resourceId; } else if (isset($request->resourceId)) { @@ -83,8 +62,9 @@ public function calculate(Request $request): PartitionResult $query = $query ->where('attendable_id', $resourceId) ->where('attendable_type', - $this->attendableType != "" ? $this->attendableType - : $request->model()->getMorphClass()); + $this->attendableType ?? $request?->model()?->getMorphClass()); + // $this->attendableType != "" ? $this->attendableType + // : $request->model()->getMorphClass()); } if (! $this->showAllTime) { @@ -114,5 +94,6 @@ public function uriKey(): string { return $this->resourceId === -1 ? 'active-attendance-breakdown' : 'active-attendance-breakdown-'.$this->attendableType.'-'.$this->resourceId; + //'../'.$this->attendableType.'/'.$this->resourceId.'/metrics/active-attendance-breakdown'; } } diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index 714abbc55..0f3fa8221 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -21,22 +21,16 @@ class RsvpSourceBreakdown extends Partition */ public function name(): string { - return $this->resourceId === -1 ? 'RSVP Sources' : 'RSVP Sources for '.Event::where( + return $this->resourceId === null ? 'RSVP Sources' : 'RSVP Sources for '.Event::where( 'id', $this->resourceId )->sole()->name; } - /** - * Calculate the value of the metric. - */ - - protected int $resourceId; - public function __construct(int $resourceId = -1) + public function __construct(public ?int $resourceId = null) { parent::__construct(); - $this->resourceId = $resourceId; } public function calculate(NovaRequest $request): PartitionResult @@ -71,6 +65,6 @@ static function (Builder $query): void { */ public function uriKey(): string { - return $this->resourceId === -1 ? 'rsvp-source-breakdown' : 'rsvp-source-breakdown-'.$this->resourceId; + return $this->resourceId === null ? 'rsvp-source-breakdown' : 'rsvp-source-breakdown-'.$this->resourceId; } } diff --git a/app/Nova/User.php b/app/Nova/User.php index f2eb3497a..d220b4567 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -115,7 +115,7 @@ public function fields(NovaRequest $request): array return [ Hidden::make('Has Ever Logged In') ->showOnCreating() - ->default(fn (Request $r) => 0), + ->default(fn (Request $r): false => false), Text::make('Username', 'uid') ->sortable() From 6ec2cff61a9ae53f5529dc916715c221df0ab87d Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Tue, 13 Aug 2024 22:47:43 -0400 Subject: [PATCH 31/37] Fix glitch caused by unmerged change --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 6da888804..e998b8bab 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -58,7 +58,7 @@ public function calculate(Request $request): PartitionResult 'active' ); - if ($resourceId !== null) { + if (isset($resourceId)) { $query = $query ->where('attendable_id', $resourceId) ->where('attendable_type', From 8bfd48e777c414aaf2b59189ce9ca8f7053f89f7 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 17 Aug 2024 17:09:54 -0400 Subject: [PATCH 32/37] Resolved last few conversations, now to appease the linter --- .../Metrics/ActiveAttendanceBreakdown.php | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index e998b8bab..9002719a7 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -19,7 +19,7 @@ class ActiveAttendanceBreakdown extends Partition public function name(): string { $ret = $this->showAllTime ? 'Active Attendees' : 'Attendees Last 4 Weeks'; - if ($this->resourceId !== -1) { + if ($this->resourceId !== null) { $ret .= ' for '.Event::where('id', $this->resourceId)->sole()->name; } @@ -30,7 +30,7 @@ public function name(): string /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(public bool $showAllTime = false, public int $resourceId = -1, public ?string $attendableType = null) + public function __construct(public bool $showAllTime = false, public ?int $resourceId = null, public ?string $attendableType = null) { parent::__construct(); // $this->resourceId = $resourceId; @@ -43,12 +43,12 @@ public function __construct(public bool $showAllTime = false, public int $resour */ public function calculate(Request $request): PartitionResult { - $resourceId ;//= $request->resourceId ?? $this->resourceId; - if ($this->resourceId != -1) { - $resourceId = $this->resourceId; - } else if (isset($request->resourceId)) { - $resourceId = $request->resourceId; - } + $resourceId = $this->resourceId ?? $request->resourceId;//= $request->resourceId ?? $this->resourceId; + // if ($this->resourceId !== null) { + // $resourceId = $this->resourceId; + // } else if (isset($request->resourceId)) { + // $resourceId = $request->resourceId; + // } // If a user is found, this will give "Active" in the active column, otherwise the column will be null $query = Attendance::selectRaw('count(distinct gtid) as aggregate') ->selectSub( @@ -58,7 +58,7 @@ public function calculate(Request $request): PartitionResult 'active' ); - if (isset($resourceId)) { + if ($resourceId !== null) { $query = $query ->where('attendable_id', $resourceId) ->where('attendable_type', @@ -92,8 +92,7 @@ public function calculate(Request $request): PartitionResult */ public function uriKey(): string { - return $this->resourceId === -1 ? 'active-attendance-breakdown' - : 'active-attendance-breakdown-'.$this->attendableType.'-'.$this->resourceId; - //'../'.$this->attendableType.'/'.$this->resourceId.'/metrics/active-attendance-breakdown'; + return $this->resourceId === null ? 'active-attendance-breakdown' : + '../'.$this->attendableType.'s/'.$this->resourceId.'/metrics/active-attendance-breakdown'; } } From b0bc8f40eb9e11b27b3eba83ed179c3ad1550864 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 17 Aug 2024 17:37:50 -0400 Subject: [PATCH 33/37] Pint style fixes --- app/Nova/Dashboards/Main.php | 14 +++++++------- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 15 ++------------- app/Nova/Metrics/RsvpSourceBreakdown.php | 7 +++---- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index c44bc5242..0b9a68d0d 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -36,24 +36,24 @@ class Main extends Dashboard public function cards(): array { $cards = [ - (new PaymentsPerDay())->canSee( + (new PaymentsPerDay)->canSee( static fn (Request $request): bool => $request->user()->can('read-payments') ), - (new MembersByFiscalYear())->canSee( + (new MembersByFiscalYear)->canSee( static fn (Request $request): bool => $request->user()->can('read-dues-transactions') ), - (new DuesRevenueByFiscalYear())->canSee( + (new DuesRevenueByFiscalYear)->canSee( static fn (Request $request): bool => $request->user()->can('read-dues-transactions') ), - (new AttendancePerWeek())->canSee( + (new AttendancePerWeek)->canSee( static fn (Request $request): bool => $request->user()->can('read-attendance') ), - (new ActiveAttendanceBreakdown())->canSee( + (new ActiveAttendanceBreakdown)->canSee( static fn (Request $request): bool => $request->user()->can('read-users') && $request->user()->can( 'read-attendance' ) ), - (new TransactionsByDuesPackage()) + (new TransactionsByDuesPackage) ->canSee(static fn (Request $request): bool => $request->user()->can('read-payments')), ]; @@ -113,7 +113,7 @@ public function cards(): array if ($event->start_time === null || $event->start_time < Carbon::now()) { $should_include = false; } - } else if ($event->end_time < Carbon::now()) { + } elseif ($event->end_time < Carbon::now()) { $should_include = false; } if (! $should_include) { diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 9002719a7..1c223c72c 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -26,16 +26,12 @@ public function name(): string return $ret; } - /** * Create a new ActiveAttendanceBreakdown metric. */ public function __construct(public bool $showAllTime = false, public ?int $resourceId = null, public ?string $attendableType = null) { parent::__construct(); - // $this->resourceId = $resourceId; - // $this->showAllTime = $showAllTime; - // $this->attendableType = $attendableType; } /** @@ -43,12 +39,7 @@ public function __construct(public bool $showAllTime = false, public ?int $resou */ public function calculate(Request $request): PartitionResult { - $resourceId = $this->resourceId ?? $request->resourceId;//= $request->resourceId ?? $this->resourceId; - // if ($this->resourceId !== null) { - // $resourceId = $this->resourceId; - // } else if (isset($request->resourceId)) { - // $resourceId = $request->resourceId; - // } + $resourceId = $this->resourceId ?? $request->resourceId; // If a user is found, this will give "Active" in the active column, otherwise the column will be null $query = Attendance::selectRaw('count(distinct gtid) as aggregate') ->selectSub( @@ -62,9 +53,7 @@ public function calculate(Request $request): PartitionResult $query = $query ->where('attendable_id', $resourceId) ->where('attendable_type', - $this->attendableType ?? $request?->model()?->getMorphClass()); - // $this->attendableType != "" ? $this->attendableType - // : $request->model()->getMorphClass()); + $this->attendableType ?? $request?->model()?->getMorphClass()); } if (! $this->showAllTime) { diff --git a/app/Nova/Metrics/RsvpSourceBreakdown.php b/app/Nova/Metrics/RsvpSourceBreakdown.php index dc0cd454d..53e084b93 100644 --- a/app/Nova/Metrics/RsvpSourceBreakdown.php +++ b/app/Nova/Metrics/RsvpSourceBreakdown.php @@ -19,12 +19,11 @@ class RsvpSourceBreakdown extends Partition public function name(): string { return $this->resourceId === null ? 'RSVP Sources' : 'RSVP Sources for '.Event::where( - 'id', - $this->resourceId - )->sole()->name; + 'id', + $this->resourceId + )->sole()->name; } - public function __construct(public ?int $resourceId = null) { parent::__construct(); From 1d503c0981722f2e8fcb8b7ef19404ce945f6019 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 17 Aug 2024 17:51:09 -0400 Subject: [PATCH 34/37] phpcs cleanup --- app/Nova/Dashboards/Main.php | 12 ++++++------ app/Nova/Metrics/ActiveAttendanceBreakdown.php | 12 +++++++++--- app/Nova/User.php | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index 0b9a68d0d..a25bb3a81 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -36,24 +36,24 @@ class Main extends Dashboard public function cards(): array { $cards = [ - (new PaymentsPerDay)->canSee( + (new PaymentsPerDay())->canSee( static fn (Request $request): bool => $request->user()->can('read-payments') ), - (new MembersByFiscalYear)->canSee( + (new MembersByFiscalYear())->canSee( static fn (Request $request): bool => $request->user()->can('read-dues-transactions') ), - (new DuesRevenueByFiscalYear)->canSee( + (new DuesRevenueByFiscalYear())->canSee( static fn (Request $request): bool => $request->user()->can('read-dues-transactions') ), - (new AttendancePerWeek)->canSee( + (new AttendancePerWeek())->canSee( static fn (Request $request): bool => $request->user()->can('read-attendance') ), - (new ActiveAttendanceBreakdown)->canSee( + (new ActiveAttendanceBreakdown())->canSee( static fn (Request $request): bool => $request->user()->can('read-users') && $request->user()->can( 'read-attendance' ) ), - (new TransactionsByDuesPackage) + (new TransactionsByDuesPackage()) ->canSee(static fn (Request $request): bool => $request->user()->can('read-payments')), ]; diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 1c223c72c..5e50b152b 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -29,7 +29,11 @@ public function name(): string /** * Create a new ActiveAttendanceBreakdown metric. */ - public function __construct(public bool $showAllTime = false, public ?int $resourceId = null, public ?string $attendableType = null) + public function __construct( + public bool $showAllTime = false, + public ?int $resourceId = null, + public ?string $attendableType = null + ) { parent::__construct(); } @@ -52,8 +56,10 @@ public function calculate(Request $request): PartitionResult if ($resourceId !== null) { $query = $query ->where('attendable_id', $resourceId) - ->where('attendable_type', - $this->attendableType ?? $request?->model()?->getMorphClass()); + ->where( + 'attendable_type', + $this->attendableType ?? $request?->model()?->getMorphClass() + ); } if (! $this->showAllTime) { diff --git a/app/Nova/User.php b/app/Nova/User.php index d220b4567..0b6c79fea 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -115,7 +115,7 @@ public function fields(NovaRequest $request): array return [ Hidden::make('Has Ever Logged In') ->showOnCreating() - ->default(fn (Request $r): false => false), + ->default(fn(Request $r): false => false), Text::make('Username', 'uid') ->sortable() From fd55c86242cf5645006f165ca158afa937bc246c Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 17 Aug 2024 18:28:12 -0400 Subject: [PATCH 35/37] styleci fix --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 3 +-- app/Nova/User.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index 5e50b152b..c089303b7 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -33,8 +33,7 @@ public function __construct( public bool $showAllTime = false, public ?int $resourceId = null, public ?string $attendableType = null - ) - { + ) { parent::__construct(); } diff --git a/app/Nova/User.php b/app/Nova/User.php index 0ea963d18..beb714337 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -114,7 +114,7 @@ public function fields(NovaRequest $request): array return [ Hidden::make('Has Ever Logged In') ->showOnCreating() - ->default(fn(Request $r): false => false), + ->default(fn (Request $r): false => false), Text::make('Username', 'uid') ->sortable() From 191d5c237e1aeef3aa89741549d89f97cc4b5a12 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 17 Aug 2024 18:33:55 -0400 Subject: [PATCH 36/37] phpcs fix --- app/Nova/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Nova/User.php b/app/Nova/User.php index beb714337..195e002fa 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -114,7 +114,7 @@ public function fields(NovaRequest $request): array return [ Hidden::make('Has Ever Logged In') ->showOnCreating() - ->default(fn (Request $r): false => false), + ->default(static fn (Request $r): bool => false), Text::make('Username', 'uid') ->sortable() From 98b20bb126776eb77e22d6b9487961db92bb4202 Mon Sep 17 00:00:00 2001 From: jvogt23 Date: Sat, 17 Aug 2024 18:41:20 -0400 Subject: [PATCH 37/37] remove nullsafe method on non-null --- app/Nova/Metrics/ActiveAttendanceBreakdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Nova/Metrics/ActiveAttendanceBreakdown.php b/app/Nova/Metrics/ActiveAttendanceBreakdown.php index c089303b7..5b250e407 100644 --- a/app/Nova/Metrics/ActiveAttendanceBreakdown.php +++ b/app/Nova/Metrics/ActiveAttendanceBreakdown.php @@ -57,7 +57,7 @@ public function calculate(Request $request): PartitionResult ->where('attendable_id', $resourceId) ->where( 'attendable_type', - $this->attendableType ?? $request?->model()?->getMorphClass() + $this->attendableType ?? $request->model()?->getMorphClass() ); }