Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Nov 21, 2024
1 parent 9b1849b commit 2c8e946
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
35 changes: 22 additions & 13 deletions app/Filament/Admin/Resources/ElectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand All @@ -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),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Candidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Party.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lang/ro/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 2c8e946

Please sign in to comment.