Skip to content

Commit

Permalink
fix(admin): table charts and logout route
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenrikur committed Feb 22, 2024
1 parent 3da8b04 commit d4cdcae
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
9 changes: 4 additions & 5 deletions app/Filament/Widgets/AbstractApplicationTablesChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function getType(): string
return 'pie';
}

abstract protected function retrieveData(): \Illuminate\Support\Collection;
abstract protected function retrieveData(): array;

protected function getData(): array
{
Expand All @@ -26,19 +26,18 @@ protected function getData(): array
'datasets' => [
[
'label' => 'Total Tables',
'data' => $data->pluck('count')->all(),
'data' => array_values($data),
'backgroundColor' => [
'rgb(200, 180, 90)',
'rgb(250, 80, 50)',
'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(),
'labels' => array_keys($data),
];
}

Expand Down
10 changes: 8 additions & 2 deletions app/Filament/Widgets/ApplicationTablesAssignedChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
namespace App\Filament\Widgets;

use App\Models\Application;
use App\Models\TableType;
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
protected function retrieveData(): array
{
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());
return Cache::remember('dd-admin-application-tables-assigned', 60, function(): array {
$tableTypeCount = Application::query()->toBase()->join('table_types', 'table_type_assigned', '=', 'table_types.id')->select(DB::raw('table_types.id as id, COUNT(*) as count'))->where('type', '=', 'dealer')->whereNull('canceled_at')->whereNull('waiting_at')->groupBy('table_types.id')->get()->pluck('count', 'id');
return TableType::all()->mapWithKeys(function(TableType $tableType) use ($tableTypeCount) {
return [ $tableType->name => $tableTypeCount[$tableType->id] ?? 0];
})->toArray();
});
}
}
11 changes: 9 additions & 2 deletions app/Filament/Widgets/ApplicationTablesRequestedChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
namespace App\Filament\Widgets;

use App\Models\Application;
use App\Models\TableType;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class ApplicationTablesRequestedChart extends AbstractApplicationTablesChart
{
protected static ?string $heading = 'Total Tables Requested (active)';

protected function retrieveData(): \Illuminate\Support\Collection
protected function retrieveData(): array
{
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());
return Cache::remember('dd-admin-application-tables-requested', 60, function(): array {
$tableTypeCount = Application::query()->toBase()->join('table_types', 'table_type_requested', '=', 'table_types.id')->select(DB::raw('table_types.id as id, COUNT(*) as count'))->where('type', '=', 'dealer')->whereNull('canceled_at')->whereNull('waiting_at')->groupBy('table_types.id')->get()->pluck('count', 'id');
return TableType::all()->mapWithKeys(function(TableType $tableType) use ($tableTypeCount) {
return [ $tableType->name => $tableTypeCount[$tableType->id] ?? 0];
})->toArray();
});
}
}
2 changes: 1 addition & 1 deletion app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function panel(Panel $panel): Panel
->id('admin')
->path('admin')
->userMenuItems([
'logout' => MenuItem::make()->label('Log out')->url(fn () => route('auth.frontchannel-logout')),
'logout' => MenuItem::make()->label('Log out')->url(fn () => route('auth.frontchannel-logout-post')),
])
->colors([
'primary' => Color::Amber,
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
});

Route::get('/auth/frontchannel-logout', \App\Http\Controllers\Auth\FrontChannelLogoutController::class)->name('auth.frontchannel-logout');
Route::post('/auth/frontchannel-logout', \App\Http\Controllers\Auth\FrontChannelLogoutController::class)->name('auth.frontchannel-logout');
Route::post('/auth/frontchannel-logout', \App\Http\Controllers\Auth\FrontChannelLogoutController::class)->name('auth.frontchannel-logout-post');

Route::get('/', function () {
return \Illuminate\Support\Facades\Redirect::route('dashboard');
Expand Down

0 comments on commit d4cdcae

Please sign in to comment.