Fix saving PIREPs as draft
This commit is contained in:
@@ -139,6 +139,10 @@ class PirepController extends Controller
|
|||||||
protected function saveFares(Pirep $pirep, Request $request)
|
protected function saveFares(Pirep $pirep, Request $request)
|
||||||
{
|
{
|
||||||
$fares = [];
|
$fares = [];
|
||||||
|
if (!$pirep->aircraft) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($pirep->aircraft->subfleet->fares as $fare) {
|
foreach ($pirep->aircraft->subfleet->fares as $fare) {
|
||||||
$field_name = 'fare_'.$fare->id;
|
$field_name = 'fare_'.$fare->id;
|
||||||
if (!$request->filled($field_name)) {
|
if (!$request->filled($field_name)) {
|
||||||
@@ -186,7 +190,6 @@ class PirepController extends Controller
|
|||||||
$pirep = $this->pirepRepo->find($id);
|
$pirep = $this->pirepRepo->find($id);
|
||||||
if (empty($pirep)) {
|
if (empty($pirep)) {
|
||||||
Flash::error('Pirep not found');
|
Flash::error('Pirep not found');
|
||||||
|
|
||||||
return redirect(route('frontend.pirep.index'));
|
return redirect(route('frontend.pirep.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,40 +247,45 @@ class PirepController extends Controller
|
|||||||
$pirep = new Pirep($request->post());
|
$pirep = new Pirep($request->post());
|
||||||
$pirep->user_id = Auth::user()->id;
|
$pirep->user_id = Auth::user()->id;
|
||||||
|
|
||||||
# Are they allowed at this airport?
|
$attrs = $request->all();
|
||||||
if (setting('pilots.only_flights_from_current')
|
$attrs['submit'] = strtolower($attrs['submit']);
|
||||||
&& Auth::user()->curr_airport_id !== $pirep->dpt_airport_id) {
|
|
||||||
return $this->flashError(
|
|
||||||
'You are currently not at the departure airport!',
|
|
||||||
'frontend.pireps.create'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Can they fly this aircraft?
|
if($attrs['submit'] === 'submit') {
|
||||||
if (setting('pireps.restrict_aircraft_to_rank', false)
|
# Are they allowed at this airport?
|
||||||
&& !$this->userSvc->aircraftAllowed(Auth::user(), $pirep->aircraft_id)) {
|
if (setting('pilots.only_flights_from_current')
|
||||||
return $this->flashError(
|
&& Auth::user()->curr_airport_id !== $pirep->dpt_airport_id) {
|
||||||
'You are not allowed to fly this aircraft!',
|
return $this->flashError(
|
||||||
'frontend.pireps.create'
|
'You are currently not at the departure airport!',
|
||||||
);
|
'frontend.pireps.create'
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
# is the aircraft in the right place?
|
# Can they fly this aircraft?
|
||||||
if (setting('pireps.only_aircraft_at_dpt_airport')
|
if (setting('pireps.restrict_aircraft_to_rank', false)
|
||||||
&& $pirep->aircraft_id !== $pirep->dpt_airport_id) {
|
&& !$this->userSvc->aircraftAllowed(Auth::user(), $pirep->aircraft_id)) {
|
||||||
return $this->flashError(
|
return $this->flashError(
|
||||||
'This aircraft is not positioned at the departure airport!',
|
'You are not allowed to fly this aircraft!',
|
||||||
'frontend.pireps.create'
|
'frontend.pireps.create'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Make sure this isn't a duplicate
|
# is the aircraft in the right place?
|
||||||
$dupe_pirep = $this->pirepSvc->findDuplicate($pirep);
|
if (setting('pireps.only_aircraft_at_dpt_airport')
|
||||||
if ($dupe_pirep !== false) {
|
&& $pirep->aircraft_id !== $pirep->dpt_airport_id) {
|
||||||
return $this->flashError(
|
return $this->flashError(
|
||||||
'This PIREP has already been filed.',
|
'This aircraft is not positioned at the departure airport!',
|
||||||
'frontend.pireps.create'
|
'frontend.pireps.create'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Make sure this isn't a duplicate
|
||||||
|
$dupe_pirep = $this->pirepSvc->findDuplicate($pirep);
|
||||||
|
if ($dupe_pirep !== false) {
|
||||||
|
return $this->flashError(
|
||||||
|
'This PIREP has already been filed.',
|
||||||
|
'frontend.pireps.create'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any special fields
|
// Any special fields
|
||||||
@@ -296,7 +304,7 @@ class PirepController extends Controller
|
|||||||
// Depending on the button they selected, set an initial state
|
// Depending on the button they selected, set an initial state
|
||||||
// Can be saved as a draft or just submitted
|
// Can be saved as a draft or just submitted
|
||||||
if ($attrs['submit'] === 'save') {
|
if ($attrs['submit'] === 'save') {
|
||||||
$pirep->status = PirepState::DRAFT;
|
$pirep->state = PirepState::DRAFT;
|
||||||
$pirep->save();
|
$pirep->save();
|
||||||
Flash::success('PIREP saved successfully.');
|
Flash::success('PIREP saved successfully.');
|
||||||
} else if ($attrs['submit'] === 'submit') {
|
} else if ($attrs['submit'] === 'submit') {
|
||||||
@@ -317,7 +325,6 @@ class PirepController extends Controller
|
|||||||
$pirep = $this->pirepRepo->findWithoutFail($id);
|
$pirep = $this->pirepRepo->findWithoutFail($id);
|
||||||
if (empty($pirep)) {
|
if (empty($pirep)) {
|
||||||
Flash::error('Pirep not found');
|
Flash::error('Pirep not found');
|
||||||
|
|
||||||
return redirect(route('frontend.pireps.index'));
|
return redirect(route('frontend.pireps.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,6 +370,7 @@ class PirepController extends Controller
|
|||||||
|
|
||||||
$orig_route = $pirep->route;
|
$orig_route = $pirep->route;
|
||||||
$attrs = $request->all();
|
$attrs = $request->all();
|
||||||
|
$attrs['submit'] = strtolower($attrs['submit']);
|
||||||
|
|
||||||
# Fix the time
|
# Fix the time
|
||||||
$attrs['flight_time'] = Time::init(
|
$attrs['flight_time'] = Time::init(
|
||||||
@@ -384,7 +392,7 @@ class PirepController extends Controller
|
|||||||
} else if($attrs['submit'] === 'submit') {
|
} else if($attrs['submit'] === 'submit') {
|
||||||
$this->pirepSvc->submit($pirep);
|
$this->pirepSvc->submit($pirep);
|
||||||
Flash::success('PIREP submitted!');
|
Flash::success('PIREP submitted!');
|
||||||
} else if($attrs['submit'] === 'cancel') {
|
} else if($attrs['submit'] === 'delete' || $attrs['submit'] === 'cancel') {
|
||||||
$this->pirepRepo->update([
|
$this->pirepRepo->update([
|
||||||
'state' => PirepState::CANCELLED,
|
'state' => PirepState::CANCELLED,
|
||||||
'status' => PirepStatus::CANCELLED,
|
'status' => PirepStatus::CANCELLED,
|
||||||
|
|||||||
@@ -26,6 +26,17 @@ class CreatePirepRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
|
// Don't run validations if it's just being saved
|
||||||
|
$action = strtolower(request('submit', 'submit'));
|
||||||
|
if($action === 'save') {
|
||||||
|
return [
|
||||||
|
'airline_id' => 'required|exists:airlines,id',
|
||||||
|
'flight_number' => 'required',
|
||||||
|
'dpt_airport_id' => 'required',
|
||||||
|
'arr_airport_id' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$field_rules = Pirep::$rules;
|
$field_rules = Pirep::$rules;
|
||||||
|
|
||||||
$field_rules['hours'] = 'nullable|integer';
|
$field_rules['hours'] = 'nullable|integer';
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
namespace App\Http\Requests;
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
|
use App\Repositories\PirepFieldRepository;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Log;
|
||||||
|
|
||||||
class UpdatePirepRequest extends FormRequest
|
class UpdatePirepRequest extends FormRequest
|
||||||
{
|
{
|
||||||
@@ -24,6 +26,31 @@ class UpdatePirepRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return Pirep::$rules;
|
// Don't run validations if it's just being saved
|
||||||
|
$action = strtolower(request('submit', 'submit'));
|
||||||
|
if ($action === 'save' || $action === 'cancel' || $action === 'delete') {
|
||||||
|
return [
|
||||||
|
'airline_id' => 'required|exists:airlines,id',
|
||||||
|
'flight_number' => 'required',
|
||||||
|
'dpt_airport_id' => 'required',
|
||||||
|
'arr_airport_id' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$field_rules = Pirep::$rules;
|
||||||
|
|
||||||
|
$field_rules['hours'] = 'nullable|integer';
|
||||||
|
$field_rules['minutes'] = 'nullable|integer';
|
||||||
|
|
||||||
|
# Add the validation rules for the custom fields
|
||||||
|
$pirepFieldRepo = app(PirepFieldRepository::class);
|
||||||
|
|
||||||
|
$custom_fields = $pirepFieldRepo->all();
|
||||||
|
foreach ($custom_fields as $field) {
|
||||||
|
Log::info('field:', $field->toArray());
|
||||||
|
$field_rules[$field->slug] = $field->required ? 'required' : 'nullable';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $field_rules;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,10 +40,11 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
|||||||
* @property User user
|
* @property User user
|
||||||
* @property Flight|null flight
|
* @property Flight|null flight
|
||||||
* @property Collection fields
|
* @property Collection fields
|
||||||
|
* @property int status
|
||||||
|
* @property bool state
|
||||||
* @property Carbon submitted_at
|
* @property Carbon submitted_at
|
||||||
* @property Carbon created_at
|
* @property Carbon created_at
|
||||||
* @property Carbon updated_at
|
* @property Carbon updated_at
|
||||||
* @property bool state
|
|
||||||
* @property Acars position
|
* @property Acars position
|
||||||
* @property Acars[] acars
|
* @property Acars[] acars
|
||||||
* @package App\Models
|
* @package App\Models
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Widgets;
|
namespace App\Widgets;
|
||||||
|
|
||||||
use App\Interfaces\Widget;
|
use App\Interfaces\Widget;
|
||||||
|
use App\Models\Enums\PirepState;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,9 +23,17 @@ class LatestPireps extends Widget
|
|||||||
{
|
{
|
||||||
$pirepRepo = app(PirepRepository::class);
|
$pirepRepo = app(PirepRepository::class);
|
||||||
|
|
||||||
|
$pireps = $pirepRepo
|
||||||
|
->whereNotInOrder('state', [
|
||||||
|
PirepState::CANCELLED,
|
||||||
|
PirepState::DRAFT,
|
||||||
|
PirepState::IN_PROGRESS
|
||||||
|
], 'created_at', 'desc')
|
||||||
|
->recent($this->config['count']);
|
||||||
|
|
||||||
return view('widgets.latest_pireps', [
|
return view('widgets.latest_pireps', [
|
||||||
'config' => $this->config,
|
'config' => $this->config,
|
||||||
'pireps' => $pirepRepo->recent($this->config['count']),
|
'pireps' => $pireps,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ return [
|
|||||||
'download' => 'Download|Downloads',
|
'download' => 'Download|Downloads',
|
||||||
'from' => 'from',
|
'from' => 'from',
|
||||||
'to' => 'to',
|
'to' => 'to',
|
||||||
|
'state' => 'State',
|
||||||
'status' => 'Status',
|
'status' => 'Status',
|
||||||
'departure' => 'Departure',
|
'departure' => 'Departure',
|
||||||
'arrival' => 'Arrival',
|
'arrival' => 'Arrival',
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ return [
|
|||||||
'download' => 'Download|Downloads',
|
'download' => 'Download|Downloads',
|
||||||
'from' => 'da',
|
'from' => 'da',
|
||||||
'to' => 'a',
|
'to' => 'a',
|
||||||
|
'state' => 'Stato',
|
||||||
'status' => 'Stato',
|
'status' => 'Stato',
|
||||||
'departure' => 'Partenza',
|
'departure' => 'Partenza',
|
||||||
'arrival' => 'Arrivo',
|
'arrival' => 'Arrivo',
|
||||||
|
|||||||
@@ -38,11 +38,13 @@
|
|||||||
{{ Utils::minutesToTimeString($pirep->flight_time) }}
|
{{ Utils::minutesToTimeString($pirep->flight_time) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div><span class="description"><b>Aircraft</b>
|
@if($pirep->aircraft)
|
||||||
{{ $pirep->aircraft->registration }}
|
<div><span class="description"><b>Aircraft</b>
|
||||||
({{ $pirep->aircraft->name }})
|
{{ $pirep->aircraft->registration }}
|
||||||
</span>
|
({{ $pirep->aircraft->name }})
|
||||||
</div>
|
</span>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
@if(filled($pirep->level))
|
@if(filled($pirep->level))
|
||||||
<div>
|
<div>
|
||||||
<span class="description"><b>Flight Level</b>
|
<span class="description"><b>Flight Level</b>
|
||||||
|
|||||||
@@ -95,7 +95,7 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{{ url('/logout') }}">
|
<a class="nav-link" href="{{ url('/logout') }}">
|
||||||
<i class="fas fa-sign-out-alt"></i>
|
<i class="fas fa-sign-out-alt"></i>
|
||||||
<p>@lang('auth.logout')</p>
|
<p>@lang('common.logout')</p>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@@ -6,16 +6,7 @@
|
|||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<p>
|
<h2 style="margin-bottom: 5px;">{{$pirep->airline->code}}{{ $pirep->ident }}</h2>
|
||||||
<h2 style="margin-bottom: 5px;">{{$pirep->airline->code}}{{ $pirep->ident }}</h2>
|
|
||||||
<p>
|
|
||||||
@if($pirep->state === PirepState::IN_PROGRESS)
|
|
||||||
|
|
||||||
@else
|
|
||||||
@lang('pireps.arrived') {{$pirep->created_at->diffForHumans()}}
|
|
||||||
@endif
|
|
||||||
</p>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -101,6 +92,16 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td width="30%">@lang('common.state')</td>
|
||||||
|
<td>
|
||||||
|
<div class="badge badge-info">
|
||||||
|
{{ PirepState::label($pirep->state) }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td width="30%">@lang('common.status')</td>
|
<td width="30%">@lang('common.status')</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -33,7 +33,13 @@
|
|||||||
'id' => $pirep->arr_airport->icao
|
'id' => $pirep->arr_airport->icao
|
||||||
])}}">{{$pirep->arr_airport->icao}}</a>)
|
])}}">{{$pirep->arr_airport->icao}}</a>)
|
||||||
</td>
|
</td>
|
||||||
<td>{{ $pirep->aircraft->name }}</td>
|
<td>
|
||||||
|
@if($pirep->aircraft)
|
||||||
|
{{ $pirep->aircraft->name }}
|
||||||
|
@else
|
||||||
|
-
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
{{ (new \App\Support\Units\Time($pirep->flight_time)) }}
|
{{ (new \App\Support\Units\Time($pirep->flight_time)) }}
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
<td>
|
<td>
|
||||||
{{ $p->dpt_airport_id }}-
|
{{ $p->dpt_airport_id }}-
|
||||||
{{ $p->arr_airport_id }}
|
{{ $p->arr_airport_id }}
|
||||||
{{ $p->aircraft->name }}
|
@if($p->aircraft)
|
||||||
|
{{ $p->aircraft->name }}
|
||||||
|
@endif
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
Reference in New Issue
Block a user