Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RSVPs and Attendance cards to main dashboards #4519

Merged
merged 42 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f090dd4
Bug Squashing: Fixed manual user creation with default Has Ever Logge…
jvogt23 Jan 28, 2024
ef4d218
Made RsvpSourceBreakdown match TravelAuthorityRequestReceivedForTrave…
jvogt23 Mar 24, 2024
3fa5363
Added cards for RSVPs and Attendance of events to main dashboard
jvogt23 Apr 1, 2024
3573380
StyleCI appeasement
jvogt23 Apr 1, 2024
a666f1b
StyleCI Appeasement
jvogt23 Apr 1, 2024
583c5f8
Bug Squashing: Fixed manual user creation with default Has Ever Logge…
jvogt23 Jan 28, 2024
621fb94
Made RsvpSourceBreakdown match TravelAuthorityRequestReceivedForTrave…
jvogt23 Mar 24, 2024
fd5c93c
Added cards for RSVPs and Attendance of events to main dashboard
jvogt23 Apr 1, 2024
445e51a
StyleCI appeasement
jvogt23 Apr 1, 2024
6ae5d69
StyleCI Appeasement
jvogt23 Apr 1, 2024
1be0011
Merge branch 'jvogt/rsvp' of https://github.com/RoboJackets/apiary in…
jvogt23 Apr 3, 2024
a05f688
FixStyle after rebase
jvogt23 Apr 3, 2024
9443816
Style fixes
jvogt23 Apr 3, 2024
38c2d7c
Linter appeasement
jvogt23 Apr 5, 2024
42b6ad0
Linter appeasement
jvogt23 Apr 5, 2024
56722bb
Linter appeasement
jvogt23 Apr 5, 2024
3710ead
Linter appeasement
jvogt23 Apr 5, 2024
17220bd
Linter appeasement
jvogt23 Apr 5, 2024
d84022d
Linter appeasement
jvogt23 Apr 5, 2024
9dfc6b3
Merge branch 'main' into jvogt/rsvp
jvogt23 Apr 5, 2024
c356f77
Update app/Nova/Dashboards/Main.php
jvogt23 Apr 14, 2024
962165e
Update app/Nova/Metrics/ActiveAttendanceBreakdown.php
jvogt23 Apr 14, 2024
f56e332
Update app/Nova/User.php
jvogt23 Apr 14, 2024
aca2593
Update app/Nova/Metrics/ActiveAttendanceBreakdown.php
jvogt23 Apr 14, 2024
5c61d43
Remove unnecessary variable
jvogt23 Apr 14, 2024
fb6054c
merge remote into local
jvogt23 Apr 14, 2024
4a33a8b
Remove debug attributes
jvogt23 Apr 14, 2024
fed518a
Changed to constructor property promotion
jvogt23 Apr 14, 2024
083fe02
Update app/Nova/Metrics/ActiveAttendanceBreakdown.php
jvogt23 Apr 14, 2024
e291571
Update app/Nova/Metrics/ActiveAttendanceBreakdown.php
jvogt23 Apr 14, 2024
4e41739
Made attributes nullable, defaulting to null
jvogt23 Apr 14, 2024
a0215de
resolved requested changes, needs debugging
jvogt23 Apr 14, 2024
51c118c
Fixed most of the nitpicks - The remaining ones need troubleshooting
jvogt23 Aug 14, 2024
819e904
fix merge conflicts
jvogt23 Aug 14, 2024
6ec2cff
Fix glitch caused by unmerged change
jvogt23 Aug 14, 2024
8bfd48e
Resolved last few conversations, now to appease the linter
jvogt23 Aug 17, 2024
b0bc8f4
Pint style fixes
jvogt23 Aug 17, 2024
1d503c0
phpcs cleanup
jvogt23 Aug 17, 2024
5f41ff9
Merge branch 'main' into jvogt/rsvp
jvogt23 Aug 17, 2024
fd55c86
styleci fix
jvogt23 Aug 17, 2024
191d5c2
phpcs fix
jvogt23 Aug 17, 2024
98b20bb
remove nullsafe method on non-null
jvogt23 Aug 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions app/Nova/Dashboards/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -108,6 +110,32 @@ 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 ($event->attendance()->count() > 0) {
$should_include = true;
}
if ($event->end_time === null) {
if ($event->start_time === null || $event->start_time < Carbon::now()) {
$should_include = false;
}
} elseif ($event->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;
}

Expand Down Expand Up @@ -137,6 +165,28 @@ 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, $id, 'event'))->canSee(
static fn (Request $request): bool => $request->user()->can('read-attendance')
),
];
}

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')
),
];
}

return $cards;
}
}
36 changes: 21 additions & 15 deletions app/Nova/Metrics/ActiveAttendanceBreakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Nova\Metrics;

use App\Models\Attendance;
use App\Models\Event;
use App\Models\User;
use Illuminate\Http\Request;
use Laravel\Nova\Metrics\Partition;
Expand All @@ -17,30 +18,31 @@ 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 !== null) {
$ret .= ' for '.Event::where('id', $this->resourceId)->sole()->name;
}

/**
* Whether to show based on all attendance records or only those from the last two weeks.
*
* @var bool
*/
protected $showAllTime = false;
return $ret;
}

/**
* Create a new ActiveAttendanceBreakdown metric.
*/
public function __construct(bool $showAllTime = false)
{
public function __construct(
public bool $showAllTime = false,
public ?int $resourceId = null,
public ?string $attendableType = null
) {
parent::__construct();
$this->showAllTime = $showAllTime;
}

/**
* Calculate the value of the metric.
*/
public function calculate(Request $request): PartitionResult
{
$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(
Expand All @@ -50,10 +52,13 @@ public function calculate(Request $request): PartitionResult
'active'
);

if (isset($request->resourceId)) {
if ($resourceId !== null) {
$query = $query
->where('attendable_id', $request->resourceId)
->where('attendable_type', $request->model()->getMorphClass());
->where('attendable_id', $resourceId)
->where(
'attendable_type',
$this->attendableType ?? $request->model()?->getMorphClass()
);
}

if (! $this->showAllTime) {
Expand Down Expand Up @@ -81,6 +86,7 @@ public function calculate(Request $request): PartitionResult
*/
public function uriKey(): string
{
return 'active-attendance-breakdown';
return $this->resourceId === null ? 'active-attendance-breakdown' :
'../'.$this->attendableType.'s/'.$this->resourceId.'/metrics/active-attendance-breakdown';
}
}
26 changes: 19 additions & 7 deletions app/Nova/Metrics/RsvpSourceBreakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,40 @@

namespace App\Nova\Metrics;

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;

class RsvpSourceBreakdown extends Partition
{
/**
* The displayable name of the metric.
*
* @var string
*/
public $name = 'RSVP Sources';
public function name(): string
{
return $this->resourceId === null ? 'RSVP Sources' : 'RSVP Sources for '.Event::where(
'id',
$this->resourceId
)->sole()->name;
}

public function __construct(public ?int $resourceId = null)
{
parent::__construct();
}

/**
* Calculate the value of the metric.
*/
public function calculate(Request $request): PartitionResult
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',
Expand Down Expand Up @@ -53,6 +65,6 @@ static function (Builder $query): void {
*/
public function uriKey(): string
{
return 'rsvp-source-breakdown';
return $this->resourceId === null ? 'rsvp-source-breakdown' : 'rsvp-source-breakdown-'.$this->resourceId;
}
}
5 changes: 5 additions & 0 deletions app/Nova/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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;
Expand Down Expand Up @@ -111,6 +112,10 @@ class User extends Resource
public function fields(NovaRequest $request): array
{
return [
Hidden::make('Has Ever Logged In')
->showOnCreating()
->default(static fn (Request $r): bool => false),

Text::make('Username', 'uid')
->sortable()
->rules('required', 'max:127')
Expand Down