- closes #3636
This commit is contained in:
HDVinnie
2024-03-12 10:42:31 -04:00
parent 04f5ecb68d
commit 378af760f2
4 changed files with 205 additions and 97 deletions
@@ -35,12 +35,7 @@ class ApplicationController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
return view('Staff.application.index', [
'applications' => Application::withoutGlobalScope(ApprovedScope::class)
->with(['user.group', 'moderated.group', 'imageProofs', 'urlProofs'])
->latest()
->paginate(25),
]);
return view('Staff.application.index');
}
/**
+71
View File
@@ -0,0 +1,71 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Livewire;
use App\Models\Application;
use App\Models\Scopes\ApprovedScope;
use App\Traits\LivewireSort;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Url;
use Livewire\Component;
use Livewire\WithPagination;
class ApplicationSearch extends Component
{
use LivewireSort;
use WithPagination;
#TODO: Update URL attributes once Livewire 3 fixes upstream bug. See: https://github.com/livewire/livewire/discussions/7746
#[Url(history: true)]
public string $email = '';
#[Url(history: true)]
public bool $show = false;
#[Url(history: true)]
public string $sortField = 'created_at';
#[Url(history: true)]
public string $sortDirection = 'desc';
#[Url(history: true)]
public int $perPage = 25;
final public function toggleProperties($property): void
{
if ($property === 'show') {
$this->show = !$this->show;
}
}
#[Computed]
final public function applications(): \Illuminate\Contracts\Pagination\LengthAwarePaginator
{
return Application::withoutGlobalScope(ApprovedScope::class)->with([
'user.group', 'moderated.group', 'imageProofs', 'urlProofs'
])
->when($this->email, fn ($query) => $query->where('email', 'LIKE', '%'.$this->email.'%'))
->when($this->show === true, fn ($query) => $query->where('status', '=', Application::PENDING))
->orderBy($this->sortField, $this->sortDirection)
->paginate($this->perPage);
}
final public function render(): \Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\Foundation\Application
{
return view('livewire.application-search', [
'applications' => $this->applications
]);
}
}
@@ -22,95 +22,5 @@
@section('page', 'page__application--index')
@section('main')
<section class="panelV2">
<h2 class="panel__heading">{{ __('staff.applications') }}</h2>
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th>#</th>
<th>{{ __('common.user') }}</th>
<th>{{ __('common.email') }}</th>
<th>{{ __('staff.application-type') }}</th>
<th>{{ __('common.image') }}</th>
<th>{{ __('staff.links') }}</th>
<th>{{ __('common.created_at') }}</th>
<th>{{ __('common.status') }}</th>
<th>{{ __('common.moderated-by') }}</th>
<th>{{ __('common.action') }}</th>
</tr>
</thead>
<tbody>
@forelse ($applications as $application)
<tr>
<td>{{ $application->id }}</td>
<td>
@if ($application->user === null)
N/A
@else
<x-user_tag :anon="false" :user="$application->user" />
@endif
</td>
<td>{{ $application->email }}</td>
<td>{{ $application->type }}</td>
<td>{{ $application->imageProofs->count() }}</td>
<td>{{ $application->urlProofs->count() }}</td>
<td>
<time
datetime="{{ $application->created_at }}"
title="{{ $application->created_at }}"
>
{{ $application->created_at->diffForHumans() }}
</time>
</td>
<td>
@switch($application->status)
@case(\App\Models\Application::PENDING)
<span class="application--pending">Pending</span>
@break
@case(\App\Models\Application::APPROVED)
<span class="application--approved">Approved</span>
@break
@case(\App\Models\Application::REJECTED)
<span class="application--rejected">Rejected</span>
@break
@default
<span class="application--unknown">Unknown</span>
@endswitch
</td>
<td>
@if ($application->moderated === null)
N/A
@else
<x-user_tag :anon="false" :user="$application->moderated" />
@endif
</td>
<td>
<menu class="data-table__actions">
<li class="data-table__action">
<a
class="form__button form__button--text"
href="{{ route('staff.applications.show', ['id' => $application->id]) }}"
>
{{ __('common.view') }}
</a>
</li>
</menu>
</td>
</tr>
@empty
<tr class="applications--empty">
<td colspan="10">
{{ __('common.no') }} {{ __('staff.applications') }}
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
{{ $applications->links('partials.pagination') }}
</section>
@livewire('application-search')
@endsection
@@ -0,0 +1,132 @@
<section class="panelV2">
<header class="panel__header">
<h2 class="panel__heading">{{ __('staff.applications') }}</h2>
<div class="panel__actions">
<div class="panel__action">
<div class="form__group">
<input
id="show"
class="form__checkbox"
type="checkbox"
wire:click="toggleProperties('show')"
/>
<label class="form__label" for="show">Show Pending Only</label>
</div>
</div>
<div class="panel__action">
<div class="form__group">
<input
id="receiver"
class="form__text"
type="text"
wire:model.live="email"
placeholder=" "
/>
<label class="form__label form__label--floating" for="receiver">
{{ __('common.email') }}
</label>
</div>
</div>
<div class="panel__action">
<div class="form__group">
<select id="quantity" class="form__select" wire:model.live="perPage" required>
<option>25</option>
<option>50</option>
<option>100</option>
</select>
<label class="form__label form__label--floating" for="quantity">
{{ __('common.quantity') }}
</label>
</div>
</div>
</div>
</header>
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th>#</th>
<th>{{ __('common.user') }}</th>
<th>{{ __('common.email') }}</th>
<th>{{ __('staff.application-type') }}</th>
<th>{{ __('common.image') }}</th>
<th>{{ __('staff.links') }}</th>
<th>{{ __('common.created_at') }}</th>
<th>{{ __('common.status') }}</th>
<th>{{ __('common.moderated-by') }}</th>
<th>{{ __('common.action') }}</th>
</tr>
</thead>
<tbody>
@forelse ($applications as $application)
<tr>
<td>{{ $application->id }}</td>
<td>
@if ($application->user === null)
N/A
@else
<x-user_tag :anon="false" :user="$application->user" />
@endif
</td>
<td>{{ $application->email }}</td>
<td>{{ $application->type }}</td>
<td>{{ $application->imageProofs->count() }}</td>
<td>{{ $application->urlProofs->count() }}</td>
<td>
<time
datetime="{{ $application->created_at }}"
title="{{ $application->created_at }}"
>
{{ $application->created_at->diffForHumans() }}
</time>
</td>
<td>
@switch($application->status)
@case(\App\Models\Application::PENDING)
<span class="application--pending">Pending</span>
@break
@case(\App\Models\Application::APPROVED)
<span class="application--approved">Approved</span>
@break
@case(\App\Models\Application::REJECTED)
<span class="application--rejected">Rejected</span>
@break
@default
<span class="application--unknown">Unknown</span>
@endswitch
</td>
<td>
@if ($application->moderated === null)
N/A
@else
<x-user_tag :anon="false" :user="$application->moderated" />
@endif
</td>
<td>
<menu class="data-table__actions">
<li class="data-table__action">
<a
class="form__button form__button--text"
href="{{ route('staff.applications.show', ['id' => $application->id]) }}"
>
{{ __('common.view') }}
</a>
</li>
</menu>
</td>
</tr>
@empty
<tr class="applications--empty">
<td colspan="10">
{{ __('common.no') }} {{ __('staff.applications') }}
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
{{ $applications->links('partials.pagination') }}
</section>