-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created a view for collection and added widgets
- Loading branch information
1 parent
709e21c
commit c4d7282
Showing
4 changed files
with
85 additions
and
2 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
20 changes: 20 additions & 0 deletions
20
app/Filament/Dashboard/Resources/CollectionResource/Pages/ViewCollection.php
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,20 @@ | ||
<?php | ||
|
||
namespace App\Filament\Dashboard\Resources\CollectionResource\Pages; | ||
|
||
use App\Filament\Dashboard\Resources\CollectionResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ViewRecord; | ||
use App\Filament\Dashboard\Resources\CollectionResource\Widgets\CollectionStats; | ||
|
||
class ViewCollection extends ViewRecord | ||
{ | ||
protected static string $resource = CollectionResource::class; | ||
|
||
protected function getHeaderWidgets(): array | ||
{ | ||
return [ | ||
CollectionStats::class, | ||
]; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/Filament/Dashboard/Resources/CollectionResource/Widgets/CollectionStats.php
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,52 @@ | ||
<?php | ||
|
||
namespace App\Filament\Dashboard\Resources\CollectionResource\Widgets; | ||
|
||
use Filament\Widgets\StatsOverviewWidget as BaseWidget; | ||
use Filament\Widgets\StatsOverviewWidget\Stat; | ||
use Illuminate\Support\Facades\Cache; | ||
use App\Models\Collection; | ||
|
||
class CollectionStats extends BaseWidget | ||
{ | ||
public ?Collection $record = null; | ||
|
||
protected function getStats(): array | ||
{ | ||
return [ | ||
// Stat::make('Entries', $this->record->entries->count()) | ||
// ->description('Total count') | ||
// ->color('primary'), | ||
// Stat::make('Total Entries', Cache::rememberForever('stats.collections', function () { | ||
// return Collection::count(); | ||
// })), | ||
Stat::make('Total Entries', Cache::rememberForever('stats.collections'.$this->record->id.'entries.count', function () { | ||
return $this->record->entries->count(); | ||
})), | ||
Stat::make('Total Molecules', Cache::rememberForever('stats.collections'.$this->record->id.'molecules.count', function () { | ||
return $this->record->molecules->count(); | ||
})), | ||
Stat::make('Total Citations', Cache::rememberForever('stats.collections'.$this->record->id.'citations.count', function () { | ||
return $this->record->citations->count(); | ||
})), | ||
Stat::make('Total Organisms', Cache::rememberForever('stats.collections'.$this->record->id.'organisms.count', function () { | ||
// refactor the below with eloquent relations if possible | ||
$molecules = $this->record->molecules; | ||
$count = 0; | ||
foreach($molecules as $molecule) { | ||
$count += $molecule->organisms()->count(); | ||
} | ||
return $count; | ||
})), | ||
Stat::make('Total Geo Locations', Cache::rememberForever('stats.collections'.$this->record->id.'geo_locations.count', function () { | ||
// refactor the below with eloquent relations if possible | ||
$molecules = $this->record->molecules; | ||
$count = 0; | ||
foreach($molecules as $molecule) { | ||
$count += $molecule->geoLocations()->count(); | ||
} | ||
return $count; | ||
})), | ||
]; | ||
} | ||
} |
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