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)
|
protected function return_fields_view($flight)
|
||||||
{
|
{
|
||||||
$flight->refresh();
|
$flight->refresh();
|
||||||
|
|
||||||
return view('admin.flights.flight_fields', [
|
return view('admin.flights.flight_fields', [
|
||||||
'flight' => $flight,
|
'flight' => $flight,
|
||||||
'flight_fields' => $this->flightFieldRepo->all(),
|
'flight_fields' => $this->flightFieldRepo->all(),
|
||||||
@ -383,13 +382,12 @@ class FlightController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param $flight_id
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return mixed
|
* @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);
|
$flight = $this->flightRepo->findWithoutFail($flight_id);
|
||||||
if (empty($flight)) {
|
if (empty($flight)) {
|
||||||
Flash::error('Flight not found');
|
Flash::error('Flight not found');
|
||||||
@ -398,18 +396,21 @@ class FlightController extends Controller
|
|||||||
|
|
||||||
// add custom field to flight
|
// add custom field to flight
|
||||||
if ($request->isMethod('post')) {
|
if ($request->isMethod('post')) {
|
||||||
|
Log::info('Adding new flight field, flight: '.$flight_id, $request->input());
|
||||||
|
|
||||||
$field = new FlightFieldValue;
|
$field = new FlightFieldValue;
|
||||||
$field->flight_id = $flight_id;
|
$field->flight_id = $flight_id;
|
||||||
$field->name = $request->input('name');
|
$field->name = $request->input('name');
|
||||||
$field->value = $request->input('value');
|
$field->value = $request->input('value');
|
||||||
$field->save();
|
$field->save();
|
||||||
} elseif ($request->isMethod('put')) {
|
} 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 = new FlightFieldValue();
|
||||||
$field->flight_id = $flight_id;
|
$field->flight_id = $flight_id;
|
||||||
$field->name = $request->input('name');
|
$field->name = $request->input('name');
|
||||||
} else {
|
|
||||||
$field = FlightFieldValue::where('id', $request->input('field_id'))->first();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$field->value = $request->input('value');
|
$field->value = $request->input('value');
|
||||||
@ -417,7 +418,8 @@ class FlightController extends Controller
|
|||||||
// update the field value
|
// update the field value
|
||||||
} // remove custom field from flight
|
} // remove custom field from flight
|
||||||
elseif ($request->isMethod('delete')) {
|
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'));
|
FlightFieldValue::destroy($request->input('field_id'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -455,7 +457,11 @@ class FlightController extends Controller
|
|||||||
$fleetSvc = app(FleetService::class);
|
$fleetSvc = app(FleetService::class);
|
||||||
|
|
||||||
// add aircraft to flight
|
// 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')) {
|
if ($request->isMethod('post')) {
|
||||||
$fleetSvc->addSubfleetToFlight($subfleet, $flight);
|
$fleetSvc->addSubfleetToFlight($subfleet, $flight);
|
||||||
} // remove aircraft from flight
|
} // remove aircraft from flight
|
||||||
|
@ -20,7 +20,7 @@ class Kernel extends HttpKernel
|
|||||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
\Spatie\Pjax\Middleware\FilterIfPjax::class,
|
//\Spatie\Pjax\Middleware\FilterIfPjax::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
|
@ -100,7 +100,7 @@
|
|||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
|
<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/admin/js/vendor.js') }}"></script>
|
||||||
<script src="{{ public_asset('/assets/system/js/phpvms.js') }}"></script>
|
<script src="{{ public_asset('/assets/system/js/phpvms.js') }}"></script>
|
||||||
|
@ -9,8 +9,21 @@
|
|||||||
</thead>
|
</thead>
|
||||||
@endif
|
@endif
|
||||||
<tbody>
|
<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
|
@php
|
||||||
|
if(in_array($field->name, $shown, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$shown[] = $field->name;
|
||||||
$val_field = $flight->field_values->where('name', $field->name)->first();
|
$val_field = $flight->field_values->where('name', $field->name)->first();
|
||||||
@endphp
|
@endphp
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -63,12 +63,16 @@ $(document).ready(function () {
|
|||||||
setEditable();
|
setEditable();
|
||||||
setFieldsEditable();
|
setFieldsEditable();
|
||||||
|
|
||||||
/*const pjax = new Pjax({
|
/*new Pjax({
|
||||||
elements: 'form[action]',
|
elements: 'form[action].pjax_subfleet_form',
|
||||||
selectors: ['.pjax_subfleet_form'],
|
selectors: ['div#subfleet_flight_wrapper'],
|
||||||
switches: {
|
history: false,
|
||||||
'#subfleet_flight_wrapper': Pjax.switches.replaceNode
|
});
|
||||||
}
|
|
||||||
|
new Pjax({
|
||||||
|
elements: 'form[action].pjax_flight_fields',
|
||||||
|
selectors: ['div#flight_fields_wrapper'],
|
||||||
|
history: false
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
$(document).on('submit', 'form.pjax_flight_fields', function (event) {
|
$(document).on('submit', 'form.pjax_flight_fields', function (event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user