Skip to content

Commit

Permalink
hackgreenville-com-433 - Add events widget to the dashboard
Browse files Browse the repository at this point in the history
resolves hackgvl#433
  • Loading branch information
zach2825 committed Nov 5, 2024
1 parent f89921f commit 5d3b386
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/Filament/Resources/EventResource/Widgets/TotalActiveEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Filament\Resources\EventResource\Widgets;

use App\Models\Event;
use Filament\Widgets\ChartWidget;

class TotalActiveEvents extends ChartWidget
{
protected static ?string $heading = 'Chart';

protected static ?string $description = 'All Events';

protected static ?string $maxHeight = '250px';

protected function getData(): array
{
$data = Event::query()
->published()
->get()
->groupBy('status')
->map(fn ($events) => $events->count())
->toArray();

return [
'labels' => array_keys($data),
'datasets' => [
[
'label' => 'Events',
'data' => array_values($data),
'backgroundColor' => [
'#FF6384',
'#36A2EB',
'#FFCE56',
],
],
],
];
}

protected function getType(): string
{
return 'pie';
}
}

0 comments on commit 5d3b386

Please sign in to comment.