diff --git a/app/Database/factories/AircraftFactory.php b/app/Database/factories/AircraftFactory.php index 22cb3d9a..85cc45d5 100644 --- a/app/Database/factories/AircraftFactory.php +++ b/app/Database/factories/AircraftFactory.php @@ -15,7 +15,8 @@ $factory->define(App\Models\Aircraft::class, function (Faker $faker) { 'name' => $faker->unique()->text(50), 'registration' => $faker->unique()->text(10), 'hex_code' => \App\Support\ICAO::createHexCode(), - 'active' => true, + 'status' => \App\Models\Enums\AircraftStatus::ACTIVE, + 'state' => \App\Models\Enums\AircraftState::PARKED, 'created_at' => $faker->dateTimeBetween('-1 week', 'now'), 'updated_at' => function (array $pirep) { return $pirep['created_at']; diff --git a/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php b/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php index 7174da30..68cbc1f8 100644 --- a/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php +++ b/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php @@ -1,6 +1,7 @@ string('hex_code', 10)->nullable(); $table->unsignedDecimal('zfw')->nullable()->default(0); $table->unsignedBigInteger('flight_time')->nullable()->default(0); - $table->boolean('active')->default(true); + $table->unsignedTinyInteger('status')->default(AircraftStatus::ACTIVE); $table->unsignedTinyInteger('state')->default(AircraftState::PARKED); $table->timestamps(); diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/sample.yml index 1ae98427..52e20fcc 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/sample.yml @@ -150,16 +150,28 @@ airports: aircraft: - id: 1 subfleet_id: 1 - name: Boeing 747-400 + airport_id: KJFK + name: Boeing 747-438 registration: 001Z + status: 1 - id: 2 subfleet_id: 2 + airport_id: LGRP name: Boeing 777-200 registration: C202 + status: 1 - id: 3 subfleet_id: 1 + airport_id: KAUS name: Boeing 747-412 registration: S2333 + status: 1 + - id: 4 + subfleet_id: 1 + airport_id: KAUS + name: Boeing 747-436 RETIRED + registration: + status: 2 fares: - id: 1 @@ -181,13 +193,18 @@ fares: subfleets: - id: 1 airline_id: 1 - name: 747-400 Winglets - type: 744W + name: 747-43X RB211-524G + type: 744-3X-RB211 ground_handling_multiplier: 200 - id: 2 airline_id: 1 - name: 777-200 LR - type: 772-LR + name: 777-222ER GE90-76B + type: 772-22ER-GE90-76B + ground_handling_multiplier: 150 + - id: 3 + airline_id: 1 + name: 777-367 ER GE90-115B + type: 772-36ER-GE90-115B ground_handling_multiplier: 150 # add a few mods to aircraft and fares @@ -296,7 +313,7 @@ pireps: airline_id: 1 flight_id: flightid_2 flight_number: 101 - aircraft_id: 1 + aircraft_id: 2 dpt_airport_id: LGRP arr_airport_id: LGRP flight_time: 180 # 6 hours @@ -312,7 +329,7 @@ pireps: airline_id: 1 flight_id: flightid_2 flight_number: 101 - aircraft_id: 1 + aircraft_id: 3 dpt_airport_id: KJFK arr_airport_id: KAUS flight_time: 180 # 6 hours diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index faeed858..9bd22c95 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateAircraftRequest; use App\Http\Requests\UpdateAircraftRequest; +use App\Models\Enums\AircraftStatus; use App\Models\Subfleet; use App\Repositories\AircraftRepository; use Flash; @@ -32,7 +33,7 @@ class AircraftController extends BaseController public function index(Request $request) { $this->aircraftRepository->pushCriteria(new RequestCriteria($request)); - $aircraft = $this->aircraftRepository->all(); + $aircraft = $this->aircraftRepository->orderBy('name', 'asc')->all(); return view('admin.aircraft.index', [ 'aircraft' => $aircraft @@ -46,6 +47,7 @@ class AircraftController extends BaseController { return view('admin.aircraft.create', [ 'subfleets' => Subfleet::all()->pluck('name', 'id'), + 'statuses' => AircraftStatus::select(true), ]); } @@ -56,9 +58,6 @@ class AircraftController extends BaseController public function store(CreateAircraftRequest $request) { $attrs = $request->all(); - - $attrs['active'] = get_truth_state($attrs['active']); - $aircraft = $this->aircraftRepository->create($attrs); Flash::success('Aircraft saved successfully.'); @@ -96,6 +95,7 @@ class AircraftController extends BaseController return view('admin.aircraft.edit', [ 'subfleets' => Subfleet::all()->pluck('name', 'id'), + 'statuses' => AircraftStatus::select(true), 'aircraft' => $aircraft, ]); } @@ -114,8 +114,6 @@ class AircraftController extends BaseController } $attrs = $request->all(); - $attrs['active'] = get_truth_state($attrs['active']); - $this->aircraftRepository->update($attrs, $id); Flash::success('Aircraft updated successfully.'); diff --git a/app/Models/Aircraft.php b/app/Models/Aircraft.php index d53e4ba1..290a8773 100644 --- a/app/Models/Aircraft.php +++ b/app/Models/Aircraft.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Models\Enums\AircraftStatus; use App\Support\ICAO; class Aircraft extends BaseModel @@ -16,7 +17,8 @@ class Aircraft extends BaseModel 'registration', 'hex_code', 'zfw', - 'active', + 'status', + 'state', ]; /** @@ -27,7 +29,8 @@ class Aircraft extends BaseModel protected $casts = [ 'subfleet_id' => 'integer', 'zfw' => 'float', - 'active' => 'boolean', + 'status' => 'integer', + 'state' => 'integer', ]; /** @@ -57,6 +60,11 @@ class Aircraft extends BaseModel }); } + public function getActiveAttribute() + { + return $this->status === AircraftStatus::ACTIVE; + } + /** * foreign keys */ diff --git a/app/Models/Enums/AircraftStatus.php b/app/Models/Enums/AircraftStatus.php new file mode 100644 index 00000000..8f2705c0 --- /dev/null +++ b/app/Models/Enums/AircraftStatus.php @@ -0,0 +1,24 @@ + 'Stored', + AircraftStatus::ACTIVE => 'Active', + AircraftStatus::RETIRED => 'Retired', + AircraftStatus::SCRAPPED => 'Scrapped', + AircraftStatus::WRITTEN_OFF => 'Written Off', + ]; +} diff --git a/app/Models/Subfleet.php b/app/Models/Subfleet.php index 616095ad..db04ad97 100644 --- a/app/Models/Subfleet.php +++ b/app/Models/Subfleet.php @@ -2,6 +2,8 @@ namespace App\Models; +use App\Models\Enums\AircraftStatus; + /** * Class Subfleet * @package App\Models @@ -42,8 +44,8 @@ class Subfleet extends BaseModel ]; /** - * Modify some fields on the fly. Make sure the subfleet - * names don't have spaces in them. + * Modify some fields on the fly. Make sure the subfleet names don't + * have spaces in them, so the csv import/export can use the types */ public static function boot() { @@ -51,7 +53,8 @@ class Subfleet extends BaseModel static::creating(function ($model) { if (filled($model->type)) { - $model->type = str_replace(' ', '_', $model->type); + $model->type = str_replace(' ', '-', $model->type); + $model->type = str_replace(',', '', $model->type); } if(!filled($model->ground_handling_multiplier)) { @@ -61,7 +64,8 @@ class Subfleet extends BaseModel static::updating(function ($model) { if (filled($model->type)) { - $model->type = str_replace(' ', '_', $model->type); + $model->type = str_replace(' ', '-', $model->type); + $model->type = str_replace(',', '', $model->type); } }); } @@ -72,7 +76,8 @@ class Subfleet extends BaseModel public function aircraft() { - return $this->hasMany(Aircraft::class, 'subfleet_id'); + return $this->hasMany(Aircraft::class, 'subfleet_id') + ->where('status', AircraftStatus::ACTIVE); } public function airline() diff --git a/resources/views/admin/aircraft/fields.blade.php b/resources/views/admin/aircraft/fields.blade.php index ed5561a6..e7239668 100644 --- a/resources/views/admin/aircraft/fields.blade.php +++ b/resources/views/admin/aircraft/fields.blade.php @@ -33,14 +33,12 @@ {!! Form::text('registration', null, ['class' => 'form-control']) !!}

{{ $errors->first('registration') }}

+ -
- {!! Form::label('active', 'Active:') !!} -
- +
+ {!! Form::label('status', 'Status:') !!} + {!! Form::select('status', $statuses, null, ['class' => 'form-control select2', 'placeholder' => 'Select Status']) !!} +

{{ $errors->first('subfleet_id') }}

diff --git a/resources/views/admin/aircraft/table.blade.php b/resources/views/admin/aircraft/table.blade.php index 9a4a56a0..6039d854 100644 --- a/resources/views/admin/aircraft/table.blade.php +++ b/resources/views/admin/aircraft/table.blade.php @@ -2,6 +2,7 @@ Name Subfleet + Location {{--ICAO--}} Registration Hours @@ -21,16 +22,20 @@ - @endif - {!! $ac->icao !!} - {{--{!! $ac->registration !!}--}} + + {!! $ac->airport_id !!} + + {!! $ac->registration !!} {!! Utils::minutesToTimeString($ac->flight_hours) !!} - @if($ac->active == GenericState::ACTIVE) - {!! GenericState::label($ac->active); !!} + @if($ac->status == \App\Models\Enums\AircraftStatus::ACTIVE) + {!! \App\Models\Enums\AircraftStatus::label($ac->status); !!} @else - Inactive + + {!! \App\Models\Enums\AircraftStatus::label($ac->status) !!} + @endif