Skip to content

Commit

Permalink
feat: similar named organisms are displayed on the edit page of organ…
Browse files Browse the repository at this point in the history
…isms with an option to edit them
  • Loading branch information
sriramkanakam87 committed Aug 15, 2024
1 parent edde586 commit 36622d4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
5 changes: 2 additions & 3 deletions app/Filament/Dashboard/Resources/OrganismResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ public static function form(Form $form): Form

Group::make()
->schema([
Section::make('Similar Organisms')
Section::make('')
->schema([
OrganismsTable::make('Custom Table'),
// \Livewire\Livewire::mount('similar-organisms', ['organismId' => function ($get) {
// dd($get('name'));
// return $get('name');
// }]),
]),
])
->hidden(function($operation) {
->hidden(function ($operation) {
return $operation === 'create';
})
->columnSpan(1),
Expand Down
23 changes: 23 additions & 0 deletions app/Forms/Components/OrganismsTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Forms\Components;

use App\Models\Organism;
use Filament\Forms\Components\Field;

class OrganismsTable extends Field
{
protected string $view = 'forms.components.organisms-table';

public static function make(string $name): static
{
return parent::make($name);
}

public function getTableData($record_name)
{
return Organism::select('id', 'name', urldecode('iri'), 'molecule_count')->where('name', 'ILIKE', '%'.$record_name.'%')
->orWhereRaw('? ILIKE CONCAT(\'%\', name, \'%\')', [$record_name])
->get();
}
}
41 changes: 19 additions & 22 deletions resources/views/forms/components/organisms-table.blade.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@


<div>
<table class="table-auto w-full">
<thead>
<tr>
@foreach(array_keys($getTableData($getRecord()->name)[0] ?? []) as $header)
<th class="px-4 py-2">{{ $header }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($getTableData($getRecord()->name) as $row)
<tr>
@foreach($row as $value)
<td class="border px-4 py-2">{{ $value }}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="overflow-x-auto">
@foreach($getTableData($getRecord()->name) as $row)
<div class="border p-2 px-4 rounded-md mb-2 flex items-center justify-between">
<div class="mr-4">
<p class="text-md font-bold">
{{ $row['name'] }} (Molecule count: {{ $row['molecule_count'] }})
</p>
<p>
<a href="{{$row['iri']}}" target="_blank" class="text-blue-600 hover:underline">
IRI - {{ $row['iri'] }}
</a>
</p>
</div>
<x-button href="{{env('APP_URL').'/dashboard/organisms/'.$row['id'].'/edit'}}" target="_blank" wire:navigate.hover>
Edit
</x-button>
</div>
@endforeach
</div>

0 comments on commit 36622d4

Please sign in to comment.