add: warning searching

This commit is contained in:
HDVinnie
2023-05-28 22:20:06 -04:00
parent f007edcdf1
commit 98e8f91cd9
4 changed files with 272 additions and 64 deletions
@@ -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');
}
}
+100
View File
@@ -0,0 +1,100 @@
<?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\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,
]);
}
}
+1 -60
View File
@@ -22,64 +22,5 @@
@section('page', 'page__warning-log--index')
@section('main')
<section class="panelV2">
<h2 class="panel__heading">{{ __('staff.warnings-log') }} ({{ $warningcount }})</h2>
<table class="table table-condensed table-striped table-bordered table-hover">
<thead>
<tr>
<th>{{ __('common.user') }}</th>
<th>{{ __('user.warned-by') }}</th>
<th>{{ __('torrent.torrent') }}</th>
<th>{{ __('common.reason') }}</th>
<th>{{ __('user.created-on') }}</th>
<th>{{ __('user.expires-on') }}</th>
<th>{{ __('common.active') }}</th>
</tr>
</thead>
<tbody>
@forelse ($warnings as $warning)
<tr>
<td>
<x-user_tag :anon="false" :user="$warning->warneduser" />
</td>
<td>
<x-user_tag :anon="false" :user="$warning->staffuser" />
</td>
<td>
@isset($warning->torrent)
<a href="{{ route('torrent', ['id' => $warning->torrenttitle->id]) }}">
{{ $warning->torrenttitle->name }}
</a>
@else
n/a
@endisset
</td>
<td>{{ $warning->reason }}</td>
<td>
<time datetime="{{ $warning->created_at }}">
{{ $warning->created_at }}
</time>
</td>
<td>
<time datetime="{{ $warning->expires_on }}">
{{ $warning->expires_on }}
</time>
</td>
<td>
@if ($warning->active)
<span class='text-green'>{{ __('common.yes') }}</span>
@else
<span class='text-red'>{{ __('common.expired') }}</span>
@endif
</td>
</tr>
@empty
<tr>
<td colspan="7">No warnings</td>
</tr>
@endforelse
</tbody>
</table>
{{ $warnings->links('partials.pagination') }}
</section>
@livewire('warning-log-search')
@endsection
@@ -0,0 +1,168 @@
<section class="panelV2">
<header class="panel__header">
<h2 class="panel__heading">{{ __('staff.warnings-log') }}</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 Soft Deletes
</label>
</div>
</div>
<div class="panel__action">
<div class="form__group">
<input
id="receiver"
class="form__text"
type="text"
wire:model="receiver"
placeholder=" "
/>
<label class="form__label form__label--floating">
{{ __('common.user') }} {{ __('common.username') }}
</label>
</div>
</div>
<div class="panel__action">
<div class="form__group">
<input
id="sender"
class="form__text"
type="text"
wire:model="sender"
placeholder=" "
/>
<label class="form__label form__label--floating">
{{ __('common.staff') }} {{ __('common.username') }}
</label>
</div>
</div>
<div class="panel__action">
<div class="form__group">
<input
id="torrent"
class="form__text"
type="text"
wire:model="torrent"
placeholder=" "
/>
<label class="form__label form__label--floating">
{{ __('torrent.torrent') }} {{ __('common.name') }}
</label>
</div>
</div>
<div class="panel__action">
<div class="form__group">
<input
id="reason"
class="form__text"
type="text"
wire:model="reason"
placeholder=" "
/>
<label class="form__label form__label--floating">
{{ __('common.reason') }}
</label>
</div>
</div>
<div class="panel__action">
<div class="form__group">
<select
id="quantity"
class="form__select"
wire:model="perPage"
required
>
<option>25</option>
<option>50</option>
<option>100</option>
</select>
<label class="form__label form__label--floating">
{{ __('common.quantity') }}
</label>
</div>
</div>
</div>
</header>
<table class="table table-condensed table-striped table-bordered table-hover">
<thead>
<tr>
<th wire:click="sortBy('user_id')" role="columnheader button">
{{ __('common.user') }}
@include('livewire.includes._sort-icon', ['field' => 'user_id'])
</th>
<th wire:click="sortBy('warned_by')" role="columnheader button">
{{ __('user.warned-by') }}
@include('livewire.includes._sort-icon', ['field' => 'warned_by'])
</th>
<th wire:click="sortBy('torrent')" role="columnheader button">
{{ __('torrent.torrent') }}
@include('livewire.includes._sort-icon', ['field' => 'torrent'])
</th>
<th>{{ __('common.reason') }}</th>
<th wire:click="sortBy('created_at')" role="columnheader button">
{{ __('common.created_at') }}
@include('livewire.includes._sort-icon', ['field' => 'created_at'])
</th>
<th wire:click="sortBy('expires_on')" role="columnheader button">
{{ __('user.expires-on') }}
@include('livewire.includes._sort-icon', ['field' => 'expires_on'])
</th>
<th wire:click="sortBy('active')" role="columnheader button">
{{ __('common.active') }}
@include('livewire.includes._sort-icon', ['field' => 'active'])
</th>
</tr>
</thead>
<tbody>
@forelse ($warnings as $warning)
<tr>
<td>
<x-user_tag :anon="false" :user="$warning->warneduser" />
</td>
<td>
<x-user_tag :anon="false" :user="$warning->staffuser" />
</td>
<td>
@isset($warning->torrent)
<a href="{{ route('torrent', ['id' => $warning->torrenttitle->id]) }}">
{{ $warning->torrenttitle->name }}
</a>
@else
n/a
@endisset
</td>
<td>{{ $warning->reason }}</td>
<td>
<time datetime="{{ $warning->created_at }}">
{{ $warning->created_at }}
</time>
</td>
<td>
<time datetime="{{ $warning->expires_on }}">
{{ $warning->expires_on }}
</time>
</td>
<td>
@if ($warning->active)
<span class='text-green'>{{ __('common.yes') }}</span>
@else
<span class='text-red'>{{ __('common.expired') }}</span>
@endif
</td>
</tr>
@empty
<tr>
<td colspan="7">No warnings</td>
</tr>
@endforelse
</tbody>
</table>
{{ $warnings->links('partials.pagination') }}
</section>