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

Sortable Admin Pireps List #1694

Merged
merged 3 commits into from
Nov 27, 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
9 changes: 5 additions & 4 deletions app/Http/Controllers/Admin/PirepController.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ public function index(Request $request): View
$this->pirepRepo->pushCriteria($criterea);

$pireps = $this->pirepRepo
->with(['airline', 'aircraft', 'dpt_airport', 'arr_airport'])
->whereNotInOrder('state', [
PirepState::CANCELLED,
->with(['airline', 'aircraft', 'dpt_airport', 'arr_airport', 'user'])
->whereNotIn('pireps.state', [
PirepState::DRAFT,
PirepState::IN_PROGRESS,
], 'created_at', 'desc')
PirepState::CANCELLED,
])
->sortable(['submitted_at' => 'desc'])
->paginate();

return view('admin.pireps.index', [
Expand Down
7 changes: 2 additions & 5 deletions app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,9 @@ public function edit(int $id): View
return redirect(route('admin.users.index'));
}

$pireps = $this->pirepRepo
->whereOrder(['user_id' => $id], 'created_at', 'desc')
->paginate();
$pireps = $this->pirepRepo->where('user_id', $id)->sortable(['submitted_at' => 'desc'])->paginate();

$countries = collect((new ISO3166())->all())
->mapWithKeys(fn ($item, $key) => [strtolower($item['alpha2']) => $item['name']]);
$countries = collect((new ISO3166())->all())->mapWithKeys(fn ($item, $key) => [strtolower($item['alpha2']) => $item['name']]);

$airlines = $this->airlineRepo->selectBoxList();
$roles = $this->roleRepo->selectBoxList(false, true);
Expand Down
1 change: 1 addition & 0 deletions app/Models/Pirep.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class Pirep extends Model
'landing_rate',
'score',
'flight_type',
'source',
'state',
'status',
'submitted_at',
Expand Down
30 changes: 13 additions & 17 deletions resources/views/admin/pireps/actions.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table class="table" style="border-style: hidden; margin-bottom: 0px;">
<table class="table" style="border-style: hidden; margin-bottom: 0px; padding:0px;">
<tr style="border-style: hidden;">
@if ($pirep->state === PirepState::PENDING || $pirep->state === PirepState::REJECTED)
<td>
Expand Down Expand Up @@ -26,31 +26,27 @@
{{ Form::close() }}
</td>
@endif
<td>
{{ Form::open(['url' => route('admin.pireps.destroy', [$pirep->id]),
'method' => 'delete',
'name' => 'delete_'.$pirep->id,
'id' => $pirep->id.'_delete',
'onclick' => "return confirm('Are you sure?')"
]) }}
{{ Form::button('Delete', ['type' => 'submit', 'class' => 'btn btn-danger']) }}
{{ Form::close() }}
</td>
@if ($on_edit_page === false)
<td>
<form action="{{ route('admin.pireps.edit', [$pirep->id]) }}">
<button type="submit" class='btn btn-info'>
<i class="fas fa-pencil-alt"></i>&nbsp;&nbsp;Edit
</button>
<button type="submit" class='btn btn-info'>Edit</button>
</form>
</td>
@endif
<td>
<form action="{{ route('frontend.pireps.show', [$pirep->id]) }}" target="_blank">
<button type="submit" class='btn btn-success'>
<i class="fas fa-eye"></i>&nbsp;&nbsp; View Pirep
</button>
<button type="submit" class='btn btn-success'>View</button>
</form>
</td>
<td>
{{ Form::open(['url' => route('admin.pireps.destroy', [$pirep->id]),
'method' => 'delete',
'name' => 'delete_'.$pirep->id,
'id' => $pirep->id.'_delete',
'onclick' => "return confirm('Are you sure?')"
]) }}
{{ Form::button('Delete', ['type' => 'submit', 'class' => 'btn btn-danger']) }}
{{ Form::close() }}
</td>
</tr>
</table>
26 changes: 15 additions & 11 deletions resources/views/admin/pireps/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

@section('title', 'Pilot Reports')
@section('actions')
<li><a href="{{ route('admin.pirepfields.index') }}"><i class="ti-menu-alt"></i>PIREP Fields</a></li>
<li><a href="{{ route('admin.pireps.index') }}?search=state:{{ \App\Models\Enums\PirepState::PENDING }}"><i class="ti-plus"></i>Pending</a></li>
<li><a href="{{ route('admin.pireps.index') }}?search=state:{{ \App\Models\Enums\PirepState::REJECTED }}"><i class="ti-plus"></i>Rejected</a></li>
<li><a href="{{ route('admin.pireps.index') }}?search=state:{{ \App\Models\Enums\PirepState::ACCEPTED }}"><i class="ti-plus"></i>Accepted</a></li>
<li><a href="{{ route('admin.pireps.index') }}"><i class="ti-plus"></i>View All</a></li>
<li><a href="{{ route('admin.pirepfields.index') }}"><i class="ti-menu-alt"></i>PIREP Fields</a></li>
<li><a href="{{ route('admin.pireps.index') }}?search=state:{{ \App\Models\Enums\PirepState::PENDING }}"><i class="ti-plus"></i>Pending</a></li>
<li><a href="{{ route('admin.pireps.index') }}?search=state:{{ \App\Models\Enums\PirepState::REJECTED }}"><i class="ti-plus"></i>Rejected</a></li>
<li><a href="{{ route('admin.pireps.index') }}?search=state:{{ \App\Models\Enums\PirepState::ACCEPTED }}"><i class="ti-plus"></i>Accepted</a></li>
<li><a href="{{ route('admin.pireps.index') }}"><i class="ti-plus"></i>View All</a></li>
@endsection
@section('content')
<div class="row" style="width: 100%">
@include('admin.pireps.table')
</div>
<div class="row text-center" style="width: 100%">
{{ $pireps->links('admin.pagination.default') }}
</div>
<div class="card border-blue-bottom">
<div class="content">
@include('admin.pireps.table')
</div>
</div>
<div class="row">
<div class="col-12 text-center">
{{ $pireps->withQueryString()->links('admin.pagination.default') }}
</div>
</div>
@endsection
@include('admin.pireps.scripts')
127 changes: 62 additions & 65 deletions resources/views/admin/pireps/pirep_card.blade.php
Original file line number Diff line number Diff line change
@@ -1,72 +1,69 @@
<div id="pirep_{{ $pirep->id }}_container" class="card border-blue-bottom pirep_card_container">
<div class="card-block" style="min-height: 0px">
<div class="row">
<div class="card-block" style="min-height: 0px">
<div class="row">
<div class="col-sm-2 text-center">
<h5><a class="text-c" href="{{ route('admin.pireps.edit', [$pirep->id]) }}">{{ $pirep->ident }}</a></h5>
<h5>
<a class="text-c" href="{{ route('admin.pireps.edit', [$pirep->id]) }}">{{ $pirep->ident }}</a>
</h5>
<div id="pirep_{{ $pirep->id }}_status_container">
@php
$PirepStateClass = "badge badge-info" ;
if($pirep->state === PirepState::PENDING ) { $PirepStateClass = "badge badge-warning" ; }
if($pirep->state === PirepState::ACCEPTED ) { $PirepStateClass = "badge badge-success" ; }
if($pirep->state === PirepState::REJECTED ) { $PirepStateClass = "badge badge-danger" ; }
@endphp
@php
$PirepStateClass = "badge badge-info" ;
if($pirep->state === PirepState::PENDING ) { $PirepStateClass = "badge badge-warning" ; }
if($pirep->state === PirepState::ACCEPTED ) { $PirepStateClass = "badge badge-success" ; }
if($pirep->state === PirepState::REJECTED ) { $PirepStateClass = "badge badge-danger" ; }
@endphp
<div class="{{ $PirepStateClass }}">{{ PirepState::label($pirep->state) }}</div>
</div>
</div>
<div class="col-sm-10">
<div class="row">
<div class="col-sm-6">
<div>
<span class="description">
<b>Pilot</b>&nbsp;{{ '('.$pirep->user_id.') '.optional($pirep->user)->name }}
</span>
</div>
</div>
<div class="col-sm-10">
<div class="row">
<div class="col-sm-6">
<div>
<span class="description">
<b>DEP</b>&nbsp;{{ $pirep->dpt_airport_id }}&nbsp;
<b>ARR</b>&nbsp;{{ $pirep->arr_airport_id }}&nbsp;
</span>
</div>
<div>
<span class="description">
<b>Flight Time</b>&nbsp; @minutestotime($pirep->flight_time)
</span>
</div>
@if($pirep->aircraft)
<div>
<span class="description">
<b>Aircraft</b>&nbsp;{{ $pirep->aircraft->registration }} @if($pirep->aircraft->registration != $pirep->aircraft->name) '{{ $pirep->aircraft->name }}' @endif
</span>
</div>
@endif
@if(filled($pirep->level) && $pirep->level > 10)
<div>
<span class="description">
<b>Flight Level</b>&nbsp;{{ $pirep->level }}
</span>
</div>
@endif
<div>
<span class="description">
<b>Filed Using</b>&nbsp; {{ PirepSource::label($pirep->source) }}
@if(filled($pirep->source_name)) ({{ $pirep->source_name }}) @endif
</span>
</div>
<div>
<span class="description">
<b>File Date</b>&nbsp; {{ show_datetime($pirep->created_at) }}
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div id="pirep_{{ $pirep->id }}_actionbar" class="pull-right">
@include('admin.pireps.actions', ['pirep' => $pirep, 'on_edit_page' => false])
</div>
</div>
</div>
</div>
<span class="description">
<b>Pilot</b>&nbsp;{{ '('.$pirep->user_id.') '.optional($pirep->user)->name }}
</span>
</div>
<div>
<span class="description">
<b>DEP</b>&nbsp;{{ $pirep->dpt_airport_id }}&nbsp;
<b>ARR</b>&nbsp;{{ $pirep->arr_airport_id }}&nbsp;
</span>
</div>
<div>
<span class="description">
<b>Flight Time</b>&nbsp; @minutestotime($pirep->flight_time)
</span>
</div>
@if($pirep->aircraft)
<div>
<span class="description">
<b>Aircraft</b>&nbsp;{{ $pirep->aircraft->registration }} @if($pirep->aircraft->registration != $pirep->aircraft->name) '{{ $pirep->aircraft->name }}' @endif
</span>
</div>
@endif
@if(filled($pirep->level) && $pirep->level > 10)
<div>
<span class="description"><b>Flight Level</b>&nbsp;{{ $pirep->level }}</span>
</div>
@endif
<div>
<span class="description"><b>Filed Using</b>&nbsp; {{ PirepSource::label($pirep->source) }}
@if(filled($pirep->source_name)) ({{ $pirep->source_name }}) @endif
</span>
</div>
<div>
<span class="description"><b>File Date</b>&nbsp; {{ show_datetime($pirep->created_at) }}</span>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div id="pirep_{{ $pirep->id }}_actionbar" class="pull-right">
@include('admin.pireps.actions', ['pirep' => $pirep, 'on_edit_page' => false])
</div>
</div>
</div>
</div>
</div>
70 changes: 69 additions & 1 deletion resources/views/admin/pireps/table.blade.php
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
@each('admin.pireps.pirep_card', $pireps, 'pirep')
{{-- @each('admin.pireps.pirep_card', $pireps, 'pirep') --}}
<div class="content table-responsive table-full-width">
<table class="table table-hover" id="flights-table">
<thead>
<th>@sortablelink('state', 'State')</th>
<th>@sortablelink('user.name', 'Pilot')</th>
<th>@sortablelink('flight_number', 'Flight #')</th>
<th>@sortablelink('aircraft.registration', 'Aircraft')</th>
<th>@sortablelink('dpt_airport_id', 'Dep')</th>
<th>@sortablelink('arr_airport_id', 'Arr')</th>
<th>@sortablelink('flight_time', 'Time')</th>
<th>@sortablelink('distance', 'Distance')</th>
<th>@sortablelink('score', 'Score')</th>
<th>@sortablelink('source', 'Source')</th>
<th>@sortablelink('submitted_at', 'Submitted')</th>
<th class="text-right">Actions</th>
</thead>
<tbody>
@foreach($pireps as $pirep)
<tr>
<td>
<div id="pirep_{{ $pirep->id }}_status_container">
@php
$PirepStateClass = "badge badge-info" ;
if($pirep->state === PirepState::PENDING ) { $PirepStateClass = "badge badge-warning" ; }
if($pirep->state === PirepState::ACCEPTED ) { $PirepStateClass = "badge badge-success" ; }
if($pirep->state === PirepState::REJECTED ) { $PirepStateClass = "badge badge-danger" ; }
@endphp
<div class="{{ $PirepStateClass }}">{{ PirepState::label($pirep->state) }}</div>
</div>
</td>
<td>
<a href="{{ route('admin.users.edit', [$pirep->user->id]) }}">
{{ $pirep->user_id.' | '.optional($pirep->user)->name_private }}
</a>
</td>
<td>
<a href="{{ route('admin.pireps.edit', [$pirep->id]) }}">{{$pirep->ident}}</a>
</td>
<td>
@if($pirep->aircraft)
{{ $pirep->aircraft->ident }}
@else
{{ $pirep->aircraft_id }}
@endif
</td>
<td>{{ $pirep->dpt_airport_id }}</td>
<td>{{ $pirep->arr_airport_id }}</td>
<td>@minutestotime($pirep->flight_time)</td>
<td>{{ round($pirep->distance->local()).' '.setting('units.distance') }}</td>
<td>{{ $pirep->score }}</td>
<td>
{{ PirepSource::label($pirep->source) }}
@if(filled($pirep->source_name))
({{ $pirep->source_name }})
@endif
</td>
<td>{{ $pirep->submitted_at->format('d.M.Y H:i') }}</td>
<td class="text-right">
<div id="pirep_{{ $pirep->id }}_actionbar" class="pull-right">
@include('admin.pireps.actions', ['pirep' => $pirep, 'on_edit_page' => false])
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>

2 changes: 1 addition & 1 deletion resources/views/admin/users/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<div class="row">
<div class="col-12 text-center">
{{ $pireps->links('admin.pagination.default') }}
{{ $pireps->withQueryString()->links('admin.pagination.default') }}
</div>
</div>
</div>
Expand Down
Loading