Fix flight field bugs
This commit is contained in:
parent
f8f5a71564
commit
eb64f268d3
@ -375,7 +375,6 @@ class FlightController extends Controller
|
||||
protected function return_fields_view($flight)
|
||||
{
|
||||
$flight->refresh();
|
||||
|
||||
return view('admin.flights.flight_fields', [
|
||||
'flight' => $flight,
|
||||
'flight_fields' => $this->flightFieldRepo->all(),
|
||||
@ -383,13 +382,12 @@ class FlightController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $flight_id
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function field_values(Request $request)
|
||||
public function field_values($flight_id, Request $request)
|
||||
{
|
||||
$flight_id = $request->id;
|
||||
|
||||
$flight = $this->flightRepo->findWithoutFail($flight_id);
|
||||
if (empty($flight)) {
|
||||
Flash::error('Flight not found');
|
||||
@ -398,18 +396,21 @@ class FlightController extends Controller
|
||||
|
||||
// add custom field to flight
|
||||
if ($request->isMethod('post')) {
|
||||
Log::info('Adding new flight field, flight: '.$flight_id, $request->input());
|
||||
|
||||
$field = new FlightFieldValue;
|
||||
$field->flight_id = $flight_id;
|
||||
$field->name = $request->input('name');
|
||||
$field->value = $request->input('value');
|
||||
$field->save();
|
||||
} elseif ($request->isMethod('put')) {
|
||||
if(!$request->input('field_id')) {
|
||||
Log::info('Updating flight field, flight: '.$flight_id, $request->input());
|
||||
$field = FlightFieldValue::where('name', $request->input('name'))->first();
|
||||
if(!$field) {
|
||||
Log::info('Field not found, creating new');
|
||||
$field = new FlightFieldValue();
|
||||
$field->flight_id = $flight_id;
|
||||
$field->name = $request->input('name');
|
||||
} else {
|
||||
$field = FlightFieldValue::where('id', $request->input('field_id'))->first();
|
||||
}
|
||||
|
||||
$field->value = $request->input('value');
|
||||
@ -417,7 +418,8 @@ class FlightController extends Controller
|
||||
// update the field value
|
||||
} // remove custom field from flight
|
||||
elseif ($request->isMethod('delete')) {
|
||||
if($flight_id) {
|
||||
Log::info('Deleting flight field, flight: '.$flight_id, $request->input());
|
||||
if($flight_id && $request->input('field_id')) {
|
||||
FlightFieldValue::destroy($request->input('field_id'));
|
||||
}
|
||||
}
|
||||
@ -455,7 +457,11 @@ class FlightController extends Controller
|
||||
$fleetSvc = app(FleetService::class);
|
||||
|
||||
// add aircraft to flight
|
||||
$subfleet = $this->subfleetRepo->find($request->input('subfleet_id'));
|
||||
$subfleet = $this->subfleetRepo->findWithoutFail($request->subfleet_id);
|
||||
if(!$subfleet) {
|
||||
return $this->return_subfleet_view($flight);
|
||||
}
|
||||
|
||||
if ($request->isMethod('post')) {
|
||||
$fleetSvc->addSubfleetToFlight($subfleet, $flight);
|
||||
} // remove aircraft from flight
|
||||
|
@ -20,7 +20,7 @@ class Kernel extends HttpKernel
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\Spatie\Pjax\Middleware\FilterIfPjax::class,
|
||||
//\Spatie\Pjax\Middleware\FilterIfPjax::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
|
@ -100,7 +100,7 @@
|
||||
</body>
|
||||
|
||||
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/pjax@0.2.5/pjax.js"></script>
|
||||
{{--<script src="https://cdn.jsdelivr.net/npm/pjax@0.2.5/pjax.js"></script>--}}
|
||||
|
||||
<script src="{{ public_asset('/assets/admin/js/vendor.js') }}"></script>
|
||||
<script src="{{ public_asset('/assets/system/js/phpvms.js') }}"></script>
|
||||
|
@ -9,8 +9,21 @@
|
||||
</thead>
|
||||
@endif
|
||||
<tbody>
|
||||
@foreach($flight_fields as $field)
|
||||
@php
|
||||
#
|
||||
# A little nasty having logic like this in a template, but we need
|
||||
# to filter out the field values that have already been shown, since
|
||||
# they were values set because they had a FlightField parent
|
||||
#
|
||||
$shown = [];
|
||||
@endphp
|
||||
@foreach($flight_fields->concat($flight->field_values) as $field)
|
||||
@php
|
||||
if(in_array($field->name, $shown, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$shown[] = $field->name;
|
||||
$val_field = $flight->field_values->where('name', $field->name)->first();
|
||||
@endphp
|
||||
<tr>
|
||||
|
@ -63,12 +63,16 @@ $(document).ready(function () {
|
||||
setEditable();
|
||||
setFieldsEditable();
|
||||
|
||||
/*const pjax = new Pjax({
|
||||
elements: 'form[action]',
|
||||
selectors: ['.pjax_subfleet_form'],
|
||||
switches: {
|
||||
'#subfleet_flight_wrapper': Pjax.switches.replaceNode
|
||||
}
|
||||
/*new Pjax({
|
||||
elements: 'form[action].pjax_subfleet_form',
|
||||
selectors: ['div#subfleet_flight_wrapper'],
|
||||
history: false,
|
||||
});
|
||||
|
||||
new Pjax({
|
||||
elements: 'form[action].pjax_flight_fields',
|
||||
selectors: ['div#flight_fields_wrapper'],
|
||||
history: false
|
||||
});*/
|
||||
|
||||
$(document).on('submit', 'form.pjax_flight_fields', function (event) {
|
||||
|
Loading…
Reference in New Issue
Block a user