Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Admin > Flight Edit (for multiple subfleet selection) #1656

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions app/Http/Controllers/Admin/FlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,20 @@ public function subfleets(string $id, Request $request): RedirectResponse|View

$fleetSvc = app(FleetService::class);

// add aircraft to flight
$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
elseif ($request->isMethod('delete')) {
$fleetSvc->removeSubfleetFromFlight($subfleet, $flight);
if ($request->isMethod('post') && filled($request->subfleet_ids)) {
// Add selected subfleets to flight
foreach ($request->subfleet_ids as $sf) {
$subfleet = $this->subfleetRepo->findWithoutFail($sf);
if ($subfleet) {
$fleetSvc->addSubfleetToFlight($subfleet, $flight);
}
}
} elseif ($request->isMethod('delete')) {
// Delete the subfleet from flight
$subfleet = $this->subfleetRepo->findWithoutFail($request->subfleet_id);
if ($subfleet) {
$fleetSvc->removeSubfleetFromFlight($subfleet, $flight);
}
}

return $this->return_subfleet_view($flight);
Expand Down
72 changes: 28 additions & 44 deletions resources/views/admin/flights/subfleets.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,43 @@
<table class="table table-responsive" id="aircrafts-table">
@if(count($flight->subfleets))
<thead>
<th>Airline</th>
<th>Type</th>
<th>Name</th>
<th style="text-align: center;">Actions</th>
<th>Airline</th>
<th>Type</th>
<th>Name</th>
<th style="text-align: center;">Actions</th>
</thead>
@endif
<tbody>
@foreach($flight->subfleets as $sf)
<tr>
<td>@if ($sf->airline->logo)
<img src="{{ $sf->airline->logo }}" style="max-width: 60px; width: 55%; height: auto;">
@else
&nbsp;{{ $sf->airline->icao }}
@endif
</td>
<td>{{ $sf->type }}</td>
<td>{{ $sf->name }}</td>
<td style="width: 10%; text-align: center;" class="form-inline">
{{ Form::open(['url' => '/admin/flights/'.$flight->id.'/subfleets',
'method' => 'delete',
'class' => 'pjax_subfleet_form']) }}
{{ Form::hidden('subfleet_id', $sf->id) }}
<div class='btn-group'>
{{ Form::button('<i class="fa fa-times"></i>',
['type' => 'submit',
'class' => 'btn btn-danger btn-xs'])
}}
</div>
{{ Form::close() }}
</td>
</tr>
@endforeach
@foreach($flight->subfleets as $sf)
<tr>
<td>@if($sf->airline->logo)
<img src="{{ $sf->airline->logo }}" style="max-width: 60px; width: 55%; height: auto;">
@else
&nbsp;{{ $sf->airline->icao }}
@endif
</td>
<td>{{ $sf->type }}</td>
<td>{{ $sf->name }}</td>
<td style="width: 10%; text-align: center;" class="form-inline">
{{ Form::open(['url' => '/admin/flights/'.$flight->id.'/subfleets', 'method' => 'delete', 'class' => 'pjax_subfleet_form']) }}
{{ Form::hidden('subfleet_id', $sf->id) }}
<div class='btn-group'>
{{ Form::button('<i class="fa fa-times"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs']) }}
</div>
{{ Form::close() }}
</td>
</tr>
@endforeach
</tbody>
</table>
<hr/>
<div class="row">
<div class="col-xs-12">
<div class="text-right">
{{ Form::open([
'url' => '/admin/flights/'.$flight->id.'/subfleets',
'method' => 'post',
'class' => 'pjax_form form-inline pjax_subfleet_form'
])
}}
{{ Form::select('subfleet_id', $avail_subfleets, null, [
'placeholder' => 'Select Subfleet',
'class' => 'select2 form-control input-lg',
'style' => 'width: 400px;',
])
}}&nbsp;
{{ Form::button('<i class="fas fa-plus"></i> add',
['type' => 'submit',
'class' => 'btn btn-success btn-s']) }}
{{ Form::open(['url' => '/admin/flights/'.$flight->id.'/subfleets', 'method' => 'post', 'class' => 'pjax_form form-inline pjax_subfleet_form']) }}
{{ Form::select('subfleet_ids[]', $avail_subfleets, null, ['class' => 'select2 form-control input-lg', 'style' => 'width: 450px;', 'multiple' => 'multiple']) }}
&nbsp;
{{ Form::button('<i class="fas fa-plus"></i> add', ['type' => 'submit', 'class' => 'btn btn-success btn-s']) }}
{{ Form::close() }}
</div>
</div>
Expand Down