diff --git a/app/Filament/Admin/Resources/ElectionResource.php b/app/Filament/Admin/Resources/ElectionResource.php index 066a793..724a462 100644 --- a/app/Filament/Admin/Resources/ElectionResource.php +++ b/app/Filament/Admin/Resources/ElectionResource.php @@ -10,6 +10,7 @@ use App\Filament\Admin\Resources\ElectionResource\RelationManagers\ScheduledJobRelationManager; use App\Models\Election; use Filament\Forms; +use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\KeyValue; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; @@ -70,15 +71,9 @@ public static function form(Form $form): Form ->enum(ElectionType::class) ->required(), - /* - * @see https://dev.mysql.com/doc/refman/8.4/en/year.html Documentation for the YEAR data type - */ - TextInput::make('year') - ->label(__('app.field.year')) - ->minValue(1901) - ->maxValue(2155) - ->numeric() - ->default(today()->year) + DatePicker::make('date') + ->label(__('app.field.date')) + ->default(today()) ->required(), TextInput::make('title') @@ -93,6 +88,10 @@ public static function form(Form $form): Form ->label(__('app.field.is_live')) ->default(false), + Toggle::make('is_visible') + ->label(__('app.field.is_visible')) + ->default(false), + Toggle::make('has_lists') ->label(__('app.field.has_lists')) ->default(false), @@ -131,12 +130,17 @@ public static function infolist(Infolist $infolist): Infolist TextEntry::make('subtitle') ->label(__('app.field.subtitle')), - TextEntry::make('year') - ->label(__('app.field.year')), + TextEntry::make('date') + ->label(__('app.field.date')) + ->date(), IconEntry::make('is_live') ->label(__('app.field.is_live')) ->boolean(), + + IconEntry::make('is_visible') + ->label(__('app.field.is_visible')) + ->boolean(), ]), Infolists\Components\Section::make() @@ -173,13 +177,18 @@ public static function table(Table $table): Table ->sortable() ->description(fn (Election $record) => $record->subtitle), - TextColumn::make('year') - ->label(__('app.field.year')) + TextColumn::make('date') + ->label(__('app.field.date')) ->sortable(), IconColumn::make('is_live') ->label(__('app.field.is_live')) ->boolean(), + + IconColumn::make('is_visible') + ->label(__('app.field.is_visible')) + ->boolean(), + ]) ->filters([ SelectFilter::make('type') diff --git a/app/Models/Candidate.php b/app/Models/Candidate.php index 0b2a245..599db29 100644 --- a/app/Models/Candidate.php +++ b/app/Models/Candidate.php @@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Support\Arr; use Spatie\Image\Enums\Fit; use Spatie\MediaLibrary\HasMedia; @@ -64,6 +65,11 @@ public function party(): BelongsTo return $this->belongsTo(Party::class); } + public function votes(): MorphMany + { + return $this->morphMany(Vote::class, 'votable'); + } + public function getDisplayName(): string { return $this->display_name ?? $this->name; diff --git a/app/Models/Party.php b/app/Models/Party.php index b61d94d..2dfc135 100644 --- a/app/Models/Party.php +++ b/app/Models/Party.php @@ -9,6 +9,7 @@ use Database\Factories\PartyFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Spatie\Image\Enums\Fit; @@ -67,6 +68,11 @@ public function registerMediaCollections(): void }); } + public function votes(): MorphMany + { + return $this->morphMany(Vote::class, 'votable'); + } + public function getDisplayName(): string { return $this->name; diff --git a/lang/ro/app.php b/lang/ro/app.php index 66a3db4..d74da12 100644 --- a/lang/ro/app.php +++ b/lang/ro/app.php @@ -21,6 +21,7 @@ 'initial_complement' => 'Înscriși pe listele complementare', 'initial_permanent' => 'Înscriși pe listele permanente', 'is_live' => 'Live', + 'is_visible' => 'Vizibil', 'locality' => 'Localitate', 'location' => 'Locație', 'name' => 'Nume',