From 378af760f24366fa01a61036f9bc17e5439c8bcb Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Tue, 12 Mar 2024 10:42:31 -0400 Subject: [PATCH 1/4] add: #3636 - closes #3636 --- .../Staff/ApplicationController.php | 7 +- app/Http/Livewire/ApplicationSearch.php | 71 ++++++++++ .../views/Staff/application/index.blade.php | 92 +----------- .../livewire/application-search.blade.php | 132 ++++++++++++++++++ 4 files changed, 205 insertions(+), 97 deletions(-) create mode 100644 app/Http/Livewire/ApplicationSearch.php create mode 100644 resources/views/livewire/application-search.blade.php diff --git a/app/Http/Controllers/Staff/ApplicationController.php b/app/Http/Controllers/Staff/ApplicationController.php index ae5632f38a..00443bdecd 100644 --- a/app/Http/Controllers/Staff/ApplicationController.php +++ b/app/Http/Controllers/Staff/ApplicationController.php @@ -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'); } /** diff --git a/app/Http/Livewire/ApplicationSearch.php b/app/Http/Livewire/ApplicationSearch.php new file mode 100644 index 0000000000..1d685f4403 --- /dev/null +++ b/app/Http/Livewire/ApplicationSearch.php @@ -0,0 +1,71 @@ + + * @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 + ]); + } +} diff --git a/resources/views/Staff/application/index.blade.php b/resources/views/Staff/application/index.blade.php index eb4d16bb36..ea314d9bac 100644 --- a/resources/views/Staff/application/index.blade.php +++ b/resources/views/Staff/application/index.blade.php @@ -22,95 +22,5 @@ @section('page', 'page__application--index') @section('main') -
-

{{ __('staff.applications') }}

-
- - - - - - - - - - - - - - - - - @forelse ($applications as $application) - - - - - - - - - - - - - @empty - - - - @endforelse - -
#{{ __('common.user') }}{{ __('common.email') }}{{ __('staff.application-type') }}{{ __('common.image') }}{{ __('staff.links') }}{{ __('common.created_at') }}{{ __('common.status') }}{{ __('common.moderated-by') }}{{ __('common.action') }}
{{ $application->id }} - @if ($application->user === null) - N/A - @else - - @endif - {{ $application->email }}{{ $application->type }}{{ $application->imageProofs->count() }}{{ $application->urlProofs->count() }} - - - @switch($application->status) - @case(\App\Models\Application::PENDING) - Pending - - @break - @case(\App\Models\Application::APPROVED) - Approved - - @break - @case(\App\Models\Application::REJECTED) - Rejected - - @break - @default - Unknown - @endswitch - - @if ($application->moderated === null) - N/A - @else - - @endif - - -
  • - - {{ __('common.view') }} - -
  • -
    -
    - {{ __('common.no') }} {{ __('staff.applications') }} -
    -
    - {{ $applications->links('partials.pagination') }} -
    + @livewire('application-search') @endsection diff --git a/resources/views/livewire/application-search.blade.php b/resources/views/livewire/application-search.blade.php new file mode 100644 index 0000000000..38cb9c4235 --- /dev/null +++ b/resources/views/livewire/application-search.blade.php @@ -0,0 +1,132 @@ +
    +
    +

    {{ __('staff.applications') }}

    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + @forelse ($applications as $application) + + + + + + + + + + + + + @empty + + + + @endforelse + +
    #{{ __('common.user') }}{{ __('common.email') }}{{ __('staff.application-type') }}{{ __('common.image') }}{{ __('staff.links') }}{{ __('common.created_at') }}{{ __('common.status') }}{{ __('common.moderated-by') }}{{ __('common.action') }}
    {{ $application->id }} + @if ($application->user === null) + N/A + @else + + @endif + {{ $application->email }}{{ $application->type }}{{ $application->imageProofs->count() }}{{ $application->urlProofs->count() }} + + + @switch($application->status) + @case(\App\Models\Application::PENDING) + Pending + + @break + @case(\App\Models\Application::APPROVED) + Approved + + @break + @case(\App\Models\Application::REJECTED) + Rejected + + @break + @default + Unknown + @endswitch + + @if ($application->moderated === null) + N/A + @else + + @endif + + +
  • + + {{ __('common.view') }} + +
  • +
    +
    + {{ __('common.no') }} {{ __('staff.applications') }} +
    +
    + {{ $applications->links('partials.pagination') }} +
    From d324c76e1413fd6fed74ba190c63958bf577e78a Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Tue, 12 Mar 2024 14:43:30 +0000 Subject: [PATCH 2/4] Blade Style Change (Prettier Blade CI) --- .../livewire/application-search.blade.php | 150 +++++++++--------- 1 file changed, 74 insertions(+), 76 deletions(-) diff --git a/resources/views/livewire/application-search.blade.php b/resources/views/livewire/application-search.blade.php index 38cb9c4235..9a21d4ca6a 100644 --- a/resources/views/livewire/application-search.blade.php +++ b/resources/views/livewire/application-search.blade.php @@ -44,87 +44,85 @@ class="form__text"
    - - - - - - - - - - - - + + + + + + + + + + + + - @forelse ($applications as $application) - - - - - - - - - + + + + + + + + - - - - @empty - - - - @endforelse + @break + @default + Unknown + @endswitch + + + + + @empty + + + + @endforelse
    #{{ __('common.user') }}{{ __('common.email') }}{{ __('staff.application-type') }}{{ __('common.image') }}{{ __('staff.links') }}{{ __('common.created_at') }}{{ __('common.status') }}{{ __('common.moderated-by') }}{{ __('common.action') }}
    #{{ __('common.user') }}{{ __('common.email') }}{{ __('staff.application-type') }}{{ __('common.image') }}{{ __('staff.links') }}{{ __('common.created_at') }}{{ __('common.status') }}{{ __('common.moderated-by') }}{{ __('common.action') }}
    {{ $application->id }} - @if ($application->user === null) - N/A - @else - - @endif - {{ $application->email }}{{ $application->type }}{{ $application->imageProofs->count() }}{{ $application->urlProofs->count() }} - - - @switch($application->status) - @case(\App\Models\Application::PENDING) - Pending + @forelse ($applications as $application) +
    {{ $application->id }} + @if ($application->user === null) + N/A + @else + + @endif + {{ $application->email }}{{ $application->type }}{{ $application->imageProofs->count() }}{{ $application->urlProofs->count() }} + + + @switch($application->status) + @case(\App\Models\Application::PENDING) + Pending - @break - @case(\App\Models\Application::APPROVED) - Approved + @break + @case(\App\Models\Application::APPROVED) + Approved - @break - @case(\App\Models\Application::REJECTED) - Rejected + @break + @case(\App\Models\Application::REJECTED) + Rejected - @break - @default - Unknown - @endswitch - - @if ($application->moderated === null) - N/A - @else - - @endif - - -
  • - - {{ __('common.view') }} - -
  • -
    -
    - {{ __('common.no') }} {{ __('staff.applications') }} -
    + @if ($application->moderated === null) + N/A + @else + + @endif + + +
  • + + {{ __('common.view') }} + +
  • +
    +
    {{ __('common.no') }} {{ __('staff.applications') }}
    From 9bc43d66d0554c540ca84ffd82e97c6ee2a5c2da Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Tue, 12 Mar 2024 10:50:30 -0400 Subject: [PATCH 3/4] fix: ApplicationControllerTest.php --- .../Http/Controllers/Staff/ApplicationControllerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Http/Controllers/Staff/ApplicationControllerTest.php b/tests/Feature/Http/Controllers/Staff/ApplicationControllerTest.php index c58f3525a4..54b226ad24 100644 --- a/tests/Feature/Http/Controllers/Staff/ApplicationControllerTest.php +++ b/tests/Feature/Http/Controllers/Staff/ApplicationControllerTest.php @@ -12,6 +12,7 @@ */ use App\Http\Controllers\Staff\ApplicationController; +use App\Http\Livewire\ApplicationSearch; use App\Http\Requests\Staff\ApproveApplicationRequest; use App\Http\Requests\Staff\RejectApplicationRequest; use App\Models\Application; @@ -56,7 +57,7 @@ $response = $this->actingAs($this->staffUser)->get(route('staff.applications.index')); $response->assertOk(); $response->assertViewIs('Staff.application.index'); - $response->assertViewHas('applications'); + $response->assertSeeLivewire(ApplicationSearch::class); }); test('reject validates with a form request', function (): void { From e223a613990a743f40cf1c66384dc5f1137c15e0 Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Tue, 12 Mar 2024 11:27:13 -0400 Subject: [PATCH 4/4] update: searching + deleting --- app/Http/Livewire/ApplicationSearch.php | 23 ++++++---- phpstan-baseline.neon | 10 ++++ .../livewire/application-search.blade.php | 46 +++++++++++++++---- 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/app/Http/Livewire/ApplicationSearch.php b/app/Http/Livewire/ApplicationSearch.php index 1d685f4403..754644db3d 100644 --- a/app/Http/Livewire/ApplicationSearch.php +++ b/app/Http/Livewire/ApplicationSearch.php @@ -32,7 +32,7 @@ class ApplicationSearch extends Component public string $email = ''; #[Url(history: true)] - public bool $show = false; + public string $status = ''; #[Url(history: true)] public string $sortField = 'created_at'; @@ -43,13 +43,6 @@ class ApplicationSearch extends Component #[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 { @@ -57,11 +50,23 @@ final public function applications(): \Illuminate\Contracts\Pagination\LengthAwa '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)) + ->when($this->status, fn ($query) => $query->where('status', '=', $this->status)) ->orderBy($this->sortField, $this->sortDirection) ->paginate($this->perPage); } + final public function destroy(int $id): void + { + abort_unless(auth()->user()->group->is_modo, 403); + + $application = Application::withoutGlobalScopes()->findOrFail($id); + $application->urlProofs()->delete(); + $application->imageProofs()->delete(); + $application->delete(); + + $this->dispatch('success', type: 'success', message: 'Application has successfully been deleted!'); + } + final public function render(): \Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\Foundation\Application { return view('livewire.application-search', [ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d622a21ab4..fcf796277f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -865,6 +865,16 @@ parameters: count: 4 path: app/Http/Controllers/User/WarningController.php + - + message: "#^Method App\\\\Http\\\\Livewire\\\\ApplicationSearch\\:\\:applications\\(\\) return type with generic interface Illuminate\\\\Contracts\\\\Pagination\\\\LengthAwarePaginator does not specify its types\\: TItem$#" + count: 1 + path: app/Http/Livewire/ApplicationSearch.php + + - + message: "#^Parameter \\#1 \\$boolean of function abort_unless expects bool, int given\\.$#" + count: 1 + path: app/Http/Livewire/ApplicationSearch.php + - message: "#^Property App\\\\Http\\\\Livewire\\\\AttachmentUpload\\:\\:\\$attachment has no type specified\\.$#" count: 1 diff --git a/resources/views/livewire/application-search.blade.php b/resources/views/livewire/application-search.blade.php index 9a21d4ca6a..2217c1396e 100644 --- a/resources/views/livewire/application-search.blade.php +++ b/resources/views/livewire/application-search.blade.php @@ -4,13 +4,13 @@
    - - + +
    @@ -59,7 +59,7 @@ class="form__text" @forelse ($applications as $application) - + {{ $application->id }} @if ($application->user === null) @@ -115,6 +115,17 @@ class="form__button form__button--text" {{ __('common.view') }} +
  • +
    + +
    +
  • @@ -127,4 +138,23 @@ class="form__button form__button--text"
    {{ $applications->links('partials.pagination') }} +