-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,344 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
trait Publishable | ||
{ | ||
public function initializePublishable(): void | ||
{ | ||
$this->fillable[] = 'published_at'; | ||
|
||
$this->casts['published_at'] = 'datetime'; | ||
} | ||
|
||
public function scopeWithDrafted(Builder $query): Builder | ||
{ | ||
return $query->withoutGlobalScope('published'); | ||
} | ||
|
||
public function scopeOnlyDrafted(Builder $query): Builder | ||
{ | ||
return $query | ||
->withDrafted() | ||
->whereNull('published_at'); | ||
} | ||
|
||
public function scopeOnlyScheduled(Builder $query): Builder | ||
{ | ||
return $query | ||
->withDrafted() | ||
->whereNotNull('published_at') | ||
->where('published_at', '>', Carbon::now()); | ||
} | ||
|
||
public function scopeOnlyPublished(Builder $query): Builder | ||
{ | ||
return $query | ||
->whereNotNull('published_at') | ||
->where('published_at', '<=', Carbon::now()); | ||
} | ||
|
||
public function isDraft(): bool | ||
{ | ||
return \is_null($this->published_at); | ||
} | ||
|
||
public function isPublished(): bool | ||
{ | ||
return ! $this->isDraft() && $this->published_at->isPast(); | ||
} | ||
|
||
public function isScheduled(): bool | ||
{ | ||
return ! $this->isDraft() && $this->published_at->isFuture(); | ||
} | ||
|
||
/** | ||
* Determine the publish status of the model instance. | ||
* | ||
* @return string | ||
*/ | ||
public function status(): string | ||
{ | ||
if ($this->isDraft()) { | ||
return 'draft'; | ||
} | ||
|
||
if ($this->isPublished()) { | ||
return 'published'; | ||
} | ||
|
||
if ($this->isScheduled()) { | ||
return 'scheduled'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
use App\Concerns\Enums\Arrayable; | ||
use App\Concerns\Enums\Comparable; | ||
use App\Concerns\Enums\HasLabel; | ||
|
||
enum Country: string | ||
{ | ||
use Arrayable; | ||
use Comparable; | ||
use HasLabel; | ||
|
||
case EU = 'eu'; | ||
case AT = 'at'; | ||
case BE = 'be'; | ||
case BG = 'bg'; | ||
case HR = 'hr'; | ||
case CY = 'cy'; | ||
case CZ = 'cz'; | ||
case DK = 'dk'; | ||
case EE = 'ee'; | ||
case FI = 'fi'; | ||
case FR = 'fr'; | ||
case DE = 'de'; | ||
case GR = 'gr'; | ||
case HU = 'hu'; | ||
case IE = 'ie'; | ||
case IT = 'it'; | ||
case LV = 'lv'; | ||
case LT = 'lt'; | ||
case LU = 'lu'; | ||
case MT = 'mt'; | ||
case NL = 'nl'; | ||
case PL = 'pl'; | ||
case PT = 'pt'; | ||
case RO = 'ro'; | ||
case SK = 'sk'; | ||
case SI = 'si'; | ||
case ES = 'es'; | ||
case SE = 'se'; | ||
|
||
protected function labelKeyPrefix(): ?string | ||
{ | ||
return 'countries'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\ElectionDayResource\Pages; | ||
use App\Models\ElectionDay; | ||
use Carbon\Carbon; | ||
use Filament\Forms\Components\DatePicker; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Table; | ||
|
||
class ElectionDayResource extends Resource | ||
{ | ||
protected static ?string $model = ElectionDay::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-calendar-days'; | ||
|
||
public static function getNavigationGroup(): ?string | ||
{ | ||
return __('navigation.group.manage'); | ||
} | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
DatePicker::make('date') | ||
->time(false) | ||
->unique(ignoreRecord:true) | ||
->columnSpanFull(), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('id') | ||
->prefix('#') | ||
->sortable() | ||
->shrink(), | ||
|
||
TextColumn::make('date') | ||
->sortable() | ||
->formatStateUsing(fn (Carbon $state) => $state->toDateString()), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]) | ||
->defaultSort('date', 'desc'); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ManageElectionDays::route('/'), | ||
]; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/Filament/Resources/ElectionDayResource/Pages/ManageElectionDays.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ElectionDayResource\Pages; | ||
|
||
use App\Filament\Resources\ElectionDayResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ManageElectionDays extends ListRecords | ||
{ | ||
protected static string $resource = ElectionDayResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.