Update admin instance page, add search and improve performance

This commit is contained in:
Daniel Supernault 2021-04-20 22:03:41 -06:00
parent ab755811d1
commit f582937300
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 115 additions and 95 deletions

View file

@ -14,29 +14,58 @@ trait AdminInstanceController
public function instances(Request $request) public function instances(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'filter' => [ 'filter' => [
'nullable', 'nullable',
'string', 'string',
'min:1', 'min:1',
'max:20', 'max:20',
Rule::in(['autocw', 'unlisted', 'banned']) Rule::in([
'cw',
'unlisted',
'banned',
// 'popular',
'new',
'all'
])
], ],
]); ]);
if($request->has('filter') && $request->filled('filter')) { if($request->has('q') && $request->filled('q')) {
$instances = Instance::where('domain', 'like', '%' . $request->input('q') . '%')->simplePaginate(10);
} else if($request->has('filter') && $request->filled('filter')) {
switch ($request->filter) { switch ($request->filter) {
case 'autocw': case 'cw':
$instances = Instance::whereAutoCw(true)->orderByDesc('id')->paginate(5); $instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->whereAutoCw(true)->orderByDesc('id')->simplePaginate(10);
break; break;
case 'unlisted': case 'unlisted':
$instances = Instance::whereUnlisted(true)->orderByDesc('id')->paginate(5); $instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->whereUnlisted(true)->orderByDesc('id')->simplePaginate(10);
break; break;
case 'banned': case 'banned':
$instances = Instance::whereBanned(true)->orderByDesc('id')->paginate(5); $instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->whereBanned(true)->orderByDesc('id')->simplePaginate(10);
break;
case 'new':
$instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->latest()->simplePaginate(10);
break;
// case 'popular':
// $popular = Profile::selectRaw('*, count(domain) as count')
// ->whereNotNull('domain')
// ->groupBy('domain')
// ->orderByDesc('count')
// ->take(10)
// ->get()
// ->pluck('domain')
// ->toArray();
// $instances = Instance::whereIn('domain', $popular)->simplePaginate(10);
// break;
default:
$instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->orderByDesc('id')->simplePaginate(10);
break; break;
} }
} else { } else {
$instances = Instance::orderByDesc('id')->paginate(5); $instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->orderByDesc('id')->simplePaginate(10);
} }
return view('admin.instances.home', compact('instances')); return view('admin.instances.home', compact('instances'));
} }

View file

@ -1,59 +1,49 @@
@extends('admin.partial.template-full') @extends('admin.partial.template-full')
@section('section') @section('section')
<div class="title"> <div class="title d-flex justify-content-between align-items-center">
<h3 class="font-weight-bold d-inline-block">Instances</h3> <h3 class="font-weight-bold mr-5">Instances</h3>
<span class="float-right"> <div class="btn-group btn-group-sm">
<div class="dropdown"> <a class="btn btn-{{!request()->filled('filter')||request()->query('filter')=='all'?'primary':'outline-primary'}} font-weight-bold" href="?filter=all">All</a>
<button class="btn btn-light btn-sm dropdown-toggle font-weight-bold" type="button" id="filterDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> {{-- <a class="btn btn-{{request()->query('filter')=='popular'?'primary':'outline-primary'}} font-weight-bold" href="?filter=popular">Popular</a> --}}
<i class="fas fa-filter"></i> <a class="btn btn-{{request()->query('filter')=='new'?'primary':'outline-primary'}} font-weight-bold" href="?filter=new">New</a>
</button> <a class="btn btn-{{request()->query('filter')=='cw'?'primary':'outline-primary'}} font-weight-bold" href="?filter=cw">CW</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="filterDropdown"> <a class="btn btn-{{request()->query('filter')=='banned'?'primary':'outline-primary'}} font-weight-bold" href="?filter=banned">Banned</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=unlisted">Show only Unlisted</a> <a class="btn btn-{{request()->query('filter')=='unlisted'?'primary':'outline-primary'}} font-weight-bold" href="?filter=unlisted">Unlisted</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=autocw">Show only Auto CW</a> </div>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=banned">Show only Banned</a> <div class="">
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}">Show all</a> </div>
<div class="dropdown-divider"></div> <form class="" method="get">
<form class="" method="post"> <input class="form-control rounded-pill" name="q" value="{{request()->query('q')}}" placeholder="Search domain">
@csrf
<button type="submit" class="btn btn-primary py-1 font-weight-bold btn-sm btn-block">Run Scan</button>
</form> </form>
</div>
</div>
</span>
</div> </div>
<hr> <hr>
@if($instances->count() == 0 && request()->has('filter') == false)
<div class="alert alert-warning mb-3"> <div class="row">
<div class="col-12 col-md-8 offset-md-2">
@if($instances->count() == 0 && !request()->has('filter') && !request()->has('q'))
<div class="alert alert-warning mb-3">
<p class="lead font-weight-bold mb-0">Warning</p> <p class="lead font-weight-bold mb-0">Warning</p>
<p class="font-weight-lighter mb-0">No instances were found.</p> <p class="font-weight-lighter mb-0">No instances were found.</p>
</div> </div>
<p class="font-weight-lighter">Do you want to scan and populate instances from Profiles and Statuses?</p> <p class="font-weight-lighter">Do you want to scan and populate instances from Profiles and Statuses?</p>
<p> <p>
<form method="post"> <form method="post">
@csrf @csrf
<button type="submit" class="btn btn-primary py-1 font-weight-bold">Run Scan</button> <button type="submit" class="btn btn-primary py-1 font-weight-bold">Run Scan</button>
</form> </form>
</p> </p>
@else @else
<ul class="list-group"> <ul class="list-group">
@foreach($instances as $instance) @foreach($instances as $instance)
<li class="list-group-item"> <li class="list-group-item">
<div class="d-flex justify-content-between align-items-center">
<div> <div>
<p class="h4 font-weight-normal mb-1"> <div class="d-flex justify-content-between align-items-center">
<p class="h4 font-weight-light mb-0 text-break mr-2">
{{$instance->domain}} {{$instance->domain}}
</p> </p>
<p class="mb-0"> <p class="mb-0 text-right" style="min-width: 210px;">
<a class="btn btn-outline-primary btn-sm py-0 font-weight-normal" href="{{$instance->getUrl()}}">Overview</a>
<button class="btn btn-outline-secondary btn-sm py-0 font-weight-normal btn-action mr-3"
data-instance-id="{{$instance->id}}"
data-instance-domain="{{$instance->domain}}"
data-instance-unlisted="{{$instance->unlisted}}"
data-instance-autocw="{{$instance->auto_cw}}"
data-instance-banned="{{$instance->banned}}"
>Actions</button>
@if($instance->unlisted) @if($instance->unlisted)
<i class="fas fa-minus-circle text-danger" data-toggle="tooltip" title="Unlisted from timelines"></i> <i class="fas fa-minus-circle text-danger" data-toggle="tooltip" title="Unlisted from timelines"></i>
@endif @endif
@ -63,34 +53,35 @@
@if($instance->banned) @if($instance->banned)
<i class="fas fa-shield-alt text-danger" data-toggle="tooltip" title="Instance is banned"></i> <i class="fas fa-shield-alt text-danger" data-toggle="tooltip" title="Instance is banned"></i>
@endif @endif
<a class="btn btn-outline-primary btn-sm py-0 font-weight-normal ml-2" href="{{$instance->getUrl()}}">Overview</a>
<button class="btn btn-outline-secondary btn-sm py-0 font-weight-normal btn-action"
data-instance-id="{{$instance->id}}"
data-instance-domain="{{$instance->domain}}"
data-instance-unlisted="{{$instance->unlisted}}"
data-instance-autocw="{{$instance->auto_cw}}"
data-instance-banned="{{$instance->banned}}"
>Actions</button>
</p> </p>
</div> </div>
<div>
<div class="d-inline-block pr-4">
<p class="h4 font-weight-light text-center">{{$instance->profiles()->count()}}</p>
<p class="mb-0 small font-weight-normal text-muted">Profiles</p>
</div>
<div class="d-inline-block pr-4">
<p class="h4 font-weight-light text-center">{{$instance->statuses()->count()}}</p>
<p class="mb-0 small font-weight-normal text-muted">Statuses</p>
</div>
<div class="d-inline-block pr-4">
<p class="h4 font-weight-light text-center text-muted">{{$instance->reported()->count()}}</p>
<p class="mb-0 small font-weight-normal text-muted">Reports</p>
</div>
<div class="d-inline-block">
<p class="h4 font-weight-light text-center text-muted filesize" data-size="{{$instance->media()->sum('size')}}">0</p>
<p class="mb-0 small font-weight-normal text-muted">Storage Used</p>
</div>
</div>
</div> </div>
</li> </li>
@endforeach @endforeach
</ul> </ul>
<div class="d-flex justify-content-center mt-5 small"> <div class="d-flex justify-content-center mt-5 small">
{{$instances->links()}} {{$instances->links()}}
</div>
@endif
@if(request()->filled('q') && $instances->count() == 0)
<p class="text-center lead mb-0">No results found</p>
<p class="text-center font-weight-bold mb-0"><a href="/i/admin/instances">Go back</a></p>
@endif
@if(request()->filled('filter') && $instances->count() == 0)
<p class="text-center lead mb-0">No results found</p>
<p class="text-center font-weight-bold mb-0"><a href="/i/admin/instances">Go back</a></p>
@endif
</div>
</div> </div>
@endif
@endsection @endsection
@push('scripts') @push('scripts')