Convert aircraft active to more detailed status #134

This commit is contained in:
Nabeel Shahzad 2018-02-23 16:37:10 -06:00
parent 709aec83e2
commit 910c0e0eab
9 changed files with 91 additions and 34 deletions

View File

@ -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'];

View File

@ -1,6 +1,7 @@
<?php
use App\Models\Enums\AircraftState;
use App\Models\Enums\AircraftStatus;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
@ -19,7 +20,7 @@ class CreateAircraftsTable extends Migration
$table->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();

View File

@ -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

View File

@ -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.');

View File

@ -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
*/

View 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',
];
}

View File

@ -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()

View File

@ -33,14 +33,12 @@
{!! Form::text('registration', null, ['class' => 'form-control']) !!}
<p class="text-danger">{{ $errors->first('registration') }}</p>
</div>
<!-- Active Field -->
<div class="form-group col-6">
{!! Form::label('active', 'Active:') !!}
<br />
<label class="checkbox-inline">
{!! Form::hidden('active', 0) !!}
{!! Form::checkbox('active') !!}
</label>
<div class="form-group col-sm-6">
{!! Form::label('status', 'Status:') !!}
{!! Form::select('status', $statuses, null, ['class' => 'form-control select2', 'placeholder' => 'Select Status']) !!}
<p class="text-danger">{{ $errors->first('subfleet_id') }}</p>
</div>
</div>
<div class="row">

View File

@ -2,6 +2,7 @@
<thead>
<th>Name</th>
<th>Subfleet</th>
<th style="text-align: center;">Location</th>
{{--<th style="text-align: center;">ICAO</th>--}}
<th style="text-align: center;">Registration</th>
<th style="text-align: center;">Hours</th>
@ -21,16 +22,20 @@
-
@endif
</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;">
{!! Utils::minutesToTimeString($ac->flight_hours) !!}
</td>
<td style="text-align: center;">
@if($ac->active == GenericState::ACTIVE)
<span class="label label-success">{!! GenericState::label($ac->active); !!}</span>
@if($ac->status == \App\Models\Enums\AircraftStatus::ACTIVE)
<span class="label label-success">{!! \App\Models\Enums\AircraftStatus::label($ac->status); !!}</span>
@else
<span class="label label-default">Inactive</span>
<span class="label label-default">
{!! \App\Models\Enums\AircraftStatus::label($ac->status) !!}
</span>
@endif
</td>
<td style="width: 10%; text-align: right;">