Skip to content

Commit

Permalink
Add candidates importe / hidden candidates list on tournouts when Can…
Browse files Browse the repository at this point in the history
…didadtes is null (#113)

fix candidates
  • Loading branch information
gheorghelupu17 authored Nov 29, 2024
1 parent 0c31fc4 commit 0e3fa2e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
11 changes: 11 additions & 0 deletions app/Filament/Admin/Resources/CandidateResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
namespace App\Filament\Admin\Resources;

use App\Filament\Admin\Resources\CandidateResource\Pages;
use App\Filament\Imports\SimpleCandidateImporter;
use App\Models\Candidate;
use Filament\Facades\Filament;
use Filament\Forms\Components\ColorPicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Columns\ColorColumn;
use Filament\Tables\Columns\SpatieMediaLibraryImageColumn;
use Filament\Tables\Columns\TextColumn;
Expand Down Expand Up @@ -87,6 +90,14 @@ public static function table(Table $table): Table
->filters([
//
])
->headerActions([
ImportAction::make()
->importer(SimpleCandidateImporter::class)
->options([
'election_id' => Filament::getTenant()->id,
'candidate_list' => true,
]),
])
->actions([
Tables\Actions\EditAction::make(),
])
Expand Down
10 changes: 7 additions & 3 deletions app/Filament/Imports/SimpleCandidateImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public static function getColumns(): array
->requiredMapping()
->rules(['required', 'string', 'max:255']),

ImportColumn::make('acronym')
->rules(['nullable', 'string', 'max:255']),

ImportColumn::make('color')
->rules(['nullable', 'string', 'hex_color']),
];
Expand All @@ -33,9 +36,10 @@ public function getJobRetryUntil(): ?CarbonInterface

public function resolveRecord(): Candidate|Party
{
static::$model = RecordService::isIndependentCandidate($this->data['name'])
? Candidate::class
: Party::class;
static::$model = Party::class;
if (RecordService::isIndependentCandidate($this->data['name']) || $this->options['candidate_list']) {
static::$model = Candidate::class;
}

return static::getModel()::firstOrNew([
'name' => $this->data['name'],
Expand Down
4 changes: 3 additions & 1 deletion app/Models/Party.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class Party extends Model implements HasMedia, HasDisplayName
public static function booted(): void
{
static::creating(function (Party $party) {
if (blank($party->acronym)) {

if (empty($party->acronym)) {
dd('here', $party);
$party->acronym = Str::initials($party->name);
}
});
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/pages/election-turnouts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
:election="$election"
show-embed />

@if ($election->type->isNot(ElectionType::REFERENDUM))
@if ($election->type->isNot(ElectionType::REFERENDUM) && $this->candidates->isNotEmpty())
<x-candidates.turnouts-table :items="$this->candidates" />
@endif

Expand Down

0 comments on commit 0e3fa2e

Please sign in to comment.