-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add SMR area management/publication feature #1736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
19wintersp
wants to merge
5
commits into
VATSIM-UK:main
Choose a base branch
from
19wintersp:smr-areas
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8187579
feat: add SMR area management/publication feature
19wintersp 7c41613
style: ci
19wintersp f3f2760
test: add tests for SMR areas
19wintersp d1d5ae1
test: fix incomplete tests and remove redundant override
19wintersp 439472d
docs: add note about output format
19wintersp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,119 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Helpers\HasCoordinates; | ||
use App\Filament\Helpers\SelectOptions; | ||
use App\Filament\Resources\SmrAreaResource\Pages; | ||
use App\Models\SmrArea; | ||
use Filament\Forms\Components\Select; | ||
use Filament\Forms\Components\Textarea; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Components\DateTimePicker; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables\Table; | ||
use Filament\Tables; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Support\Facades\App; | ||
|
||
class SmrAreaResource extends Resource | ||
{ | ||
use TranslatesStrings; | ||
use HasCoordinates; | ||
|
||
protected static ?string $model = SmrArea::class; | ||
protected static ?string $modelLabel = 'SMR Area'; | ||
protected static ?string $navigationGroup = 'Airfield'; | ||
protected static ?string $navigationIcon = 'heroicon-o-exclamation-triangle'; | ||
protected static ?string $navigationLabel = 'SMR Areas'; | ||
protected static ?string $pluralModelLabel = 'SMR Areas'; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Select::make('airfield_id') | ||
->label(self::translateFormPath('airfield.label')) | ||
->helperText(self::translateFormPath('airfield.helper')) | ||
->options(SelectOptions::airfields()) | ||
->searchable(!App::runningUnitTests()) | ||
->required(), | ||
TextInput::make('name') | ||
->label(self::translateFormPath('name.label')) | ||
->helperText(self::translateFormPath('name.helper')) | ||
->minLength(1) | ||
->maxLength(255), | ||
TextInput::make('source') | ||
->label(self::translateFormPath('source.label')) | ||
->helperText(self::translateFormPath('source.helper')) | ||
->minLength(1) | ||
->maxLength(255), | ||
Textarea::make('coordinates') | ||
->label(self::translateFormPath('coordinates.label')) | ||
->helperText(self::translateFormPath('coordinates.helper')) | ||
->rows(5) | ||
->required() | ||
// relatively lax validation; a stricter pattern is somewhat unnecessary | ||
->regex('/^(COORD(:[NESW][\d\.]{13}){2}\n*){3,}$/'), | ||
DateTimePicker::make('start_date') | ||
->label(self::translateFormPath('start_date.label')) | ||
->helperText(self::translateFormPath('start_date.helper')), | ||
DateTimePicker::make('end_date') | ||
->label(self::translateFormPath('end_date.label')) | ||
->helperText(self::translateFormPath('end_date.helper')) | ||
->after('start_date'), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('airfield.code') | ||
->label(self::translateTablePath('columns.airfield')) | ||
->searchable() | ||
->sortable(), | ||
Tables\Columns\TextColumn::make('name') | ||
->label(self::translateTablePath('columns.name')) | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('source') | ||
->label(self::translateTablePath('columns.source')) | ||
->searchable(), | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\DeleteAction::make(), | ||
]) | ||
->filters([ | ||
Tables\Filters\Filter::make('expired') | ||
->toggle() | ||
->label(self::translateFilterPath('expired')) | ||
->query(fn (Builder $query) => $query->expired()), | ||
Tables\Filters\TernaryFilter::make('activation') | ||
->label(self::translateFilterPath('activation.label')) | ||
->trueLabel(self::translateFilterPath('activation.true')) | ||
->falseLabel(self::translateFilterPath('activation.false')) | ||
->queries( | ||
true: fn (Builder $query) => $query->active(), | ||
false: fn (Builder $query) => $query->whereNot->active(), | ||
blank: fn (Builder $query) => $query, | ||
), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListSmrAreas::route('/'), | ||
'create' => Pages\CreateSmrArea::route('/create'), | ||
'view' => Pages\ViewSmrArea::route('/{record}'), | ||
'edit' => Pages\EditSmrArea::route('/{record}/edit'), | ||
]; | ||
} | ||
|
||
protected static function translationPathRoot(): string | ||
{ | ||
return 'smr_areas'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/Filament/Resources/SmrAreaResource/Pages/CreateSmrArea.php
This file contains hidden or 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,11 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\SmrAreaResource\Pages; | ||
|
||
use App\Filament\Resources\SmrAreaResource; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateSmrArea extends CreateRecord | ||
{ | ||
protected static string $resource = SmrAreaResource::class; | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/SmrAreaResource/Pages/EditSmrArea.php
This file contains hidden or 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,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\SmrAreaResource\Pages; | ||
|
||
use App\Filament\Resources\SmrAreaResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditSmrArea extends EditRecord | ||
{ | ||
protected static string $resource = SmrAreaResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\DeleteAction::make(), | ||
]; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/Filament/Resources/SmrAreaResource/Pages/ListSmrAreas.php
This file contains hidden or 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 | ||
|
||
namespace App\Filament\Resources\SmrAreaResource\Pages; | ||
|
||
use App\Filament\Resources\Pages\LimitsTableRecordListingOptions; | ||
use App\Filament\Resources\SmrAreaResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListSmrAreas extends ListRecords | ||
{ | ||
use LimitsTableRecordListingOptions; | ||
protected static string $resource = SmrAreaResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/SmrAreaResource/Pages/ViewSmrArea.php
This file contains hidden or 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,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\SmrAreaResource\Pages; | ||
|
||
use App\Filament\Resources\SmrAreaResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\ViewRecord; | ||
|
||
class ViewSmrArea extends ViewRecord | ||
{ | ||
protected static string $resource = SmrAreaResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\EditAction::make(), | ||
]; | ||
} | ||
} |
This file contains hidden or 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 | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\SmrArea; | ||
use Illuminate\Http\Response; | ||
|
||
class SmrAreaController extends Controller | ||
{ | ||
public function getFormattedSmrAreas(): Response | ||
{ | ||
return response( | ||
// backwards-compatible format for vSMR: sline-format coordinates on | ||
// each line, with polygons separated by at least one blank line | ||
SmrArea::active()->pluck("coordinates")->join("\n\n"), | ||
200, | ||
["Content-Type" => "text/plain"], | ||
); | ||
} | ||
} |
This file contains hidden or 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 | ||
|
||
namespace App\Models; | ||
|
||
use App\Models\Airfield\Airfield; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class SmrArea extends Model | ||
{ | ||
public $table = 'smr_area'; | ||
|
||
protected $fillable = [ | ||
'airfield_id', | ||
'name', | ||
'source', | ||
'coordinates', | ||
'start_date', | ||
'end_date', | ||
'created_at', | ||
'updated_at', | ||
]; | ||
|
||
protected $hidden = [ | ||
'created_at', | ||
'updated_at', | ||
]; | ||
|
||
public function airfield(): BelongsTo | ||
{ | ||
return $this->belongsTo(Airfield::class); | ||
} | ||
|
||
public function scopeActive(Builder $query): Builder | ||
{ | ||
return $query | ||
->where(fn (Builder $query) => $query | ||
->where('start_date', '<', now()) | ||
->orWhereNull('start_date')) | ||
->where(fn (Builder $query) => $query | ||
->where('end_date', '>', now()) | ||
->orWhereNull('end_date')); | ||
} | ||
|
||
public function scopeExpired(Builder $query): Builder | ||
{ | ||
return $query->where('end_date', '<', now()); | ||
} | ||
} |
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37
database/migrations/2025_04_30_220010_create_smr_area_table.php
This file contains hidden or 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,37 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('smr_area', function (Blueprint $table) { | ||
$table->id()->primary(); | ||
$table->unsignedInteger('airfield_id'); | ||
$table->string('name')->nullable(); | ||
$table->string('source')->nullable(); | ||
$table->text('coordinates'); | ||
$table->dateTime('start_date')->nullable(); | ||
$table->dateTime('end_date')->nullable(); | ||
$table->timestamps(); | ||
|
||
$table->foreign('airfield_id') | ||
->references('id') | ||
->on('airfield') | ||
->cascadeOnDelete(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('smr_area'); | ||
} | ||
}; |
This file contains hidden or 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 hidden or 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 | ||
|
||
use App\Models\SmrArea; | ||
use Illuminate\Database\Seeder; | ||
|
||
class SmrAreaSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
*/ | ||
public function run(): void | ||
{ | ||
SmrArea::create([ | ||
'airfield_id' => 1, | ||
'coordinates' => str_repeat("COORD:N000.00.00.000:E000.00.00.000\n", 3), | ||
'start_date' => null, | ||
'end_date' => null, | ||
]); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
<?php | ||
|
||
return [ | ||
'activation' => [ | ||
'label' => 'Activation', | ||
'true' => 'Active', | ||
'false' => 'Inactive', | ||
], | ||
'expired' => 'Expired', | ||
]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.