mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update user admin, remove expensive db query and add search
This commit is contained in:
parent
7b7e7cf697
commit
8feeadbf4e
2 changed files with 40 additions and 19 deletions
|
@ -16,14 +16,27 @@ trait AdminUserController
|
|||
{
|
||||
public function users(Request $request)
|
||||
{
|
||||
$search = $request->has('a') && $request->query('a') == 'search' ? $request->query('q') : null;
|
||||
$col = $request->query('col') ?? 'id';
|
||||
$dir = $request->query('dir') ?? 'desc';
|
||||
$users = User::select('id', 'username', 'status')
|
||||
->withCount('statuses')
|
||||
$offset = $request->has('page') ? $request->input('page') : 1;
|
||||
$pagination = [
|
||||
'prev' => $offset && $offset > 1 ? $offset - 1 : null,
|
||||
'next' => $offset + 1,
|
||||
'query' => $search ? '&a=search&q=' . $search : null
|
||||
];
|
||||
$users = User::select('id', 'username', 'status', 'profile_id')
|
||||
->orderBy($col, $dir)
|
||||
->simplePaginate(10);
|
||||
->when($search, function($q, $search) {
|
||||
return $q->where('username', 'like', "%{$search}%");
|
||||
})
|
||||
->when($offset > 1, function($q, $offset) {
|
||||
return $q->offset(($offset * 10));
|
||||
})
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
return view('admin.users.home', compact('users'));
|
||||
return view('admin.users.home', compact('users', 'pagination'));
|
||||
}
|
||||
|
||||
public function userShow(Request $request, $id)
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
@extends('admin.partial.template-full')
|
||||
|
||||
@section('header')
|
||||
<div class="bg-primary">
|
||||
<div class="container">
|
||||
<div class="my-5">test</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('section')
|
||||
<div class="title">
|
||||
<div class="title d-flex justify-content-between align-items-center">
|
||||
<h3 class="font-weight-bold">Users</h3>
|
||||
<form method="get">
|
||||
<input type="hidden" name="a" value="search">
|
||||
<div class="input-group">
|
||||
<input class="form-control" name="q" placeholder="Search usernames" value="{{request()->input('q')}}">
|
||||
<div class="input-group-append">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fas fa-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="table-responsive">
|
||||
|
@ -36,7 +39,6 @@
|
|||
<span class="text-danger" class="text-monospace">{{$user->id}}</span>
|
||||
</th>
|
||||
<td class="text-left">
|
||||
<img src="/storage/avatars/default.png?v=3" width="28px" class="rounded-circle mr-2" style="border:1px solid #ccc">
|
||||
<span title="{{$user->username}}" data-toggle="tooltip" data-placement="bottom">
|
||||
<span class="text-danger">{{$user->username}}</span>
|
||||
</span>
|
||||
|
@ -53,7 +55,6 @@
|
|||
<span class="text-monospace">{{$user->id}}</span>
|
||||
</th>
|
||||
<td class="text-left">
|
||||
<img src="{{$user->profile->avatarUrl()}}" width="28px" class="rounded-circle mr-2" style="border:1px solid #ccc">
|
||||
<span title="{{$user->username}}" data-toggle="tooltip" data-placement="bottom">
|
||||
<span>{{$user->username}}</span>
|
||||
@if($user->is_admin)
|
||||
|
@ -63,7 +64,7 @@
|
|||
</td>
|
||||
<td>
|
||||
<span class="action-row font-weight-lighter">
|
||||
<a href="{{$user->url()}}" class="pr-2 text-muted small font-weight-bold" title="View Profile" data-toggle="tooltip" data-placement="bottom">
|
||||
<a href="/{{$user->username}}" class="pr-2 text-muted small font-weight-bold" title="View Profile" data-toggle="tooltip" data-placement="bottom">
|
||||
Profile
|
||||
</a>
|
||||
|
||||
|
@ -71,8 +72,8 @@
|
|||
Review
|
||||
</a>
|
||||
|
||||
<a href="/i/admin/users/modlogs/{{$user->id}}" class="pr-2 text-muted small font-weight-bold" title="Moderation Logs" data-toggle="tooltip" data-placement="bottom">
|
||||
Mod Logs
|
||||
<a href="/i/admin/users/modtools/{{$user->id}}" class="pr-2 text-muted small font-weight-bold" title="Moderation Logs" data-toggle="tooltip" data-placement="bottom">
|
||||
Mod Tools
|
||||
</a>
|
||||
</span>
|
||||
</td>
|
||||
|
@ -83,7 +84,14 @@
|
|||
</table>
|
||||
</div>
|
||||
<div class="d-flex justify-content-center mt-5 small">
|
||||
{{$users->links()}}
|
||||
<ul class="pagination">
|
||||
@if($pagination['prev'])
|
||||
<li class="page-item"><a class="page-link pagination__prev" href="?page={{$pagination['prev']}}{{$pagination['query']}}" rel="prev">« Previous</a></li>
|
||||
@else
|
||||
<li class="page-item disabled"><span class="page-link" >« Previous</span></li>
|
||||
@endif
|
||||
<li class="page-item"><a class="page-link pagination__next" href="?page={{$pagination['next']}}{{$pagination['query']}}" rel="next">Next »</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
|
|
Loading…
Reference in a new issue