Add flight time to flight create/edit form
This commit is contained in:
parent
246c828d7a
commit
ad4259625c
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Facades\Utils;
|
||||
use App\Models\Enums\FlightType;
|
||||
use App\Models\Flight;
|
||||
use App\Models\FlightFields;
|
||||
@ -16,6 +17,7 @@ use App\Repositories\SubfleetRepository;
|
||||
use App\Services\FareService;
|
||||
use App\Services\FlightService;
|
||||
|
||||
use App\Support\Units\Time;
|
||||
use Illuminate\Http\Request;
|
||||
use Flash;
|
||||
use Response;
|
||||
@ -121,7 +123,11 @@ class FlightController extends BaseController
|
||||
return redirect()->back()->withInput($request->all());
|
||||
}
|
||||
|
||||
$input['active'] = get_truth_state($input['active']);;
|
||||
$input['active'] = get_truth_state($input['active']);
|
||||
|
||||
$time = new Time($input['minutes'], $input['hours']);
|
||||
$input['flight_time'] = $time->getMinutes();
|
||||
|
||||
$flight = $this->flightRepo->create($input);
|
||||
|
||||
Flash::success('Flight saved successfully.');
|
||||
@ -155,12 +161,15 @@ class FlightController extends BaseController
|
||||
public function edit($id)
|
||||
{
|
||||
$flight = $this->flightRepo->findWithoutFail($id);
|
||||
|
||||
if (empty($flight)) {
|
||||
Flash::error('Flight not found');
|
||||
return redirect(route('admin.flights.index'));
|
||||
}
|
||||
|
||||
$time = new Time($flight->flight_time);
|
||||
$flight->hours = $time->hours;
|
||||
$flight->minutes = $time->minutes;
|
||||
|
||||
$avail_subfleets = $this->getAvailSubfleets($flight);
|
||||
return view('admin.flights.edit', [
|
||||
'flight' => $flight,
|
||||
@ -209,7 +218,12 @@ class FlightController extends BaseController
|
||||
return redirect()->back()->withInput($request->all());
|
||||
}
|
||||
|
||||
$input['flight_time'] = Time::init(
|
||||
$input['minutes'],
|
||||
$input['hours'])->getMinutes();
|
||||
|
||||
$input['active'] = get_truth_state($input['active']);
|
||||
|
||||
$this->flightRepo->update($input, $id);
|
||||
|
||||
Flash::success('Flight updated successfully.');
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Services\UserService;
|
||||
use App\Support\Units\Time;
|
||||
use Log;
|
||||
use Flash;
|
||||
use Response;
|
||||
@ -184,9 +185,9 @@ class PirepController extends BaseController
|
||||
return redirect(route('admin.pireps.index'));
|
||||
}
|
||||
|
||||
$hms = Utils::minutesToTimeParts($pirep->flight_time);
|
||||
$pirep->hours = $hms['h'];
|
||||
$pirep->minutes = $hms['m'];
|
||||
$time = new Time($pirep->flight_time);
|
||||
$pirep->hours = $time->hours;
|
||||
$pirep->minutes = $time->minutes;
|
||||
|
||||
# Can we modify?
|
||||
$read_only = false;
|
||||
@ -208,6 +209,7 @@ class PirepController extends BaseController
|
||||
* @param UpdatePirepRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function update($id, UpdatePirepRequest $request)
|
||||
{
|
||||
@ -224,9 +226,9 @@ class PirepController extends BaseController
|
||||
$attrs = $request->all();
|
||||
|
||||
# Fix the time
|
||||
$hours = (int) $attrs['hours'];
|
||||
$minutes = (int) $attrs['minutes'];
|
||||
$attrs['flight_time'] = Utils::hoursToMinutes($hours) + $minutes;
|
||||
$attrs['flight_time'] = Time::init(
|
||||
$attrs['minutes'],
|
||||
$attrs['hours'])->getMinutes();
|
||||
|
||||
$pirep = $this->pirepRepo->update($attrs, $id);
|
||||
|
||||
|
@ -12,6 +12,16 @@ class Time implements Arrayable
|
||||
public $hours,
|
||||
$minutes;
|
||||
|
||||
/**
|
||||
* @param $minutes
|
||||
* @param $hours
|
||||
* @return static
|
||||
*/
|
||||
public static function init($minutes, $hours)
|
||||
{
|
||||
return new Time($minutes, $hours);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass just minutes to figure out how many hours
|
||||
* Or both hours and minutes
|
||||
|
@ -28,10 +28,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
SAME ROW
|
||||
-->
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="form-group col-sm-3">
|
||||
@ -64,25 +60,37 @@ SAME ROW
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="form-group col-sm-3">
|
||||
<div class="form-group col-sm-2">
|
||||
{!! Form::label('dpt_time', 'Departure Time:') !!}
|
||||
{!! Form::text('dpt_time', null, ['class' => 'form-control']) !!}
|
||||
<p class="text-danger">{{ $errors->first('dpt_time') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-3">
|
||||
<div class="form-group col-sm-2">
|
||||
{!! Form::label('arr_time', 'Arrival Time:') !!}
|
||||
{!! Form::text('arr_time', null, ['class' => 'form-control']) !!}
|
||||
<p class="text-danger">{{ $errors->first('arr_time') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-3">
|
||||
<div class="form-group col-sm-4">
|
||||
{!! Form::label('flight_time', 'Flight Time (hours & minutes):') !!}
|
||||
<div style="float: left">
|
||||
{!! Form::number('hours', null, ['class' => 'form-control', 'placeholder' => 'hours']) !!}
|
||||
</div>
|
||||
<div style="float: left">
|
||||
{!! Form::number('minutes', null, ['class' => 'form-control', 'placeholder' => 'minutes']) !!}
|
||||
<p class="text-danger">{{ $errors->first('hours') }}</p>
|
||||
<p class="text-danger">{{ $errors->first('minutes') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-2">
|
||||
{!! Form::label('level', 'Flight Level:') !!}
|
||||
{!! Form::text('level', null, ['class' => 'form-control']) !!}
|
||||
<p class="text-danger">{{ $errors->first('level') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-3">
|
||||
<div class="form-group col-sm-2">
|
||||
{!! Form::label('distance', 'Distance:') !!} <span class="small">in miles</span>
|
||||
{!! Form::text('distance', null, ['class' => 'form-control']) !!}
|
||||
<p class="text-danger">{{ $errors->first('distance') }}</p>
|
||||
|
Loading…
Reference in New Issue
Block a user