Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Nov 5, 2024
1 parent dfa3bc5 commit 8917f40
Show file tree
Hide file tree
Showing 26 changed files with 265 additions and 354 deletions.
32 changes: 32 additions & 0 deletions app/Enums/ElectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace App\Enums;

use App\Concerns\Enums\Arrayable;
use App\Concerns\Enums\Comparable;
use Filament\Support\Contracts\HasLabel;

enum ElectionType: string implements HasLabel
{
use Arrayable;
use Comparable;

case PRESIDENTIAL = 'presidential';
case PARLIAMENTARY = 'parliamentary';
case EURO = 'euro';
case LOCAL = 'local';
case REFERENDUM = 'referendum';

public function getLabel(): ?string
{
return match ($this) {
self::PRESIDENTIAL => __('app.election_type.presidential'),
self::PARLIAMENTARY => __('app.election_type.parliamentary'),
self::EURO => __('app.election_type.euro'),
self::LOCAL => __('app.election_type.local'),
self::REFERENDUM => __('app.election_type.referendum'),
};
}
}
9 changes: 5 additions & 4 deletions app/Filament/Admin/Resources/ElectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources;

use App\Enums\ElectionType;
use App\Filament\Admin\Resources\ElectionResource\Pages;
use App\Filament\Admin\Resources\ElectionResource\RelationManagers\ScheduledJobRelationManager;
use App\Models\Election;
Expand Down Expand Up @@ -63,7 +64,8 @@ public static function form(Form $form): Form
->schema([
Select::make('type')
->label(__('app.field.type'))
->relationship('type', 'name')
->options(ElectionType::options())
->enum(ElectionType::class)
->required(),

TextInput::make('title')
Expand Down Expand Up @@ -140,7 +142,7 @@ public static function table(Table $table): Table
->sortable()
->shrink(),

TextColumn::make('type.name')
TextColumn::make('type')
->label(__('app.field.type'))
->sortable(),

Expand All @@ -160,8 +162,7 @@ public static function table(Table $table): Table
])
->filters([
SelectFilter::make('type')
->label(__('app.field.type'))
->relationship('type', 'name'),
->label(__('app.field.type')),
])
->filtersLayout(FiltersLayout::AboveContent)
->actions([
Expand Down
81 changes: 0 additions & 81 deletions app/Filament/Admin/Resources/ElectionTypeResource.php

This file was deleted.

22 changes: 22 additions & 0 deletions app/Http/Controllers/RedirectToElectionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Models\Election;
use Illuminate\Http\RedirectResponse;

class RedirectToElectionController extends Controller
{
public function __invoke(?Election $election = null): RedirectResponse
{
$election ??= Election::latest()->first();

$route = $election->properties?->get('default_route') === 'results'
? 'front.elections.results'
: 'front.elections.turnout';

return redirect()->route($route, $election);
}
}
6 changes: 3 additions & 3 deletions app/Livewire/Pages/ElectionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ abstract class ElectionPage extends Component implements HasForms

public Election $election;

#[Url(as: 'tara')]
#[Url(as: 'tara', history: true)]
public ?string $country = null;

#[Url(as: 'judet')]
#[Url(as: 'judet', history: true)]
public ?int $county = null;

#[Url(as: 'localitate')]
#[Url(as: 'localitate', history: true)]
public ?int $locality = null;

public function form(Form $form): Form
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Pages/ElectionResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ElectionResults extends ElectionPage
{
#[Layout('components.layouts.timeline')]
#[Layout('components.layouts.election')]
public function render()
{
return view('livewire.pages.election-results');
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Pages/ElectionTurnouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class ElectionTurnouts extends ElectionPage
{
#[Layout('components.layouts.timeline')]
#[Layout('components.layouts.election')]
public function render(): View
{
return view('livewire.pages.election-turnouts');
Expand Down
11 changes: 5 additions & 6 deletions app/Models/Election.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace App\Models;

use App\Enums\ElectionType;
use Database\Factories\ElectionFactory;
use Filament\Models\Contracts\HasAvatar;
use Filament\Models\Contracts\HasName;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Election extends Model implements HasName, HasAvatar
Expand All @@ -22,17 +22,21 @@ class Election extends Model implements HasName, HasAvatar

protected $fillable = [
'title',
'type',
'subtitle',
'slug',
'year',
'is_live',
'properties',
];

protected function casts(): array
{
return [
'type' => ElectionType::class,
'year' => 'int',
'is_live' => 'boolean',
'properties' => 'collection',
];
}

Expand All @@ -45,11 +49,6 @@ protected static function booted(): void
});
}

public function type(): BelongsTo
{
return $this->belongsTo(ElectionType::class);
}

public function scheduledJobs(): HasMany
{
return $this->hasMany(ScheduledJob::class);
Expand Down
27 changes: 0 additions & 27 deletions app/Models/ElectionType.php

This file was deleted.

67 changes: 0 additions & 67 deletions app/Policies/ElectionTypePolicy.php

This file was deleted.

38 changes: 38 additions & 0 deletions app/View/Components/Election/Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace App\View\Components\Election;

use App\Models\Election;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Route;
use Illuminate\View\Component;

class Header extends Component
{
public Election $election;

public Collection $items;

public function __construct(Election $election)
{
$this->election = $election;

$this->items = collect([
'front.elections.turnout' => __('app.navigation.turnout'),
'front.elections.results' => __('app.navigation.results'),
]);
}

public function render(): View
{
return view('components.election.header');
}

public function isCurrent(string $route): bool
{
return Route::currentRouteName() === $route;
}
}
Loading

0 comments on commit 8917f40

Please sign in to comment.