- Added comprehensive parameter and return type hinting to closures across various Filament resources, actions, and relation managers to improve type safety and static analysis. - Fixed logic in ReportRelationManager where report count was incorrectly compared, preventing the 'Buat Laporan' button from showing correctly. - Corrected namespaces for RepeatableEntry and TextEntry in ViewCooperation (changed from Filament\Schemas to Filament\Infolists). - Fixed component rendering in JournalistResource form by ensuring sections are correctly returned in the mapping. - Added @var docblocks to resolve lint errors related to auth()->user() and verified query builder return types. - Standardized file retrieval logic in PartnerResource and improved overall code reliability."
129 lines
4.3 KiB
PHP
129 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Cooperations\RelationManagers;
|
|
|
|
use App\Filament\Resources\Manage\Cooperations\Actions\Report\AcceptAction;
|
|
use App\Filament\Resources\Manage\Cooperations\Actions\Report\RejectAction;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Enums\Width;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class ReportRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'reports';
|
|
|
|
protected static ?string $title = 'Laporan';
|
|
|
|
public function isReadOnly(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
TextInput::make('title')
|
|
->placeholder('Dirgahayu Purwakarta')
|
|
->required()
|
|
->maxLength(200)
|
|
->autocomplete(false)
|
|
->autofocus(),
|
|
|
|
DatePicker::make('publication_date')
|
|
->label('Tanggal Publikasi')
|
|
->placeholder(fn (): string => now()->format('l, d F Y'))
|
|
->native(false)
|
|
->displayFormat('l, d F Y')
|
|
->required(),
|
|
|
|
TextInput::make('link')
|
|
->label('Tautan')
|
|
->placeholder('https://example.com')
|
|
->maxLength(50)
|
|
->url()
|
|
->required()
|
|
->autocomplete(false),
|
|
|
|
Textarea::make('description')
|
|
->label('Deskripsi')
|
|
->placeholder('....')
|
|
->required()
|
|
->autocomplete(false),
|
|
|
|
SpatieMediaLibraryFileUpload::make('image')
|
|
->label('Gambar')
|
|
->disk(config('filesystems.default'))
|
|
->acceptedFileTypes(['image/*'])
|
|
->maxSize(1024 * 3)
|
|
->collection('reports')
|
|
->image()
|
|
->required(),
|
|
])
|
|
->columns(1);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('title')
|
|
->columns([
|
|
TextColumn::make('title')
|
|
->label('Judul')
|
|
->searchable(),
|
|
|
|
TextColumn::make('publication_date')
|
|
->label('Tanggal Publikasi')
|
|
->date('l, d F Y'),
|
|
|
|
TextColumn::make('link')
|
|
->label('Link')
|
|
->limit(30)
|
|
->url(fn (\App\Models\Report $record): string => $record->link)
|
|
->openUrlInNewTab(),
|
|
|
|
TextColumn::make('status')
|
|
->label('Status')
|
|
->badge(),
|
|
|
|
TextColumn::make('rejectionReasons.reason')
|
|
->label('Alasan Penolakan')
|
|
->searchable(),
|
|
])
|
|
->filters([])
|
|
->recordActions([
|
|
AcceptAction::make('accept'),
|
|
|
|
RejectAction::make('reject'),
|
|
])
|
|
->headerActions([
|
|
CreateAction::make()
|
|
->label('Buat Laporan')
|
|
->modalWidth(Width::Large)
|
|
->modalHeading('Buat Laporan')
|
|
->mutateDataUsing(function (array $data): array {
|
|
$data['task_assignment_id'] = $this->getOwnerRecord()->taskAssignments()->first()?->id;
|
|
|
|
return $data;
|
|
})
|
|
->visible(function (): bool {
|
|
$taskAssignment = $this->getOwnerRecord()->taskAssignments()->first();
|
|
|
|
if (! $taskAssignment) {
|
|
return false;
|
|
}
|
|
|
|
return $taskAssignment->reports()->count() < $taskAssignment->report_amount;
|
|
}),
|
|
])
|
|
->toolbarActions([]);
|
|
}
|
|
}
|