add: option to snooze reports

This commit is contained in:
Roardom
2024-09-03 01:30:14 +00:00
parent b36639db54
commit f51bfab180
8 changed files with 272 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/**
* 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 Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Controllers\Staff;
use App\Http\Controllers\Controller;
use App\Http\Requests\Staff\StoreSnoozedReportRequest;
use App\Models\Report;
class SnoozedReportController extends Controller
{
/**
* Snooze A Report.
*/
public function store(StoreSnoozedReportRequest $request, Report $report): \Illuminate\Http\RedirectResponse
{
$report->update($request->validated());
return to_route('staff.reports.show', ['report' => $report])
->withSuccess('Report has been snoozed');
}
/**
* Un-snooze A Report.
*/
public function destroy(Report $report): \Illuminate\Http\RedirectResponse
{
$report->update(['snoozed_until' => null]);
return to_route('staff.reports.show', ['report' => $report])
->withSuccess('Report has been un-snoozed');
}
}

View File

@@ -58,6 +58,9 @@ class ReportSearch extends Component
#[Url(history: true, except: 'exclude')]
public ?string $solved = 'exclude';
#[Url(history: true)]
public bool $hideSnoozed = true;
#[Url(history: true)]
public string $sortField = 'created_at';
@@ -84,6 +87,7 @@ class ReportSearch extends Component
->when($this->verdict !== null, fn ($query) => $query->where('verdict', 'LIKE', '%'.str_replace(' ', '%', '%'.$this->verdict.'%')))
->when($this->solved === 'include', fn ($query) => $query->where('solved', '=', true))
->when($this->solved === 'exclude', fn ($query) => $query->where('solved', '=', false))
->when($this->hideSnoozed, fn ($query) => $query->where(fn ($query) => $query->whereNull('snoozed_until')->orWhere('snoozed_until', '<', now())))
->orderBy($this->sortField, $this->sortDirection)
->paginate($this->perPage);
}

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/**
* 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 Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Requests\Staff;
use Illuminate\Foundation\Http\FormRequest;
class StoreSnoozedReportRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array<\Illuminate\Contracts\Validation\Rule|string>|string>
*/
public function rules(): array
{
return [
'snoozed_until' => [
'required',
'string',
'date_format:Y-m-d H:i:s',
],
];
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
if (ctype_digit($this->snoozed_days)) {
$this->merge([
'snoozed_until' => now()->addDays((int) $this->snoozed_days)->toDateTimeString(),
]);
}
}
}

View File

@@ -36,6 +36,7 @@ use Illuminate\Database\Eloquent\Model;
* @property int|null $reported_user
* @property int|null $torrent_id
* @property int|null $request_id
* @property \Illuminate\Support\Carbon|null $snoozed_until
*/
class Report extends Model
{
@@ -51,6 +52,18 @@ class Report extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Get the attributes that should be cast.
*
* @return array{snoozed_until: 'datetime'}
*/
protected function casts(): array
{
return [
'snoozed_until' => 'datetime',
];
}
/**
* Belongs To A Request.
*

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/**
* 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 Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('reports', function (Blueprint $table): void {
$table->timestamp('snoozed_until')->nullable();
});
}
};

View File

@@ -122,4 +122,115 @@
@endif
</div>
</section>
<section class="panelV2">
<h2 class="panel__heading">Snooze</h2>
@if ($report->snoozed_until !== null)
<dl class="key-value">
<div class="key-value__group">
<dt>Snoozed until</dt>
<dd>{{ $report->snoozed_until }}</dd>
</div>
</dl>
@endif
<div class="panel__body">
@if ($report->snoozed_until === null)
<form
class="form"
action="{{ route('staff.snoozed_reports.store', ['report' => $report]) }}"
method="POST"
x-data
x-on:change="$root.submit()"
>
@csrf
<p class="form__group">
<input
id="snoozed_days"
class="form__text"
name="snoozed_days"
placeholder=" "
inputmode="numeric"
pattern="[0-9]*"
type="text"
/>
<label for="snoozed_days" class="form__label form__label--floating">
Custom Days
</label>
</p>
<div class="form__group--short-horizontal">
<p class="form__group form__group--short-horizontal">
<button
name="snoozed_until"
value="{{ now()->addDays(1) }}"
class="form__button form__button--outlined form__button--centered"
>
1 day
</button>
</p>
<p class="form__group form__group--short-horizontal">
<button
name="snoozed_until"
value="{{ now()->addDays(3) }}"
class="form__button form__button--outlined form__button--centered"
>
3 days
</button>
</p>
<p class="form__group form__group--short-horizontal">
<button
name="snoozed_until"
value="{{ now()->addDays(7) }}"
class="form__button form__button--outlined form__button--centered"
>
1 week
</button>
</p>
<p class="form__group form__group--short-horizontal">
<button
name="snoozed_until"
value="{{ now()->addDays(14) }}"
class="form__button form__button--outlined form__button--centered"
>
2 weeks
</button>
</p>
<p class="form__group form__group--short-horizontal">
<button
name="snoozed_until"
value="{{ now()->addDays(28) }}"
class="form__button form__button--outlined form__button--centered"
>
4 weeks
</button>
</p>
<p class="form__group form__group--short-horizontal">
<button
name="snoozed_until"
value="{{ now()->addDays(56) }}"
class="form__button form__button--outlined form__button--centered"
>
8 weeks
</button>
</p>
</div>
</form>
@else
<form
class="form"
action="{{ route('staff.snoozed_reports.destroy', ['report' => $report]) }}"
method="POST"
>
@csrf
@method('DELETE')
<input type="hidden" name="snoozed_until" value="" />
<p class="form__group form__group--horizontal">
<button class="form__button form__button--centered form__button--filled">
<i class="{{ config('other.font-awesome') }} fa-clock"></i>
Unsnooze
</button>
</p>
</form>
@endif
</div>
</section>
@endsection

View File

@@ -130,6 +130,15 @@
{{ __('common.quantity') }}
</label>
</p>
<p class="form__group">
<input
id="hideSnoozed"
class="form__checkbox"
type="checkbox"
wire:model.live="hideSnoozed"
/>
<label class="form__label" for="hideSnoozed">Hide Snoozed</label>
</p>
</div>
</form>
</div>

View File

@@ -1030,6 +1030,14 @@ Route::middleware('language')->group(function (): void {
});
});
// Snoozed Reports
Route::prefix('snoozed-reports')->group(function (): void {
Route::name('snoozed_reports.')->group(function (): void {
Route::post('/{report}', [App\Http\Controllers\Staff\SnoozedReportController::class, 'store'])->name('store');
Route::delete('/{report}', [App\Http\Controllers\Staff\SnoozedReportController::class, 'destroy'])->name('destroy');
});
});
// Resolutions
Route::prefix('resolutions')->group(function (): void {
Route::name('resolutions.')->group(function (): void {