-
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 view page for organism and added widgets
1 parent
a5bc781
commit 7562377
Showing
3 changed files
with
61 additions
and
0 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/OrganismResource/Pages/ViewOrganism.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\OrganismResource\Pages; | ||
|
||
use App\Filament\Dashboard\Resources\OrganismResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ViewRecord; | ||
use App\Filament\Dashboard\Resources\OrganismResource\Widgets\OrganismStats; | ||
|
||
class ViewOrganism extends ViewRecord | ||
{ | ||
protected static string $resource = OrganismResource::class; | ||
|
||
protected function getHeaderWidgets(): array | ||
{ | ||
return [ | ||
OrganismStats::class, | ||
]; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/Filament/Dashboard/Resources/OrganismResource/Widgets/OrganismStats.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,31 @@ | ||
<?php | ||
|
||
namespace App\Filament\Dashboard\Resources\OrganismResource\Widgets; | ||
|
||
use Filament\Widgets\StatsOverviewWidget as BaseWidget; | ||
use Filament\Widgets\StatsOverviewWidget\Stat; | ||
use App\Models\Organism; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
class OrganismStats extends BaseWidget | ||
{ | ||
public ?Organism $record = null; | ||
|
||
protected function getStats(): array | ||
{ | ||
return [ | ||
Stat::make('Total Molecules', Cache::rememberForever('stats.organisms'.$this->record->id.'molecules.count', function () { | ||
return $this->record->molecules->count(); | ||
})), | ||
Stat::make('Total Geo Locations', Cache::rememberForever('stats.organisms'.$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; | ||
})), | ||
]; | ||
} | ||
} |