Skip to content

Commit

Permalink
fix: importer updates and formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Apr 25, 2024
1 parent 276deb7 commit d8bd65e
Show file tree
Hide file tree
Showing 27 changed files with 124 additions and 147 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/ImportEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function handle()

$batchJobs = [];
$i = 0;
Entry::select('id')->where('status', 'PASSED')->whereNull('molecule_id')->where('collection_id', $collection->id)->chunk(10000, function ($ids) use (&$batchJobs, &$i) {
Entry::select('id')->where('status', 'PASSED')->where('collection_id', $collection->id)->chunk(10000, function ($ids) use (&$batchJobs, &$i) {
array_push($batchJobs, new ImportEntriesBatch($ids->pluck('id')->toArray()));
$i = $i + 1;
});
Expand Down
12 changes: 5 additions & 7 deletions app/Events/ReportStatusChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use App\Models\Report;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use App\Models\Report;

class ReportStatusChanged
{
Expand All @@ -18,10 +15,11 @@ class ReportStatusChanged
/**
* Create a new event instance.
*/
public $report;

public $new;

public $report;
public $new;
public $old;
public $old;

public function __construct(Report $report, $new, $old)
{
Expand Down
5 changes: 1 addition & 4 deletions app/Events/ReportSubmitted.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use App\Models\Report;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use App\Models\Report;

class ReportSubmitted
{
Expand Down
27 changes: 18 additions & 9 deletions app/Filament/Dashboard/Imports/EntryImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Filament\Forms\Components\Checkbox;

class EntryImporter extends Importer
{
Expand All @@ -30,12 +31,24 @@ public static function getColumns(): array
];
}

public static function getOptionsFormComponents(): array
{
return [
Checkbox::make('updateExisting')
->label('Update existing records'),
];
}

public function resolveRecord(): ?Entry
{
// return Entry::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
if ($this->options['updateExisting'] ?? false) {
return Entry::firstOrNew([
'canonical_smiles' => $this->data['canonical_smiles'],
'reference_id' => $this->data['reference_id'],
'collection_id' => $this->options['collection_id'],
]);
}

$entry = new Entry();
$entry->collection_id = $this->options['collection_id'];

Expand All @@ -46,11 +59,7 @@ public static function getCompletedNotificationBody(Import $import): string
{
ImportedCSVProcessed::dispatch($import);

$body = 'Your entry import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';

if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
$body = 'Your entry import has completed. '.number_format($import->total_rows).' '.str('row')->plural($import->total_rows).' imported.';

return $body;
}
Expand Down
9 changes: 2 additions & 7 deletions app/Filament/Dashboard/Resources/GeoLocationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
namespace App\Filament\Dashboard\Resources;

use App\Filament\Dashboard\Resources\GeoLocationResource\Pages;
use App\Filament\Dashboard\Resources\GeoLocationResource\RelationManagers;
use App\Models\GeoLocation;
use Filament\Forms;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Fieldset;

class GeoLocationResource extends Resource
{
protected static ?string $navigationGroup = 'Data';

protected static ?int $navigationSort = 5;

protected static ?string $model = GeoLocation::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace App\Filament\Dashboard\Resources\GeoLocationResource\Pages;

use App\Filament\Dashboard\Resources\GeoLocationResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
use App\Models\Molecule;
use Filament\Resources\Pages\CreateRecord;

class CreateGeoLocation extends CreateRecord
{
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Dashboard/Resources/MoleculeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use App\Filament\Dashboard\Resources\MoleculeResource\Pages;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\CitationsRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\CollectionsRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\MoleculesRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\PropertiesRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\GeoLocationRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\MoleculesRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\OrganismsRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\PropertiesRelationManager;
use App\Models\Molecule;
use Filament\Forms\Components\TextArea;
use Filament\Forms\Components\TextInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
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;
use Filament\Tables\Actions\AttachAction;
use Filament\Tables\Table;

class GeoLocationRelationManager extends RelationManager
{
Expand Down Expand Up @@ -41,7 +39,7 @@ public function table(Table $table): Table
->preloadRecordSelect()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('locations')
Forms\Components\TextInput::make('locations'),
]),
])
->actions([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\AttachAction;
use Filament\Tables\Actions\EditAction;
use App\Models\Organism;
use Filament\Tables\Table;

class OrganismsRelationManager extends RelationManager
{
Expand Down Expand Up @@ -44,7 +39,7 @@ public function table(Table $table): Table
->preloadRecordSelect()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('organism_parts')
Forms\Components\TextInput::make('organism_parts'),
]),
])
->actions([
Expand Down
3 changes: 0 additions & 3 deletions app/Filament/Dashboard/Resources/OrganismResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
namespace App\Filament\Dashboard\Resources;

use App\Filament\Dashboard\Resources\OrganismResource\Pages;
use App\Filament\Dashboard\Resources\OrganismResource\RelationManagers;
use App\Models\Organism;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class OrganismResource extends Resource
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Filament\Dashboard\Resources\OrganismResource\Pages;

use App\Filament\Dashboard\Resources\OrganismResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreateOrganism extends CreateRecord
Expand Down
63 changes: 30 additions & 33 deletions app/Filament/Dashboard/Resources/ReportResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

namespace App\Filament\Dashboard\Resources;

use App\Events\ReportStatusChanged;
use App\Filament\Dashboard\Resources\ReportResource\Pages;
use App\Filament\Dashboard\Resources\ReportResource\RelationManagers;
use App\Models\Citation;
use App\Models\Molecule;
use App\Models\Report;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieTagsInput;
use Filament\Forms\Components\TextArea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use App\Events\ReportStatusChanged;
use App\Models\Molecule;
use App\Models\Citation;
use Illuminate\Http\Request;
use Filament\Forms\Get;
use Illuminate\Support\Str;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;
use Filament\Forms\Components\SpatieTagsInput;

class ReportResource extends Resource
{
Expand All @@ -32,7 +32,7 @@ class ReportResource extends Resource
protected static ?int $navigationSort = 1;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
return $form
Expand All @@ -46,9 +46,9 @@ public static function form(Form $form): Form
'collection' => 'Collection',
])
->hidden(function (string $operation) {
if($operation == 'create' && (!request()->has('collection_uuid') && !request()->has('citation_id') && !request()->has('compound_id'))) {
if ($operation == 'create' && (! request()->has('collection_uuid') && ! request()->has('citation_id') && ! request()->has('compound_id'))) {
return false;
}else {
} else {
return true;
}
}),
Expand All @@ -60,18 +60,17 @@ public static function form(Form $form): Form
->relationship('collections', 'title')
->multiple()
->preload()
->hidden(function (Get $get, String $operation) {
if($operation == 'edit' || $operation == 'view') {
if($get('collections') == []) {
return true;
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if ($get('collections') == []) {
return true;
}
}
elseif(!request()->has('collection_uuid') && $get('choice') != 'collection') {
} elseif (! request()->has('collection_uuid') && $get('choice') != 'collection') {
return true;
}
})
->disabled(function (String $operation) {
if($operation == 'edit') {
->disabled(function (string $operation) {
if ($operation == 'edit') {
return true;
}
})
Expand All @@ -83,18 +82,17 @@ public static function form(Form $form): Form
})
->multiple()
// ->preload()
->hidden(function (Get $get, String $operation) {
if($operation == 'edit' || $operation == 'view') {
if($get('citations') == []) {
return true;
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if ($get('citations') == []) {
return true;
}
}
elseif(!request()->has('citation_id') && $get('choice') != 'citation') {
} elseif (! request()->has('citation_id') && $get('choice') != 'citation') {
return true;
}
})
->disabled(function (String $operation) {
if($operation == 'edit') {
->disabled(function (string $operation) {
if ($operation == 'edit') {
return true;
}
})
Expand All @@ -117,18 +115,17 @@ public static function form(Form $form): Form
TextInput::make('mol_id_csv')
->label('Molecules')
->placeholder('Enter the Identifiers separated by commas')
->hidden(function (Get $get, String $operation) {
if($operation == 'edit' || $operation == 'view') {
if(is_null($get('mol_id_csv'))) {
return true;
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if (is_null($get('mol_id_csv'))) {
return true;
}
}
elseif(!request()->has('compound_id') && $get('choice') != 'molecule') {
} elseif (! request()->has('compound_id') && $get('choice') != 'molecule') {
return true;
}
})
->disabled(function (String $operation) {
if($operation == 'edit') {
->disabled(function (string $operation) {
if ($operation == 'edit') {
return true;
}
}),
Expand Down
Loading

0 comments on commit d8bd65e

Please sign in to comment.