Skip to content

Commit

Permalink
feat: created molecule relation manger for collection resource, added…
Browse files Browse the repository at this point in the history
… functionality for processing molecules in entries table, and added forget the collection molecules count at the end of import
  • Loading branch information
sriramkanakam87 committed May 10, 2024
1 parent 5104dbf commit 6130df4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/Console/Commands/ImportEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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')
Expand Down
9 changes: 8 additions & 1 deletion app/Filament/Dashboard/Resources/CollectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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([
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Filament\Dashboard\Resources\CollectionResource\RelationManagers;

use Filament\Forms;
use Filament\Forms\Form;
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
{
protected static string $relationship = 'molecules';

public function form(Form $form): Form
{
return $form
->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(),
]),
]);
}
}

0 comments on commit 6130df4

Please sign in to comment.