Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/Steinbeck-Lab/coconut
Browse files Browse the repository at this point in the history
…into development
  • Loading branch information
CS76 committed May 15, 2024
2 parents 6772b7c + e08e647 commit 2bb3144
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 1 deletion.
85 changes: 85 additions & 0 deletions app/Console/Commands/DashWidgetsRefresh.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Console\Commands;

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 Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;

class DashWidgetsRefresh extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:dash-widgets-refresh';

/**
* The console command description.
*
* @var string
*/
protected $description = 'This refreshes the dashboard widgets.';

/**
* Execute the console command.
*/
public function handle()
{
// Clear the cache for all dashboard widgets
Cache::forget('stats.collections');
Cache::forget('stats.citations');
Cache::forget('stats.organisms');
Cache::forget('stats.geo_locations');
Cache::forget('stats.reports');
Cache::forget('stats.molecules');
Cache::forget('stats.molecules.non_stereo');
Cache::forget('stats.molecules.stereo');
Cache::forget('stats.molecules.parent');

// Create the cache for all DashboardStats widgets
Cache::rememberForever('stats.collections', function () {
return Collection::count();
});
Cache::rememberForever('stats.citations', function () {
return Citation::count();
});
Cache::rememberForever('stats.organisms', function () {
return Organism::count();
});
Cache::rememberForever('stats.geo_locations', function () {
return GeoLocation::count();
});
Cache::rememberForever('stats.reports', function () {
return Report::count();
});

// Create the cache for all DashboardStatsMid widgets
Cache::rememberForever('stats.molecules', function () {
return Molecule::count();
});
Cache::rememberForever('stats.molecules.non_stereo', function () {
return Molecule::where([
['has_stereo', false],
['is_parent', false],
])->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();
});
}
}
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
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
18 changes: 17 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\Filament\Dashboard\Resources\CollectionResource\Widgets\EntriesOverview;
use App\Livewire\ShowJobStatus;
Expand Down Expand Up @@ -75,6 +76,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([
//
Expand All @@ -92,11 +102,17 @@ 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 @@ -11,10 +11,12 @@
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 Illuminate\Support\Facades\Artisan;

class EntriesRelationManager extends RelationManager
{
Expand Down Expand Up @@ -157,6 +159,23 @@ 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');
}),
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([
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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;

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 2bb3144

Please sign in to comment.