diff --git a/app/Filament/Widgets/AdminWidget.php b/app/Filament/Widgets/AdminWidget.php index fa00e2c..3ebe802 100644 --- a/app/Filament/Widgets/AdminWidget.php +++ b/app/Filament/Widgets/AdminWidget.php @@ -8,6 +8,8 @@ use Filament\Widgets\StatsOverviewWidget\Card; use App\Models\User; use App\Models\Item; use App\Models\Reserveditem; +use Filament\Support\Enums\IconPosition; + class AdminWidget extends BaseWidget { @@ -17,10 +19,10 @@ class AdminWidget extends BaseWidget { return [ //Card::make(__('Total number of users'), User::count() ), - Card::make(__('Total number of games'), Item::where('type', 'game')->count() ), - Card::make(__('Total number of items'), Item::where('type', 'item')->count() ), - Card::make(__('Reservations at the moment'), Reserveditem::where('returned_date', null)->count() ), - Card::make(__('Reservations over time'), Reserveditem::withTrashed()->withTrashed()->count() ), + Stat::make(__('Total amount of games'), Item::where('type', 'game')->count() ), + Stat::make(__('Total amount of items'), Item::where('type', 'item')->count() ), + Stat::make(__('Reservations at the moment'), Reserveditem::where('returned_date', null)->count() ), + Stat::make(__('Reservations over time'), Reserveditem::withTrashed()->withTrashed()->count() ), ]; } diff --git a/app/Filament/Widgets/PopularCategoryChart.php b/app/Filament/Widgets/PopularCategoryChart.php new file mode 100644 index 0000000..61b3b8d --- /dev/null +++ b/app/Filament/Widgets/PopularCategoryChart.php @@ -0,0 +1,66 @@ + [ + 'x' => [ + 'display' => false, + ], + 'y' => [ + 'display' => false, + ], + ], + ]; + + protected function getData(): array + { + $categories = Category::where('type', 'game')->get(); + $categoryNames = []; + + foreach ($categories as $obj){ + $categoryNames[] = $obj->name; + } + + $items = Reserveditem::withTrashed()->with('item')->whereHas('item', function($query){ + return $query->where('type', 'game'); + })->get()->groupBy('item.category_id'); + + + $itemCategoriesCount = []; + + foreach ($items as $item){ + + $itemCategoriesCount[] = $item->count(); + + } + + return [ + 'datasets' => [ + [ + 'label' => __('Reservation Category'), + 'data' => $itemCategoriesCount, + 'backgroundColor' => ["#03045e","#0077b6","#00b4d8","#90e0ef","#caf0f8"], + "hoverOffset" => 4, + ], + ], + 'labels' => $categoryNames, + + ]; + } + + protected function getType(): string + { + return 'pie'; + } +} diff --git a/app/Filament/Widgets/ReservationsChart.php b/app/Filament/Widgets/ReservationsChart.php index 9e0d2c2..81824a7 100644 --- a/app/Filament/Widgets/ReservationsChart.php +++ b/app/Filament/Widgets/ReservationsChart.php @@ -10,6 +10,7 @@ use App\Models\Reserveditem; class ReservationsChart extends ChartWidget { protected static ?string $heading = "Reservations by month"; + protected static ?string $maxHeight = '300px'; protected function getData(): array diff --git a/lang/vendor/filament-panels/sv.json b/lang/vendor/filament-panels/sv.json index a4d6bb4..985c3cd 100644 --- a/lang/vendor/filament-panels/sv.json +++ b/lang/vendor/filament-panels/sv.json @@ -33,8 +33,8 @@ "Is admin": "Admin", "Password": "Lösenord", "Email verified at": "Email verifierad den", - "Total number of games": "Totalt antal spel i lager", - "Total number of items": "Totalt antal saker i lager", + "Total amount of games": "Totalt antal spel i lager", + "Total amount of items": "Totalt antal saker i lager", "Reservations at the moment": "Nuvarande reservationer", "Reservations over time": "Alla reservationer", "Phone": "Telefonnummer", @@ -42,5 +42,7 @@ "Category literature": "Kategori litteratur", "Category games": "Kategori spel", "Category items": "Kategori saker", - "Reservations by month": "Reservationer per månad" + "Reservations by month": "Reservationer per månad", + "Amount of games in inventory": "Antal spel i lager", + "Amount of items in inventory": "Antal saker i lager" } \ No newline at end of file