Skip to content

Commit

Permalink
feat: created view page for organism and added widgets
Browse files Browse the repository at this point in the history
sriramkanakam87 committed May 2, 2024
1 parent a5bc781 commit 7562377
Showing 3 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/Filament/Dashboard/Resources/OrganismResource.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use App\Filament\Dashboard\Resources\OrganismResource\Widgets\OrganismStats;

class OrganismResource extends Resource
{
@@ -53,6 +54,7 @@ public static function table(Table $table): Table
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
@@ -75,6 +77,14 @@ public static function getPages(): array
'index' => Pages\ListOrganisms::route('/'),
'create' => Pages\CreateOrganism::route('/create'),
'edit' => Pages\EditOrganism::route('/{record}/edit'),
'view' => Pages\ViewOrganism::route('/{record}'),
];
}

public static function getWidgets(): array
{
return [
OrganismStats::class,
];
}
}
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,
];
}
}
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;
})),
];
}
}

0 comments on commit 7562377

Please sign in to comment.