diff --git a/app/Http/Controllers/Staff/WarningController.php b/app/Http/Controllers/Staff/WarningController.php index b75f030ce..27eb30d33 100644 --- a/app/Http/Controllers/Staff/WarningController.php +++ b/app/Http/Controllers/Staff/WarningController.php @@ -23,12 +23,11 @@ class WarningController extends Controller { /** * Warnings Log. + * + * @see \app\Http\Livewire\WarningLogSearch */ public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View { - $warnings = Warning::with(['torrenttitle', 'warneduser'])->latest()->paginate(25); - $warningcount = Warning::count(); - - return view('Staff.warning.index', ['warnings' => $warnings, 'warningcount' => $warningcount]); + return view('Staff.warning.index'); } } diff --git a/app/Http/Livewire/WarningLogSearch.php b/app/Http/Livewire/WarningLogSearch.php new file mode 100644 index 000000000..62250f832 --- /dev/null +++ b/app/Http/Livewire/WarningLogSearch.php @@ -0,0 +1,100 @@ + + * @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\Torrent; +use App\Models\User; +use App\Models\Warning; +use Livewire\Component; +use Livewire\WithPagination; + +class WarningLogSearch extends Component +{ + use WithPagination; + + public string $sender = ''; + + public string $receiver = ''; + + public string $torrent = ''; + + public string $reason = ''; + + public bool $show = false; + + public int $perPage = 25; + + public string $sortField = 'created_at'; + + public string $sortDirection = 'desc'; + + protected $queryString = [ + 'sender' => ['except' => ''], + 'receiver' => ['except' => ''], + 'torrent' => ['except' => ''], + 'reason' => ['except' => ''], + 'show' => ['except' => false], + 'page' => ['except' => 1], + 'perPage' => ['except' => ''], + ]; + + final public function paginationView(): string + { + return 'vendor.pagination.livewire-pagination'; + } + + final public function updatedPage(): void + { + $this->emit('paginationChanged'); + } + + final public function toggleProperties($property): void + { + if ($property === 'show') { + $this->show = ! $this->show; + } + } + + final public function getWarningsProperty(): \Illuminate\Contracts\Pagination\LengthAwarePaginator + { + return Warning::query() + ->with(['warneduser', 'staffuser', 'torrenttitle']) + ->when($this->sender, fn ($query) => $query->whereIn('warned_by', User::select('id')->where('username', '=', $this->sender))) + ->when($this->receiver, fn ($query) => $query->whereIn('user_id', User::select('id')->where('username', '=', $this->receiver))) + ->when($this->torrent, fn ($query) => $query->whereIn('torrent', Torrent::select('id')->where('name', 'LIKE', '%'.$this->torrent.'%'))) + ->when($this->reason, fn ($query) => $query->where('reason', 'LIKE', '%'.$this->reason.'%')) + ->when($this->show === true, fn ($query) => $query->onlyTrashed()) + ->orderBy($this->sortField, $this->sortDirection) + ->paginate($this->perPage); + } + + final public function sortBy($field): void + { + if ($this->sortField === $field) { + $this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc'; + } else { + $this->sortDirection = 'asc'; + } + + $this->sortField = $field; + } + + final public function render(): \Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\Foundation\Application + { + return view('livewire.warning-log-search', [ + 'warnings' => $this->warnings, + ]); + } +} + diff --git a/resources/views/Staff/warning/index.blade.php b/resources/views/Staff/warning/index.blade.php index 0c4cbfb16..f18bce5b7 100644 --- a/resources/views/Staff/warning/index.blade.php +++ b/resources/views/Staff/warning/index.blade.php @@ -22,64 +22,5 @@ @section('page', 'page__warning-log--index') @section('main') -
-

{{ __('staff.warnings-log') }} ({{ $warningcount }})

- - - - - - - - - - - - - - @forelse ($warnings as $warning) - - - - - - - - - - @empty - - - - @endforelse - -
{{ __('common.user') }}{{ __('user.warned-by') }}{{ __('torrent.torrent') }}{{ __('common.reason') }}{{ __('user.created-on') }}{{ __('user.expires-on') }}{{ __('common.active') }}
- - - - - @isset($warning->torrent) - - {{ $warning->torrenttitle->name }} - - @else - n/a - @endisset - {{ $warning->reason }} - - - - - @if ($warning->active) - {{ __('common.yes') }} - @else - {{ __('common.expired') }} - @endif -
No warnings
- {{ $warnings->links('partials.pagination') }} -
+ @livewire('warning-log-search') @endsection diff --git a/resources/views/livewire/warning-log-search.blade.php b/resources/views/livewire/warning-log-search.blade.php new file mode 100644 index 000000000..95402fe41 --- /dev/null +++ b/resources/views/livewire/warning-log-search.blade.php @@ -0,0 +1,168 @@ +
+
+

{{ __('staff.warnings-log') }}

+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + + + + + + + + + + + + + @forelse ($warnings as $warning) + + + + + + + + + + @empty + + + + @endforelse + +
+ {{ __('common.user') }} + @include('livewire.includes._sort-icon', ['field' => 'user_id']) + + {{ __('user.warned-by') }} + @include('livewire.includes._sort-icon', ['field' => 'warned_by']) + + {{ __('torrent.torrent') }} + @include('livewire.includes._sort-icon', ['field' => 'torrent']) + {{ __('common.reason') }} + {{ __('common.created_at') }} + @include('livewire.includes._sort-icon', ['field' => 'created_at']) + + {{ __('user.expires-on') }} + @include('livewire.includes._sort-icon', ['field' => 'expires_on']) + + {{ __('common.active') }} + @include('livewire.includes._sort-icon', ['field' => 'active']) +
+ + + + + @isset($warning->torrent) + + {{ $warning->torrenttitle->name }} + + @else + n/a + @endisset + {{ $warning->reason }} + + + + + @if ($warning->active) + {{ __('common.yes') }} + @else + {{ __('common.expired') }} + @endif +
No warnings
+ {{ $warnings->links('partials.pagination') }} +