Convert aircraft active to more detailed status #134
This commit is contained in:
@@ -15,7 +15,8 @@ $factory->define(App\Models\Aircraft::class, function (Faker $faker) {
|
|||||||
'name' => $faker->unique()->text(50),
|
'name' => $faker->unique()->text(50),
|
||||||
'registration' => $faker->unique()->text(10),
|
'registration' => $faker->unique()->text(10),
|
||||||
'hex_code' => \App\Support\ICAO::createHexCode(),
|
'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'),
|
'created_at' => $faker->dateTimeBetween('-1 week', 'now'),
|
||||||
'updated_at' => function (array $pirep) {
|
'updated_at' => function (array $pirep) {
|
||||||
return $pirep['created_at'];
|
return $pirep['created_at'];
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Enums\AircraftState;
|
use App\Models\Enums\AircraftState;
|
||||||
|
use App\Models\Enums\AircraftStatus;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ class CreateAircraftsTable extends Migration
|
|||||||
$table->string('hex_code', 10)->nullable();
|
$table->string('hex_code', 10)->nullable();
|
||||||
$table->unsignedDecimal('zfw')->nullable()->default(0);
|
$table->unsignedDecimal('zfw')->nullable()->default(0);
|
||||||
$table->unsignedBigInteger('flight_time')->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->unsignedTinyInteger('state')->default(AircraftState::PARKED);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
||||||
|
|||||||
@@ -150,16 +150,28 @@ airports:
|
|||||||
aircraft:
|
aircraft:
|
||||||
- id: 1
|
- id: 1
|
||||||
subfleet_id: 1
|
subfleet_id: 1
|
||||||
name: Boeing 747-400
|
airport_id: KJFK
|
||||||
|
name: Boeing 747-438
|
||||||
registration: 001Z
|
registration: 001Z
|
||||||
|
status: 1
|
||||||
- id: 2
|
- id: 2
|
||||||
subfleet_id: 2
|
subfleet_id: 2
|
||||||
|
airport_id: LGRP
|
||||||
name: Boeing 777-200
|
name: Boeing 777-200
|
||||||
registration: C202
|
registration: C202
|
||||||
|
status: 1
|
||||||
- id: 3
|
- id: 3
|
||||||
subfleet_id: 1
|
subfleet_id: 1
|
||||||
|
airport_id: KAUS
|
||||||
name: Boeing 747-412
|
name: Boeing 747-412
|
||||||
registration: S2333
|
registration: S2333
|
||||||
|
status: 1
|
||||||
|
- id: 4
|
||||||
|
subfleet_id: 1
|
||||||
|
airport_id: KAUS
|
||||||
|
name: Boeing 747-436 RETIRED
|
||||||
|
registration:
|
||||||
|
status: 2
|
||||||
|
|
||||||
fares:
|
fares:
|
||||||
- id: 1
|
- id: 1
|
||||||
@@ -181,13 +193,18 @@ fares:
|
|||||||
subfleets:
|
subfleets:
|
||||||
- id: 1
|
- id: 1
|
||||||
airline_id: 1
|
airline_id: 1
|
||||||
name: 747-400 Winglets
|
name: 747-43X RB211-524G
|
||||||
type: 744W
|
type: 744-3X-RB211
|
||||||
ground_handling_multiplier: 200
|
ground_handling_multiplier: 200
|
||||||
- id: 2
|
- id: 2
|
||||||
airline_id: 1
|
airline_id: 1
|
||||||
name: 777-200 LR
|
name: 777-222ER GE90-76B
|
||||||
type: 772-LR
|
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
|
ground_handling_multiplier: 150
|
||||||
|
|
||||||
# add a few mods to aircraft and fares
|
# add a few mods to aircraft and fares
|
||||||
@@ -296,7 +313,7 @@ pireps:
|
|||||||
airline_id: 1
|
airline_id: 1
|
||||||
flight_id: flightid_2
|
flight_id: flightid_2
|
||||||
flight_number: 101
|
flight_number: 101
|
||||||
aircraft_id: 1
|
aircraft_id: 2
|
||||||
dpt_airport_id: LGRP
|
dpt_airport_id: LGRP
|
||||||
arr_airport_id: LGRP
|
arr_airport_id: LGRP
|
||||||
flight_time: 180 # 6 hours
|
flight_time: 180 # 6 hours
|
||||||
@@ -312,7 +329,7 @@ pireps:
|
|||||||
airline_id: 1
|
airline_id: 1
|
||||||
flight_id: flightid_2
|
flight_id: flightid_2
|
||||||
flight_number: 101
|
flight_number: 101
|
||||||
aircraft_id: 1
|
aircraft_id: 3
|
||||||
dpt_airport_id: KJFK
|
dpt_airport_id: KJFK
|
||||||
arr_airport_id: KAUS
|
arr_airport_id: KAUS
|
||||||
flight_time: 180 # 6 hours
|
flight_time: 180 # 6 hours
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Http\Requests\CreateAircraftRequest;
|
use App\Http\Requests\CreateAircraftRequest;
|
||||||
use App\Http\Requests\UpdateAircraftRequest;
|
use App\Http\Requests\UpdateAircraftRequest;
|
||||||
|
use App\Models\Enums\AircraftStatus;
|
||||||
use App\Models\Subfleet;
|
use App\Models\Subfleet;
|
||||||
use App\Repositories\AircraftRepository;
|
use App\Repositories\AircraftRepository;
|
||||||
use Flash;
|
use Flash;
|
||||||
@@ -32,7 +33,7 @@ class AircraftController extends BaseController
|
|||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->aircraftRepository->pushCriteria(new RequestCriteria($request));
|
$this->aircraftRepository->pushCriteria(new RequestCriteria($request));
|
||||||
$aircraft = $this->aircraftRepository->all();
|
$aircraft = $this->aircraftRepository->orderBy('name', 'asc')->all();
|
||||||
|
|
||||||
return view('admin.aircraft.index', [
|
return view('admin.aircraft.index', [
|
||||||
'aircraft' => $aircraft
|
'aircraft' => $aircraft
|
||||||
@@ -46,6 +47,7 @@ class AircraftController extends BaseController
|
|||||||
{
|
{
|
||||||
return view('admin.aircraft.create', [
|
return view('admin.aircraft.create', [
|
||||||
'subfleets' => Subfleet::all()->pluck('name', 'id'),
|
'subfleets' => Subfleet::all()->pluck('name', 'id'),
|
||||||
|
'statuses' => AircraftStatus::select(true),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,9 +58,6 @@ class AircraftController extends BaseController
|
|||||||
public function store(CreateAircraftRequest $request)
|
public function store(CreateAircraftRequest $request)
|
||||||
{
|
{
|
||||||
$attrs = $request->all();
|
$attrs = $request->all();
|
||||||
|
|
||||||
$attrs['active'] = get_truth_state($attrs['active']);
|
|
||||||
|
|
||||||
$aircraft = $this->aircraftRepository->create($attrs);
|
$aircraft = $this->aircraftRepository->create($attrs);
|
||||||
|
|
||||||
Flash::success('Aircraft saved successfully.');
|
Flash::success('Aircraft saved successfully.');
|
||||||
@@ -96,6 +95,7 @@ class AircraftController extends BaseController
|
|||||||
|
|
||||||
return view('admin.aircraft.edit', [
|
return view('admin.aircraft.edit', [
|
||||||
'subfleets' => Subfleet::all()->pluck('name', 'id'),
|
'subfleets' => Subfleet::all()->pluck('name', 'id'),
|
||||||
|
'statuses' => AircraftStatus::select(true),
|
||||||
'aircraft' => $aircraft,
|
'aircraft' => $aircraft,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -114,8 +114,6 @@ class AircraftController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$attrs = $request->all();
|
$attrs = $request->all();
|
||||||
$attrs['active'] = get_truth_state($attrs['active']);
|
|
||||||
|
|
||||||
$this->aircraftRepository->update($attrs, $id);
|
$this->aircraftRepository->update($attrs, $id);
|
||||||
|
|
||||||
Flash::success('Aircraft updated successfully.');
|
Flash::success('Aircraft updated successfully.');
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Enums\AircraftStatus;
|
||||||
use App\Support\ICAO;
|
use App\Support\ICAO;
|
||||||
|
|
||||||
class Aircraft extends BaseModel
|
class Aircraft extends BaseModel
|
||||||
@@ -16,7 +17,8 @@ class Aircraft extends BaseModel
|
|||||||
'registration',
|
'registration',
|
||||||
'hex_code',
|
'hex_code',
|
||||||
'zfw',
|
'zfw',
|
||||||
'active',
|
'status',
|
||||||
|
'state',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,7 +29,8 @@ class Aircraft extends BaseModel
|
|||||||
protected $casts = [
|
protected $casts = [
|
||||||
'subfleet_id' => 'integer',
|
'subfleet_id' => 'integer',
|
||||||
'zfw' => 'float',
|
'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
|
* foreign keys
|
||||||
*/
|
*/
|
||||||
|
|||||||
24
app/Models/Enums/AircraftStatus.php
Normal file
24
app/Models/Enums/AircraftStatus.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AircraftState
|
||||||
|
* @package App\Models\Enums
|
||||||
|
*/
|
||||||
|
class AircraftStatus extends EnumBase
|
||||||
|
{
|
||||||
|
public const STORED = 0;
|
||||||
|
public const ACTIVE = 1;
|
||||||
|
public const RETIRED = 2;
|
||||||
|
public const SCRAPPED = 3;
|
||||||
|
public const WRITTEN_OFF = 4;
|
||||||
|
|
||||||
|
public static $labels = [
|
||||||
|
AircraftStatus::STORED => 'Stored',
|
||||||
|
AircraftStatus::ACTIVE => 'Active',
|
||||||
|
AircraftStatus::RETIRED => 'Retired',
|
||||||
|
AircraftStatus::SCRAPPED => 'Scrapped',
|
||||||
|
AircraftStatus::WRITTEN_OFF => 'Written Off',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Enums\AircraftStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Subfleet
|
* Class Subfleet
|
||||||
* @package App\Models
|
* @package App\Models
|
||||||
@@ -42,8 +44,8 @@ class Subfleet extends BaseModel
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify some fields on the fly. Make sure the subfleet
|
* Modify some fields on the fly. Make sure the subfleet names don't
|
||||||
* names don't have spaces in them.
|
* have spaces in them, so the csv import/export can use the types
|
||||||
*/
|
*/
|
||||||
public static function boot()
|
public static function boot()
|
||||||
{
|
{
|
||||||
@@ -51,7 +53,8 @@ class Subfleet extends BaseModel
|
|||||||
|
|
||||||
static::creating(function ($model) {
|
static::creating(function ($model) {
|
||||||
if (filled($model->type)) {
|
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)) {
|
if(!filled($model->ground_handling_multiplier)) {
|
||||||
@@ -61,7 +64,8 @@ class Subfleet extends BaseModel
|
|||||||
|
|
||||||
static::updating(function ($model) {
|
static::updating(function ($model) {
|
||||||
if (filled($model->type)) {
|
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()
|
public function aircraft()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Aircraft::class, 'subfleet_id');
|
return $this->hasMany(Aircraft::class, 'subfleet_id')
|
||||||
|
->where('status', AircraftStatus::ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function airline()
|
public function airline()
|
||||||
|
|||||||
@@ -33,14 +33,12 @@
|
|||||||
{!! Form::text('registration', null, ['class' => 'form-control']) !!}
|
{!! Form::text('registration', null, ['class' => 'form-control']) !!}
|
||||||
<p class="text-danger">{{ $errors->first('registration') }}</p>
|
<p class="text-danger">{{ $errors->first('registration') }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Active Field -->
|
<!-- Active Field -->
|
||||||
<div class="form-group col-6">
|
<div class="form-group col-sm-6">
|
||||||
{!! Form::label('active', 'Active:') !!}
|
{!! Form::label('status', 'Status:') !!}
|
||||||
<br />
|
{!! Form::select('status', $statuses, null, ['class' => 'form-control select2', 'placeholder' => 'Select Status']) !!}
|
||||||
<label class="checkbox-inline">
|
<p class="text-danger">{{ $errors->first('subfleet_id') }}</p>
|
||||||
{!! Form::hidden('active', 0) !!}
|
|
||||||
{!! Form::checkbox('active') !!}
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Subfleet</th>
|
<th>Subfleet</th>
|
||||||
|
<th style="text-align: center;">Location</th>
|
||||||
{{--<th style="text-align: center;">ICAO</th>--}}
|
{{--<th style="text-align: center;">ICAO</th>--}}
|
||||||
<th style="text-align: center;">Registration</th>
|
<th style="text-align: center;">Registration</th>
|
||||||
<th style="text-align: center;">Hours</th>
|
<th style="text-align: center;">Hours</th>
|
||||||
@@ -21,16 +22,20 @@
|
|||||||
-
|
-
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">{!! $ac->icao !!}</td>
|
|
||||||
{{--<td style="text-align: center;">{!! $ac->registration !!}</td>--}}
|
<td style="text-align: center;">{!! $ac->airport_id !!}</td>
|
||||||
|
|
||||||
|
<td style="text-align: center;">{!! $ac->registration !!}</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
{!! Utils::minutesToTimeString($ac->flight_hours) !!}
|
{!! Utils::minutesToTimeString($ac->flight_hours) !!}
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
@if($ac->active == GenericState::ACTIVE)
|
@if($ac->status == \App\Models\Enums\AircraftStatus::ACTIVE)
|
||||||
<span class="label label-success">{!! GenericState::label($ac->active); !!}</span>
|
<span class="label label-success">{!! \App\Models\Enums\AircraftStatus::label($ac->status); !!}</span>
|
||||||
@else
|
@else
|
||||||
<span class="label label-default">Inactive</span>
|
<span class="label label-default">
|
||||||
|
{!! \App\Models\Enums\AircraftStatus::label($ac->status) !!}
|
||||||
|
</span>
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td style="width: 10%; text-align: right;">
|
<td style="width: 10%; text-align: right;">
|
||||||
|
|||||||
Reference in New Issue
Block a user