-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin): improve UX and implement dashboard (#62)
* feat(admin): improve login/logout * feat(admin): show user avatar * feat(ui): add frontdesk and admin links to dashboard * feat(admin): add statistics widgets to dashboard * feat(admin): use caching for stats * feat(admin): configure fixed widgets instead of discovery * feat(admin): requested/assigned tables widget * chore: add display name utility to ApplicationStatus * feat(admin): exclude waiting from active on dashboard * feat(admin): add info widget to dashboard * feat(admin): add registration status chart to dashboard * fix(admin): properly cache regsys data
- Loading branch information
Showing
13 changed files
with
361 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Models\Application; | ||
use Filament\Widgets\ChartWidget; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
abstract class AbstractApplicationTablesChart extends ChartWidget | ||
{ | ||
protected static ?string $heading = 'Total Tables (active)'; | ||
protected static ?string $maxHeight = '200px'; | ||
|
||
protected function getType(): string | ||
{ | ||
return 'pie'; | ||
} | ||
|
||
abstract protected function retrieveData(): \Illuminate\Support\Collection; | ||
|
||
protected function getData(): array | ||
{ | ||
$data = $this->retrieveData(); | ||
return [ | ||
'datasets' => [ | ||
[ | ||
'label' => 'Total Tables', | ||
'data' => $data->pluck('count')->all(), | ||
'backgroundColor' => [ | ||
'rgb(200, 180, 90)', | ||
'rgb(0, 200, 255)', | ||
'rgb(255, 200, 80)', | ||
'rgb(250, 100, 200)', | ||
'rgb(150, 100, 255)', | ||
'rgb(0, 180, 0)', | ||
'rgb(250, 80, 50)', | ||
], | ||
], | ||
], | ||
'labels' => $data->pluck('type')->all(), | ||
]; | ||
} | ||
|
||
protected function getOptions(): array | ||
{ | ||
return [ | ||
'scales' => [ | ||
'x' => [ | ||
'display' => false, | ||
], | ||
'y' => [ | ||
'display' => false, | ||
], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Models\Application; | ||
use Filament\Widgets\StatsOverviewWidget as BaseWidget; | ||
use Filament\Widgets\StatsOverviewWidget\Stat; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class ApplicationStats extends BaseWidget | ||
{ | ||
protected function getStats(): array | ||
{ | ||
$data = Cache::remember('dd-admin-application-stats', 60, fn() => Application::query()->toBase()->select(DB::raw('type, COUNT(*) as count'))->whereNull('canceled_at')->whereNull('waiting_at')->groupBy('type')->get()); | ||
return [ | ||
Stat::make('Total Applications (active)', fn() => $data->sum('count')), | ||
Stat::make('Total Dealers (active)', fn() => $data->firstWhere('type', 'dealer')?->count ?? 0), | ||
Stat::make('Total Shares (active)', fn() => $data->firstWhere('type', 'share')?->count ?? 0), | ||
Stat::make('Total Assistants (active)', fn() => $data->firstWhere('type', 'assistant')?->count ?? 0), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Enums\ApplicationStatus; | ||
use App\Models\Application; | ||
use Filament\Widgets\ChartWidget; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
class ApplicationStatusChart extends ChartWidget | ||
{ | ||
protected static ?string $heading = 'Applications by Status'; | ||
protected static ?string $maxHeight = '200px'; | ||
|
||
protected function getType(): string | ||
{ | ||
return 'pie'; | ||
} | ||
|
||
protected function getData(): array | ||
{ | ||
$status = Cache::remember('dd-admin-application-status', 60, fn () => [ | ||
ApplicationStatus::Canceled->displayName() => ApplicationStatus::Canceled->orWhere(Application::query())->count(), | ||
ApplicationStatus::Open->displayName() => ApplicationStatus::Open->orWhere(Application::query())->count(), | ||
ApplicationStatus::Waiting->displayName() => ApplicationStatus::Waiting->orWhere(Application::query())->count(), | ||
ApplicationStatus::TableAssigned->displayName() => ApplicationStatus::TableAssigned->orWhere(Application::query())->count(), | ||
ApplicationStatus::TableOffered->displayName() => ApplicationStatus::TableOffered->orWhere(Application::query())->count(), | ||
ApplicationStatus::TableAccepted->displayName() => ApplicationStatus::TableAccepted->orWhere(Application::query())->count(), | ||
ApplicationStatus::CheckedIn->displayName() => ApplicationStatus::CheckedIn->orWhere(Application::query())->count(), | ||
ApplicationStatus::CheckedOut->displayName() => ApplicationStatus::CheckedOut->orWhere(Application::query())->count(), | ||
]); | ||
|
||
return [ | ||
'datasets' => [ | ||
[ | ||
'label' => 'Total Applications', | ||
'data' => array_values($status), | ||
'backgroundColor' => [ | ||
'rgb(250, 80, 80)', | ||
'rgb(0, 200, 255)', | ||
'rgb(255, 200, 80)', | ||
'rgb(250, 100, 200)', | ||
'rgb(150, 100, 255)', | ||
'rgb(100, 255, 100)', | ||
'rgb(0, 180, 0)', | ||
'rgb(120, 120, 120)', | ||
], | ||
], | ||
], | ||
'labels' => array_keys($status), | ||
]; | ||
} | ||
|
||
protected function getOptions(): array | ||
{ | ||
return [ | ||
'scales' => [ | ||
'x' => [ | ||
'display' => false, | ||
], | ||
'y' => [ | ||
'display' => false, | ||
], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Models\Application; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class ApplicationTablesAssignedChart extends AbstractApplicationTablesChart | ||
{ | ||
protected static ?string $heading = 'Total Tables Assigned (active)'; | ||
|
||
protected function retrieveData(): \Illuminate\Support\Collection | ||
{ | ||
return Cache::remember('dd-admin-application-tables-assigned', 60, fn() => Application::query()->toBase()->join('table_types', 'table_type_assigned', '=', 'table_types.id')->select(DB::raw('COUNT(*) as count, name as type'))->where('type', '=', 'dealer')->whereNull('canceled_at')->whereNull('waiting_at')->groupBy('name')->get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Models\Application; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class ApplicationTablesRequestedChart extends AbstractApplicationTablesChart | ||
{ | ||
protected static ?string $heading = 'Total Tables Requested (active)'; | ||
|
||
protected function retrieveData(): \Illuminate\Support\Collection | ||
{ | ||
return Cache::remember('dd-admin-application-tables-requested', 60, fn() => Application::query()->toBase()->join('table_types', 'table_type_requested', '=', 'table_types.id')->select(DB::raw('COUNT(*) as count, name as type'))->where('type', '=', 'dealer')->whereNull('canceled_at')->whereNull('waiting_at')->groupBy('name')->get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use Filament\Widgets\Widget; | ||
|
||
class DashboardInfo extends Widget | ||
{ | ||
protected static string $view = 'filament.widgets.dashboard-info'; | ||
protected int | string | array $columnSpan = 'full'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Http\Controllers\Client\RegSysClientController; | ||
use App\Models\Application; | ||
use Filament\Widgets\ChartWidget; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class RegistrationStatusChart extends ChartWidget | ||
{ | ||
protected static ?string $heading = 'Registration Status (active; refresh: 10 minutes)'; | ||
protected static ?string $pollingInterval = '3600s'; | ||
protected static ?string $maxHeight = '200px'; | ||
|
||
protected function getType(): string | ||
{ | ||
return 'pie'; | ||
} | ||
|
||
protected function getData(): array | ||
{ | ||
$data = Cache::remember('dd-admin-application-totals', 10 * 60, function (): array { | ||
$registrations = RegSysClientController::getAllRegs('id'); | ||
return Application::with('user')->whereNull('canceled_at')->whereNull('waiting_at')->get() | ||
->map(fn (Application $application): string => $registrations[$application->user_id]['status'] ?? 'unknown') | ||
->reduce(function (array $statusCount, string $status) { | ||
$statusCount[$status] += 1; | ||
return $statusCount; | ||
}, [ | ||
'new' => 0, | ||
'approved' => 0, | ||
'partially paid' => 0, | ||
'paid' => 0, | ||
'checked in' => 0, | ||
'unknown' => 0, | ||
'cancelled' => 0, | ||
]); | ||
}); | ||
return [ | ||
'datasets' => [ | ||
[ | ||
'label' => 'Total Applications', | ||
'data' => array_values($data), | ||
'backgroundColor' => [ | ||
'rgb(255, 200, 80)', | ||
'rgb(0, 200, 255)', | ||
'rgb(250, 100, 200)', | ||
'rgb(100, 255, 100)', | ||
'rgb(0, 180, 0)', | ||
'rgb(120, 120, 120)', | ||
'rgb(250, 80, 80)', | ||
], | ||
], | ||
], | ||
'labels' => array_keys($data), | ||
]; | ||
} | ||
|
||
protected function getOptions(): array | ||
{ | ||
return [ | ||
'scales' => [ | ||
'x' => [ | ||
'display' => false, | ||
], | ||
'y' => [ | ||
'display' => false, | ||
], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.