Skip to content

Commit

Permalink
feat: new issues relation for molecules is created
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramkanakam87 committed Dec 13, 2024
1 parent f5f58d8 commit 13539f3
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/Filament/Dashboard/Resources/MoleculeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\CitationsRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\CollectionsRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\GeoLocationRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\IssuesRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\MoleculesRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\OrganismsRelationManager;
use App\Filament\Dashboard\Resources\MoleculeResource\RelationManagers\PropertiesRelationManager;
Expand Down Expand Up @@ -225,6 +226,7 @@ public static function getRelations(): array
GeoLocationRelationManager::class,
OrganismsRelationManager::class,
AuditsRelationManager::class,
IssuesRelationManager::class,
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

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

use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;

class IssuesRelationManager extends RelationManager
{
protected static string $relationship = 'issues';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('title')
->required()
->maxLength(255),
Forms\Components\TextInput::make('comment')
->required()
->maxLength(255),
Forms\Components\TextInput::make('is_active')
->label('Active')
->required()
->maxLength(255)
->hidden(function (string $operation) {
return $operation == 'create';
}),
Forms\Components\TextInput::make('is_fixed')
->label('Fixed')
->required()
->maxLength(255)
->hidden(function (string $operation) {
return $operation == 'create';
}),
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('title')
->columns([
Tables\Columns\TextColumn::make('title'),
Tables\Columns\TextColumn::make('comment'),
Tables\Columns\TextColumn::make('is_active')
->label('Active')
->formatStateUsing(
function (string $state) {
return $state ? 'Yes' : 'No';
}
),
Tables\Columns\TextColumn::make('is_fixed')
->label('Fixed')
->formatStateUsing(
function (string $state) {
return $state ? 'Yes' : 'No';
}
),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['user_id'] = auth()->id();

return $data;
}),
Tables\Actions\AttachAction::make()->multiple(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}
8 changes: 8 additions & 0 deletions app/Models/Molecule.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ public function related()
return $this->belongsToMany(Molecule::class, 'molecule_related', 'molecule_id', 'related_id');
}

/**
* Get the issues associated with the molecule.
*/
public function issues(): BelongsToMany
{
return $this->belongsToMany(Issue::class)->withPivot('is_active', 'is_fixed')->withTimestamps();
}

public function transformAudit(array $data): array
{
return changeAudit($data);
Expand Down

0 comments on commit 13539f3

Please sign in to comment.