Skip to content

Commit

Permalink
Aircraft can be added without subfleet/block subfleet deletion if sti…
Browse files Browse the repository at this point in the history
…ll in use #128
  • Loading branch information
nabeelio committed Jan 9, 2018
1 parent 0e36849 commit cbdce35
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 13 deletions.
6 changes: 4 additions & 2 deletions app/Http/Controllers/Admin/AircraftController.php
Expand Up @@ -23,6 +23,7 @@ public function __construct(

/**
* Display a listing of the Aircraft.
* @throws \Prettus\Repository\Exceptions\RepositoryException
*/
public function index(Request $request)
{
Expand All @@ -46,11 +47,12 @@ public function create()

/**
* Store a newly created Aircraft in storage.
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function store(CreateAircraftRequest $request)
{
$input = $request->all();
$aircraft = $this->aircraftRepository->create($input);
$this->aircraftRepository->create($input);

Flash::success('Aircraft saved successfully.');
return redirect(route('admin.aircraft.index'));
Expand Down Expand Up @@ -93,6 +95,7 @@ public function edit($id)

/**
* Update the specified Aircraft in storage.
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function update($id, UpdateAircraftRequest $request)
{
Expand Down Expand Up @@ -126,5 +129,4 @@ public function destroy($id)
Flash::success('Aircraft deleted successfully.');
return redirect(route('admin.aircraft.index'));
}

}
17 changes: 15 additions & 2 deletions app/Http/Controllers/Admin/SubfleetController.php
Expand Up @@ -15,6 +15,7 @@
use App\Http\Requests\CreateSubfleetRequest;
use App\Http\Requests\UpdateSubfleetRequest;

use App\Repositories\AircraftRepository;
use App\Repositories\FareRepository;
use App\Repositories\SubfleetRepository;

Expand All @@ -23,19 +24,23 @@
class SubfleetController extends BaseController
{
/** @var SubfleetRepository */
private $subfleetRepo, $fareRepo, $fareSvc;
private $aircraftRepo, $subfleetRepo, $fareRepo, $fareSvc;

/**
* SubfleetController constructor.
*
* @param AircraftRepository $aircraftRepo
* @param SubfleetRepository $subfleetRepo
* @param FareRepository $fareRepo
* @param FareRepository $fareRepo
* @param FareService $fareSvc
*/
public function __construct(
AircraftRepository $aircraftRepo,
SubfleetRepository $subfleetRepo,
FareRepository $fareRepo,
FareService $fareSvc
) {
$this->aircraftRepo = $aircraftRepo;
$this->subfleetRepo = $subfleetRepo;
$this->fareRepo = $fareRepo;
$this->fareSvc = $fareSvc;
Expand Down Expand Up @@ -183,6 +188,14 @@ public function destroy($id)
return redirect(route('admin.subfleets.index'));
}

# Make sure no aircraft are assigned to this subfleet
# before trying to delete it, or else things might go boom
$aircraft = $this->aircraftRepo->findWhere(['subfleet_id' => $id], ['id']);
if($aircraft->count() > 0) {
Flash::error('There are aircraft still assigned to this subfleet, you can\'t delete it!')->important();
return redirect(route('admin.subfleets.index'));
}

$this->subfleetRepo->delete($id);

Flash::success('Subfleet deleted successfully.');
Expand Down
1 change: 1 addition & 0 deletions app/Models/Aircraft.php
Expand Up @@ -31,6 +31,7 @@ class Aircraft extends BaseModel
* @var array
*/
public static $rules = [
'subfleet_id' => 'required',
'name' => 'required',
];

Expand Down
18 changes: 18 additions & 0 deletions app/Models/Enums/GenericState.php
@@ -0,0 +1,18 @@
<?php

namespace App\Models\Enums;

/**
* Class GenericState
* @package App\Models\Enums
*/
class GenericState extends EnumBase
{
const INACTIVE = 0;
const ACTIVE = 1;

public static $labels = [
GenericState::INACTIVE => 'Inactive',
GenericState::ACTIVE => 'Active',
];
}
1 change: 1 addition & 0 deletions config/app.php
Expand Up @@ -118,6 +118,7 @@
'Yaml' => Symfony\Component\Yaml\Yaml::class,

# ENUMS
'GenericState' => App\Models\Enums\GenericState::class,
'UserState' => App\Models\Enums\UserState::class,
'PirepSource' => App\Models\Enums\PirepSource::class,
'PirepState' => App\Models\Enums\PirepState::class,
Expand Down
12 changes: 9 additions & 3 deletions resources/views/admin/aircraft/create.blade.php
Expand Up @@ -3,9 +3,15 @@
@section('content')
<div class="card border-blue-bottom">
<div class="content">
{!! Form::open(['route' => 'admin.aircraft.store']) !!}
@include('admin.aircraft.fields')
{!! Form::close() !!}
@if(!filled($subfleets))
<p class="text-center">
You must add a subfleet before you can add an aircraft!
</p>
@else
{!! Form::open(['route' => 'admin.aircraft.store']) !!}
@include('admin.aircraft.fields')
{!! Form::close() !!}
@endif
</div>
</div>
@endsection
6 changes: 3 additions & 3 deletions resources/views/admin/aircraft/table.blade.php
Expand Up @@ -11,7 +11,7 @@
@foreach($aircraft as $ac)
<tr>
<td>
@if($ac->subfleet_id)
@if($ac->subfleet_id && $ac->subfleet)
<a href="{!! route('admin.subfleets.edit', [$ac->subfleet_id]) !!}">
{!! $ac->subfleet->name !!}
</a>
Expand All @@ -23,8 +23,8 @@
<td style="text-align: center;">{!! $ac->icao !!}</td>
<td style="text-align: center;">{!! $ac->registration !!}</td>
<td style="text-align: center;">
@if($ac->active == 1)
<span class="label label-success">Active</span>
@if($ac->active == GenericState::ACTIVE)
<span class="label label-success">{!! GenericState::label($ac->active); !!}</span>
@else
<span class="label label-default">Inactive</span>
@endif
Expand Down
12 changes: 9 additions & 3 deletions resources/views/admin/subfleets/create.blade.php
Expand Up @@ -3,9 +3,15 @@
@section('content')
<div class="card border-blue-bottom">
<div class="content">
{!! Form::open(['route' => 'admin.subfleets.store']) !!}
@include('admin.subfleets.fields')
{!! Form::close() !!}
@if(!filled($airlines))
<p class="text-center">
You must add an airline before you can add a subfleet!
</p>
@else
{!! Form::open(['route' => 'admin.subfleets.store']) !!}
@include('admin.subfleets.fields')
{!! Form::close() !!}
@endif
</div>
</div>
@endsection

0 comments on commit cbdce35

Please sign in to comment.