Add shortcode & domain search

This commit is contained in:
Daniel Supernault 2022-01-21 01:12:56 -07:00
parent efeaf427e1
commit dc7962d898
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 36 additions and 5 deletions

View file

@ -355,7 +355,7 @@ class AdminController extends Controller
return view('admin.custom-emoji.not-enabled'); return view('admin.custom-emoji.not-enabled');
} }
$this->validate($request, [ $this->validate($request, [
'sort' => 'sometimes|in:all,local,remote,duplicates,disabled' 'sort' => 'sometimes|in:all,local,remote,duplicates,disabled,search'
]); ]);
if($request->has('cc')) { if($request->has('cc')) {
@ -364,7 +364,12 @@ class AdminController extends Controller
} }
$sort = $request->input('sort') ?? 'all'; $sort = $request->input('sort') ?? 'all';
$emojis = CustomEmoji::when($sort, function($query, $sort) {
if($sort == 'search' && empty($request->input('q'))) {
return redirect(route('admin.custom-emoji'));
}
$emojis = CustomEmoji::when($sort, function($query, $sort) use($request) {
if($sort == 'all') { if($sort == 'all') {
return $query->groupBy('shortcode')->latest(); return $query->groupBy('shortcode')->latest();
} else if($sort == 'local') { } else if($sort == 'local') {
@ -375,8 +380,19 @@ class AdminController extends Controller
return $query->latest()->groupBy('shortcode')->havingRaw('count(*) > 1'); return $query->latest()->groupBy('shortcode')->havingRaw('count(*) > 1');
} else if($sort == 'disabled') { } else if($sort == 'disabled') {
return $query->latest()->whereDisabled(true); return $query->latest()->whereDisabled(true);
} else if($sort == 'search') {
$q = $query
->latest()
->where('shortcode', 'like', '%' . $request->input('q') . '%')
->orWhere('domain', 'like', '%' . $request->input('q') . '%');
if(!$request->has('dups')) {
$q = $q->groupBy('shortcode');
}
return $q;
} }
})->cursorPaginate(10); })
->simplePaginate(10)
->withQueryString();
$stats = Cache::remember('pf:admin:custom_emoji:stats', 43200, function() { $stats = Cache::remember('pf:admin:custom_emoji:stats', 43200, function() {
return [ return [

View file

@ -37,7 +37,7 @@
</div> </div>
<div class="col-xl-4 col-md-6"> <div class="col-xl-4 col-md-6">
<a <a
class="btn btn-dark btn-lg px-3" class="btn btn-dark btn-lg px-3 mb-1"
href="/i/admin/custom-emoji/new"> href="/i/admin/custom-emoji/new">
<i class="far fa-plus mr-1"></i> <i class="far fa-plus mr-1"></i>
Add Custom Emoji Add Custom Emoji
@ -55,10 +55,22 @@
</div> </div>
</div> </div>
<div class="container mt-5"> <div class="container mt-5">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-12 col-md-6"> <div class="col-12 col-md-6">
<form method="get" class="mb-3" id="duplicate-form">
<input type="hidden" name="sort" value="search">
<input class="form-control rounded-pill" name="q" placeholder="Search by shortcode or domain name" value="{{request()->input('q')}}">
@if($sort == 'search')
<div class="custom-control custom-checkbox mt-1">
<input type="checkbox" class="custom-control-input" id="showDuplicate" name="dups" value="1" onclick="document.getElementById('duplicate-form').submit()" {{ request()->has('dups') ? 'checked' : ''}}>
<label class="custom-control-label" for="showDuplicate">Show duplicate results</label>
</div>
@endif
</form>
<ul class="nav nav-pills mb-3 nav-fill"> @if($sort != 'search')
<ul class="nav nav-pills my-3 nav-fill">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {{$sort=='all'?'active':''}}" href="?sort=all">All</a> <a class="nav-link {{$sort=='all'?'active':''}}" href="?sort=all">All</a>
</li> </li>
@ -79,6 +91,7 @@
<a class="nav-link {{$sort=='disabled'?'active':''}}" href="?sort=disabled">Disabled</a> <a class="nav-link {{$sort=='disabled'?'active':''}}" href="?sort=disabled">Disabled</a>
</li> </li>
</ul> </ul>
@endif
@if($sort == 'duplicates') @if($sort == 'duplicates')
<div class="alert alert-warning py-2 mt-4"> <div class="alert alert-warning py-2 mt-4">
@ -96,7 +109,9 @@
<div class="media-body"> <div class="media-body">
<p class="font-weight-bold mb-0">{{ $emoji->shortcode }}</p> <p class="font-weight-bold mb-0">{{ $emoji->shortcode }}</p>
@if($emoji->domain != config('pixelfed.domain.app'))
<p class="text-muted small mb-0">{{ $emoji->domain }}</p> <p class="text-muted small mb-0">{{ $emoji->domain }}</p>
@endif
</div> </div>
@if($sort == 'duplicates') @if($sort == 'duplicates')