From 6130df4eea4e3cedb39021eaafc3b79626706e72 Mon Sep 17 00:00:00 2001 From: Sagar Date: Fri, 10 May 2024 17:19:22 +0200 Subject: [PATCH 1/7] feat: created molecule relation manger for collection resource, added functionality for processing molecules in entries table, and added forget the collection molecules count at the end of import --- app/Console/Commands/ImportEntries.php | 2 + .../Resources/CollectionResource.php | 9 +++- .../EntriesRelationManager.php | 9 ++++ .../MoleculesRelationManager.php | 50 +++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php diff --git a/app/Console/Commands/ImportEntries.php b/app/Console/Commands/ImportEntries.php index f3e85b81..9906d9b7 100644 --- a/app/Console/Commands/ImportEntries.php +++ b/app/Console/Commands/ImportEntries.php @@ -8,6 +8,7 @@ use Illuminate\Bus\Batch; use Illuminate\Console\Command; use Illuminate\Support\Facades\Bus; +use Illuminate\Support\Facades\Cache; class ImportEntries extends Command { @@ -55,6 +56,7 @@ public function handle() $collection->jobs_status = 'INCURATION'; $collection->job_info = ''; $collection->save(); + Cache::forget('stats.collections'.$collection->id.'molecules.count'); })->name('Import Entries '.$collection->id) ->allowFailures(false) ->onConnection('redis') diff --git a/app/Filament/Dashboard/Resources/CollectionResource.php b/app/Filament/Dashboard/Resources/CollectionResource.php index bbe9848b..a8548c39 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource.php +++ b/app/Filament/Dashboard/Resources/CollectionResource.php @@ -5,6 +5,7 @@ use App\Filament\Dashboard\Resources\CollectionResource\Pages; use App\Filament\Dashboard\Resources\CollectionResource\RelationManagers\CitationsRelationManager; use App\Filament\Dashboard\Resources\CollectionResource\RelationManagers\EntriesRelationManager; +use App\Filament\Dashboard\Resources\CollectionResource\RelationManagers\MoleculesRelationManager; use App\Filament\Dashboard\Resources\CollectionResource\Widgets\CollectionStats; use App\Livewire\ShowJobStatus; use App\Models\Collection; @@ -21,6 +22,7 @@ use Filament\Tables\Table; use Illuminate\Support\Str; use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager; +use Illuminate\Database\Eloquent\Model; class CollectionResource extends Resource { @@ -91,11 +93,16 @@ public static function table(Table $table): Table public static function getRelations(): array { - return [ + // $record = static::getOwner(); + // dd(static::getOwner()); + // dd(static::$model::molecules()->get()); + $arr = [ EntriesRelationManager::class, CitationsRelationManager::class, AuditsRelationManager::class, + MoleculesRelationManager::class, ]; + return $arr; } public static function getPages(): array diff --git a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php index 53831fbe..5b49073f 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php @@ -15,6 +15,8 @@ use Filament\Tables\Columns\ImageColumn; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; +use Filament\Tables\Actions\Action; +use Illuminate\Support\Facades\Artisan; class EntriesRelationManager extends RelationManager { @@ -157,6 +159,13 @@ public function table(Table $table): Table ->options([ 'collection_id' => $this->ownerRecord->id, ]), + Action::make('process') + ->hidden(function () { + return $this->ownerRecord->entries()->where('status', 'SUBMITTED')->count() < 1; + }) + ->action(function () { + Artisan::call('entries:process'); + }), // Tables\Actions\CreateAction::make(), ]) ->actions([ diff --git a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php new file mode 100644 index 00000000..ccd0e21a --- /dev/null +++ b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php @@ -0,0 +1,50 @@ +schema([ + Forms\Components\TextInput::make('canonical_smiles') + ->required() + ->maxLength(255), + ]); + } + + public function table(Table $table): Table + { + return $table + ->recordTitleAttribute('canonical_smiles') + ->columns([ + Tables\Columns\TextColumn::make('canonical_smiles'), + ]) + ->filters([ + // + ]) + ->headerActions([ + Tables\Actions\CreateAction::make(), + ]) + ->actions([ + Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } +} From 98d3ba4f930faaac44a132f27585c74ba6ef296d Mon Sep 17 00:00:00 2001 From: Sagar Date: Fri, 10 May 2024 17:21:18 +0200 Subject: [PATCH 2/7] feat: added button for publishing the collection. --- .../RelationManagers/EntriesRelationManager.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php index 5b49073f..e779f96e 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php @@ -166,6 +166,16 @@ public function table(Table $table): Table ->action(function () { Artisan::call('entries:process'); }), + Action::make('publish') + ->hidden(function () { + return $this->ownerRecord->molecules()->where('status', 'DRAFT')->count() < 1; + }) + ->action(function () { + $this->ownerRecord->status = 'PUBLISHED'; + $this->ownerRecord->is_public = true; + $this->ownerRecord->molecules()->where('status', 'DRAFT')->update(['status' => 'APPROVED']); + $this->ownerRecord->save(); + }), // Tables\Actions\CreateAction::make(), ]) ->actions([ From d825bc30b95b4715119d528a8938a7933f281e1d Mon Sep 17 00:00:00 2001 From: Sagar Date: Fri, 10 May 2024 18:03:46 +0200 Subject: [PATCH 3/7] feat: scheduled a refresh of cache for dashboard widgets --- app/Console/Commands/DashWidgetsRefresh.php | 85 +++++++++++++++++++++ app/Console/Kernel.php | 1 + 2 files changed, 86 insertions(+) create mode 100644 app/Console/Commands/DashWidgetsRefresh.php diff --git a/app/Console/Commands/DashWidgetsRefresh.php b/app/Console/Commands/DashWidgetsRefresh.php new file mode 100644 index 00000000..210c06b7 --- /dev/null +++ b/app/Console/Commands/DashWidgetsRefresh.php @@ -0,0 +1,85 @@ +count(); + }); + Cache::rememberForever('stats.molecules.stereo', function () { + return Molecule::where([ + ['has_stereo', true], + ])->count(); + }); + Cache::rememberForever('stats.molecules.parent', function () { + return Molecule::where([ + ['has_stereo', false], + ['is_parent', true], + ])->count(); + }); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 1c34480c..e341c0ba 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -15,6 +15,7 @@ protected function schedule(Schedule $schedule): void // $schedule->command('inspire')->hourly(); $schedule->command('entries:process')->everyMinute()->withoutOverlapping(); $schedule->command('entries:import')->everyMinute()->withoutOverlapping(); + $schedule->command('app:dash-widgets-refresh')->everyFifteenMinutes()->withoutOverlapping(); } /** From c6a1489c729b6577931e6fc78f585ca1463aeb85 Mon Sep 17 00:00:00 2001 From: Sagar Date: Tue, 14 May 2024 09:30:00 +0200 Subject: [PATCH 4/7] chore: ran pint --- app/Console/Commands/DashWidgetsRefresh.php | 6 +++--- app/Filament/Dashboard/Resources/CollectionResource.php | 2 +- .../RelationManagers/EntriesRelationManager.php | 2 +- .../RelationManagers/MoleculesRelationManager.php | 2 -- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/DashWidgetsRefresh.php b/app/Console/Commands/DashWidgetsRefresh.php index 210c06b7..d21a4e62 100644 --- a/app/Console/Commands/DashWidgetsRefresh.php +++ b/app/Console/Commands/DashWidgetsRefresh.php @@ -2,14 +2,14 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; -use Illuminate\Support\Facades\Cache; use App\Models\Citation; use App\Models\Collection; use App\Models\GeoLocation; +use App\Models\Molecule; use App\Models\Organism; use App\Models\Report; -use App\Models\Molecule; +use Illuminate\Console\Command; +use Illuminate\Support\Facades\Cache; class DashWidgetsRefresh extends Command { diff --git a/app/Filament/Dashboard/Resources/CollectionResource.php b/app/Filament/Dashboard/Resources/CollectionResource.php index a8548c39..e013be93 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource.php +++ b/app/Filament/Dashboard/Resources/CollectionResource.php @@ -22,7 +22,6 @@ use Filament\Tables\Table; use Illuminate\Support\Str; use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager; -use Illuminate\Database\Eloquent\Model; class CollectionResource extends Resource { @@ -102,6 +101,7 @@ public static function getRelations(): array AuditsRelationManager::class, MoleculesRelationManager::class, ]; + return $arr; } diff --git a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php index e779f96e..4e57a22d 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php @@ -11,11 +11,11 @@ use Filament\Infolists\Infolist; use Filament\Resources\RelationManagers\RelationManager; use Filament\Tables; +use Filament\Tables\Actions\Action; use Filament\Tables\Actions\ImportAction; use Filament\Tables\Columns\ImageColumn; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; -use Filament\Tables\Actions\Action; use Illuminate\Support\Facades\Artisan; class EntriesRelationManager extends RelationManager diff --git a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php index ccd0e21a..9ec3fd20 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php @@ -7,8 +7,6 @@ use Filament\Resources\RelationManagers\RelationManager; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class MoleculesRelationManager extends RelationManager { From ceb3a5afeee65b2c17510fda0e32d852a359a6c0 Mon Sep 17 00:00:00 2001 From: Sagar Date: Tue, 14 May 2024 09:30:26 +0200 Subject: [PATCH 5/7] chore: ran pint --- app/Filament/Dashboard/Resources/CollectionResource.php | 2 +- .../RelationManagers/EntriesRelationManager.php | 2 +- .../RelationManagers/MoleculesRelationManager.php | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Filament/Dashboard/Resources/CollectionResource.php b/app/Filament/Dashboard/Resources/CollectionResource.php index a8548c39..e013be93 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource.php +++ b/app/Filament/Dashboard/Resources/CollectionResource.php @@ -22,7 +22,6 @@ use Filament\Tables\Table; use Illuminate\Support\Str; use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager; -use Illuminate\Database\Eloquent\Model; class CollectionResource extends Resource { @@ -102,6 +101,7 @@ public static function getRelations(): array AuditsRelationManager::class, MoleculesRelationManager::class, ]; + return $arr; } diff --git a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php index e779f96e..4e57a22d 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php @@ -11,11 +11,11 @@ use Filament\Infolists\Infolist; use Filament\Resources\RelationManagers\RelationManager; use Filament\Tables; +use Filament\Tables\Actions\Action; use Filament\Tables\Actions\ImportAction; use Filament\Tables\Columns\ImageColumn; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; -use Filament\Tables\Actions\Action; use Illuminate\Support\Facades\Artisan; class EntriesRelationManager extends RelationManager diff --git a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php index ccd0e21a..9ec3fd20 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php @@ -7,8 +7,6 @@ use Filament\Resources\RelationManagers\RelationManager; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class MoleculesRelationManager extends RelationManager { From 3765492654bbefcdf11958ca3252470224c8ad7d Mon Sep 17 00:00:00 2001 From: Sagar Date: Tue, 14 May 2024 09:30:55 +0200 Subject: [PATCH 6/7] chore: ran pint --- app/Filament/Dashboard/Resources/CollectionResource.php | 2 +- .../RelationManagers/EntriesRelationManager.php | 2 +- .../RelationManagers/MoleculesRelationManager.php | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Filament/Dashboard/Resources/CollectionResource.php b/app/Filament/Dashboard/Resources/CollectionResource.php index a8548c39..e013be93 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource.php +++ b/app/Filament/Dashboard/Resources/CollectionResource.php @@ -22,7 +22,6 @@ use Filament\Tables\Table; use Illuminate\Support\Str; use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager; -use Illuminate\Database\Eloquent\Model; class CollectionResource extends Resource { @@ -102,6 +101,7 @@ public static function getRelations(): array AuditsRelationManager::class, MoleculesRelationManager::class, ]; + return $arr; } diff --git a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php index 5b49073f..57a22039 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/EntriesRelationManager.php @@ -11,11 +11,11 @@ use Filament\Infolists\Infolist; use Filament\Resources\RelationManagers\RelationManager; use Filament\Tables; +use Filament\Tables\Actions\Action; use Filament\Tables\Actions\ImportAction; use Filament\Tables\Columns\ImageColumn; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; -use Filament\Tables\Actions\Action; use Illuminate\Support\Facades\Artisan; class EntriesRelationManager extends RelationManager diff --git a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php index ccd0e21a..9ec3fd20 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/RelationManagers/MoleculesRelationManager.php @@ -7,8 +7,6 @@ use Filament\Resources\RelationManagers\RelationManager; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class MoleculesRelationManager extends RelationManager { From e14219b2451bc9b15a8cf879ddf76f4ec4a53599 Mon Sep 17 00:00:00 2001 From: Sagar Date: Tue, 14 May 2024 13:17:14 +0200 Subject: [PATCH 7/7] feat: added functionality to display the status of the collection --- app/Filament/Dashboard/Resources/CollectionResource.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Filament/Dashboard/Resources/CollectionResource.php b/app/Filament/Dashboard/Resources/CollectionResource.php index e013be93..a745e0ee 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource.php +++ b/app/Filament/Dashboard/Resources/CollectionResource.php @@ -75,6 +75,15 @@ public static function table(Table $table): Table return $table ->columns([ Tables\Columns\TextColumn::make('title')->wrap(), + Tables\Columns\TextColumn::make('status') + ->badge() + ->color(fn (string $state): string => match ($state) { + 'DRAFT' => 'info', + 'REVIEW' => 'warning', + 'EMBARGO' => 'warning', + 'PUBLISHED' => 'success', + 'REJECTED' => 'danger', + }), ]) ->filters([ //