Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Oct 24, 2024
1 parent a29b522 commit 51d43df
Show file tree
Hide file tree
Showing 41 changed files with 1,070 additions and 177 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ RUN set -ex; \

FROM vendor

# Needed for splitting CSVs
RUN set -ex; \
apk add --no-cache \
gawk;

COPY docker/s6-rc.d /etc/s6-overlay/s6-rc.d
COPY --from=assets --chown=www-data:www-data /build/public/build /var/www/public/build

Expand Down
52 changes: 52 additions & 0 deletions app/Enums/Cron.php
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'),
};
}
}
12 changes: 12 additions & 0 deletions app/Exceptions/InvalidSourceUrlException.php
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
{
//
}
12 changes: 12 additions & 0 deletions app/Exceptions/MissingSourceUrlException.php
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
{
//
}
24 changes: 24 additions & 0 deletions app/Filament/Admin/Pages/ElectionSettings.php
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);
}
}

This file was deleted.

This file was deleted.

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;
}
}
50 changes: 49 additions & 1 deletion app/Imports/Siruta/CountiesImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,65 @@ public function model(array $row): ?Model

return new County([
'id' => $row['siruta'],
'code' => $this->getCountyCode($row['siruta']),
'name' => Str::of($row['denloc'])
->replace(['Ţ', 'Ş'], ['Ț', 'Ș'])
->title()
->remove(['Județul', 'Municipiul'])
->trim(),

]);
}

public function batchSize(): int
{
return 50;
}

protected function getCountyCode(int $siruta): string
{
return [
10 => 'AB',
29 => 'AR',
38 => 'AG',
47 => 'BC',
56 => 'BH',
65 => 'BN',
74 => 'BT',
83 => 'BV',
92 => 'BR',
109 => 'BZ',
118 => 'CS',
127 => 'CJ',
136 => 'CT',
145 => 'CV',
154 => 'DB',
163 => 'DJ',
172 => 'GL',
181 => 'GJ',
190 => 'HR',
207 => 'HD',
216 => 'IL',
225 => 'IS',
234 => 'IF',
243 => 'MM',
252 => 'MH',
261 => 'MS',
270 => 'NT',
289 => 'OT',
298 => 'PH',
305 => 'SM',
314 => 'SJ',
323 => 'SB',
332 => 'SV',
341 => 'TR',
350 => 'TM',
369 => 'TL',
378 => 'VS',
387 => 'VL',
396 => 'VN',
403 => 'B',
519 => 'CL',
528 => 'GR',
][$siruta];
}
}
20 changes: 20 additions & 0 deletions app/Jobs/DummyJob.php
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,
]);
}
}
Loading

0 comments on commit 51d43df

Please sign in to comment.