-
-
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
41 changed files
with
1,070 additions
and
177 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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
use App\Concerns\Enums\Arrayable; | ||
use App\Concerns\Enums\Comparable; | ||
use Filament\Support\Contracts\HasLabel; | ||
|
||
enum Cron: string implements HasLabel | ||
{ | ||
use Arrayable; | ||
use Comparable; | ||
|
||
case EVERY_MINUTE = '* * * * *'; | ||
case EVERY_2_MINUTES = '*/2 * * * *'; | ||
case EVERY_3_MINUTES = '*/3 * * * *'; | ||
case EVERY_4_MINUTES = '*/4 * * * *'; | ||
case EVERY_5_MINUTES = '*/5 * * * *'; | ||
case EVERY_10_MINUTES = '*/10 * * * *'; | ||
case EVERY_5_1_MINUTES = '1-59/5 * * * *'; | ||
case EVERY_5_2_MINUTES = '2-59/5 * * * *'; | ||
case EVERY_5_3_MINUTES = '3-59/5 * * * *'; | ||
case EVERY_5_4_MINUTES = '4-59/5 * * * *'; | ||
case EVERY_10_5_MINUTES = '5-59/10 * * * *'; | ||
case EVERY_10_6_MINUTES = '6-59/10 * * * *'; | ||
case EVERY_10_7_MINUTES = '7-59/10 * * * *'; | ||
case EVERY_10_8_MINUTES = '8-59/10 * * * *'; | ||
case EVERY_10_9_MINUTES = '9-59/10 * * * *'; | ||
|
||
public function getLabel(): ?string | ||
{ | ||
return match ($this) { | ||
self::EVERY_MINUTE => __('app.cron.every_minute'), | ||
self::EVERY_2_MINUTES => __('app.cron.every_2_minutes'), | ||
self::EVERY_3_MINUTES => __('app.cron.every_3_minutes'), | ||
self::EVERY_4_MINUTES => __('app.cron.every_4_minutes'), | ||
self::EVERY_5_MINUTES => __('app.cron.every_5_minutes'), | ||
self::EVERY_10_MINUTES => __('app.cron.every_10_minutes'), | ||
self::EVERY_5_1_MINUTES => __('app.cron.every_5_1_minutes'), | ||
self::EVERY_5_2_MINUTES => __('app.cron.every_5_2_minutes'), | ||
self::EVERY_5_3_MINUTES => __('app.cron.every_5_3_minutes'), | ||
self::EVERY_5_4_MINUTES => __('app.cron.every_5_4_minutes'), | ||
self::EVERY_10_5_MINUTES => __('app.cron.every_10_5_minutes'), | ||
self::EVERY_10_6_MINUTES => __('app.cron.every_10_6_minutes'), | ||
self::EVERY_10_7_MINUTES => __('app.cron.every_10_7_minutes'), | ||
self::EVERY_10_8_MINUTES => __('app.cron.every_10_8_minutes'), | ||
self::EVERY_10_9_MINUTES => __('app.cron.every_10_9_minutes'), | ||
}; | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
|
||
class InvalidSourceUrlException extends Exception | ||
{ | ||
// | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
|
||
class MissingSourceUrlException extends Exception | ||
{ | ||
// | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Admin\Pages; | ||
|
||
use App\Filament\Admin\Resources\ElectionResource; | ||
use Filament\Forms\Form; | ||
use Filament\Pages\Tenancy\EditTenantProfile; | ||
|
||
class ElectionSettings extends EditTenantProfile | ||
{ | ||
protected static ?string $slug = 'settings'; | ||
|
||
public static function getLabel(): string | ||
{ | ||
return __('app.election.settings'); | ||
} | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return ElectionResource::form($form); | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
app/Filament/Admin/Resources/ElectionResource/Pages/CreateElection.php
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
app/Filament/Admin/Resources/ElectionResource/Pages/EditElection.php
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
...ilament/Admin/Resources/ElectionResource/RelationManagers/ScheduledJobRelationManager.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,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Admin\Resources\ElectionResource\RelationManagers; | ||
|
||
use App\Enums\Cron; | ||
use App\Jobs\SchedulableJob; | ||
use Filament\Forms\Components\Fieldset; | ||
use Filament\Forms\Components\Select; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Columns\ToggleColumn; | ||
use Filament\Tables\Table; | ||
use HaydenPierce\ClassFinder\ClassFinder; | ||
|
||
class ScheduledJobRelationManager extends RelationManager | ||
{ | ||
protected static string $relationship = 'scheduledJobs'; | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Select::make('job') | ||
->label(__('admin.field.job')) | ||
->options(function () { | ||
ClassFinder::disablePSR4Vendors(); | ||
|
||
$classes = ClassFinder::getClassesInNamespace('App\Jobs', ClassFinder::RECURSIVE_MODE); | ||
|
||
return collect($classes) | ||
->filter(fn (string $class) => is_subclass_of($class, SchedulableJob::class)) | ||
->mapWithKeys(fn (string $job) => [ | ||
$job => $job::name(), | ||
]); | ||
}), | ||
|
||
Select::make('cron') | ||
->label(__('admin.field.cron')) | ||
->options(Cron::options()) | ||
->enum(Cron::class) | ||
->required(), | ||
|
||
Fieldset::make('source') | ||
->label('Source') | ||
->schema([ | ||
TextInput::make('source_url') | ||
->label(__('admin.field.source_url')) | ||
->columnSpanFull(), | ||
|
||
TextInput::make('source_part') | ||
->label(__('admin.field.source_part')), | ||
|
||
TextInput::make('source_username') | ||
->label(__('admin.field.source_username')), | ||
|
||
TextInput::make('source_password') | ||
->label(__('admin.field.source_password')) | ||
->password(), | ||
]), | ||
]); | ||
} | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->recordTitleAttribute('job') | ||
->columns([ | ||
ToggleColumn::make('is_enabled') | ||
->label(__('admin.field.is_enabled')) | ||
->shrink(), | ||
|
||
TextColumn::make('job') | ||
->label(__('admin.field.job')) | ||
->description(fn (string $state) => $state, 'above') | ||
->formatStateUsing(fn (string $state) => $state::name()), | ||
|
||
TextColumn::make('cron') | ||
->label(__('admin.field.cron')), | ||
|
||
TextColumn::make('last_run_at') | ||
->label(__('admin.field.last_run_at')) | ||
->since(), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->headerActions([ | ||
Tables\Actions\CreateAction::make(), | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\DeleteAction::make(), | ||
]); | ||
} | ||
|
||
public function isReadOnly(): bool | ||
{ | ||
return false; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Jobs; | ||
|
||
class DummyJob extends SchedulableJob | ||
{ | ||
public static function name(): string | ||
{ | ||
return 'Dummy Job'; | ||
} | ||
|
||
public function execute(): void | ||
{ | ||
logger()->info('Dummy job executed', [ | ||
'job' => $this->scheduledJob, | ||
]); | ||
} | ||
} |
Oops, something went wrong.