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)
{
$this->validate($request, [
'filter' => [
'nullable',
'string',
'min:1',
'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) {
case 'autocw':
$instances = Instance::whereAutoCw(true)->orderByDesc('id')->paginate(5);
case 'cw':
$instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->whereAutoCw(true)->orderByDesc('id')->simplePaginate(10);
break;
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;
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;
}
} 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'));
}
@ -99,4 +128,4 @@ trait AdminInstanceController
return response()->json([]);
}
}
}

View file

@ -1,96 +1,87 @@
@extends('admin.partial.template-full')
@section('section')
<div class="title">
<h3 class="font-weight-bold d-inline-block">Instances</h3>
<span class="float-right">
<div class="dropdown">
<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">
<i class="fas fa-filter"></i>
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="filterDropdown">
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=unlisted">Show only Unlisted</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=autocw">Show only Auto CW</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=banned">Show only Banned</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}">Show all</a>
<div class="dropdown-divider"></div>
<form class="" method="post">
@csrf
<button type="submit" class="btn btn-primary py-1 font-weight-bold btn-sm btn-block">Run Scan</button>
</form>
</div>
</div>
</span>
<div class="title d-flex justify-content-between align-items-center">
<h3 class="font-weight-bold mr-5">Instances</h3>
<div class="btn-group btn-group-sm">
<a class="btn btn-{{!request()->filled('filter')||request()->query('filter')=='all'?'primary':'outline-primary'}} font-weight-bold" href="?filter=all">All</a>
{{-- <a class="btn btn-{{request()->query('filter')=='popular'?'primary':'outline-primary'}} font-weight-bold" href="?filter=popular">Popular</a> --}}
<a class="btn btn-{{request()->query('filter')=='new'?'primary':'outline-primary'}} font-weight-bold" href="?filter=new">New</a>
<a class="btn btn-{{request()->query('filter')=='cw'?'primary':'outline-primary'}} font-weight-bold" href="?filter=cw">CW</a>
<a class="btn btn-{{request()->query('filter')=='banned'?'primary':'outline-primary'}} font-weight-bold" href="?filter=banned">Banned</a>
<a class="btn btn-{{request()->query('filter')=='unlisted'?'primary':'outline-primary'}} font-weight-bold" href="?filter=unlisted">Unlisted</a>
</div>
<div class="">
</div>
<form class="" method="get">
<input class="form-control rounded-pill" name="q" value="{{request()->query('q')}}" placeholder="Search domain">
</form>
</div>
<hr>
@if($instances->count() == 0 && request()->has('filter') == false)
<div class="alert alert-warning mb-3">
<p class="lead font-weight-bold mb-0">Warning</p>
<p class="font-weight-lighter mb-0">No instances were found.</p>
</div>
<p class="font-weight-lighter">Do you want to scan and populate instances from Profiles and Statuses?</p>
<p>
<form method="post">
@csrf
<button type="submit" class="btn btn-primary py-1 font-weight-bold">Run Scan</button>
</form>
</p>
@else
<ul class="list-group">
@foreach($instances as $instance)
<li class="list-group-item">
<div class="d-flex justify-content-between align-items-center">
<div>
<p class="h4 font-weight-normal mb-1">
{{$instance->domain}}
</p>
<p class="mb-0">
<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)
<i class="fas fa-minus-circle text-danger" data-toggle="tooltip" title="Unlisted from timelines"></i>
@endif
@if($instance->auto_cw)
<i class="fas fa-eye-slash text-danger" data-toggle="tooltip" title="CW applied to all media"></i>
@endif
@if($instance->banned)
<i class="fas fa-shield-alt text-danger" data-toggle="tooltip" title="Instance is banned"></i>
@endif
</p>
</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 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="font-weight-lighter mb-0">No instances were found.</p>
</div>
</li>
@endforeach
</ul>
<div class="d-flex justify-content-center mt-5 small">
{{$instances->links()}}
<p class="font-weight-lighter">Do you want to scan and populate instances from Profiles and Statuses?</p>
<p>
<form method="post">
@csrf
<button type="submit" class="btn btn-primary py-1 font-weight-bold">Run Scan</button>
</form>
</p>
@else
<ul class="list-group">
@foreach($instances as $instance)
<li class="list-group-item">
<div>
<div class="d-flex justify-content-between align-items-center">
<p class="h4 font-weight-light mb-0 text-break mr-2">
{{$instance->domain}}
</p>
<p class="mb-0 text-right" style="min-width: 210px;">
@if($instance->unlisted)
<i class="fas fa-minus-circle text-danger" data-toggle="tooltip" title="Unlisted from timelines"></i>
@endif
@if($instance->auto_cw)
<i class="fas fa-eye-slash text-danger" data-toggle="tooltip" title="CW applied to all media"></i>
@endif
@if($instance->banned)
<i class="fas fa-shield-alt text-danger" data-toggle="tooltip" title="Instance is banned"></i>
@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>
</div>
</div>
</li>
@endforeach
</ul>
<div class="d-flex justify-content-center mt-5 small">
{{$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>
@endif
@endsection
@push('scripts')
@ -109,7 +100,7 @@
let banned = this.getAttribute('data-instance-banned');
swal({
title: 'Instance Actions',
text: text,
text: text,
icon: 'warning',
buttons: {
unlist: {
@ -224,4 +215,4 @@
})
});
</script>
@endpush
@endpush