Merge pull request #2680 from pixelfed/staging

Update user admin, remove expensive db query and add search
This commit is contained in:
daniel 2021-02-23 00:06:01 -07:00 committed by GitHub
commit 46ca396360
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 19 deletions

View file

@ -47,6 +47,7 @@
- Updated Timeline component, add inline reports modal. ([e64b4bd3](https://github.com/pixelfed/pixelfed/commit/e64b4bd3)) - Updated Timeline component, add inline reports modal. ([e64b4bd3](https://github.com/pixelfed/pixelfed/commit/e64b4bd3))
- Updated federation pipeline, add locks. ([ddc76887](https://github.com/pixelfed/pixelfed/commit/ddc76887)) - Updated federation pipeline, add locks. ([ddc76887](https://github.com/pixelfed/pixelfed/commit/ddc76887))
- Updated MediaStorageService, improve head checks to fix failed jobs. ([1769cdfd](https://github.com/pixelfed/pixelfed/commit/1769cdfd)) - Updated MediaStorageService, improve head checks to fix failed jobs. ([1769cdfd](https://github.com/pixelfed/pixelfed/commit/1769cdfd))
- Updated user admin, remove expensive db query and add search. ([8feeadbf](https://github.com/pixelfed/pixelfed/commit/8feeadbf))
- ([](https://github.com/pixelfed/pixelfed/commit/)) - ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)

View file

@ -16,14 +16,27 @@ trait AdminUserController
{ {
public function users(Request $request) public function users(Request $request)
{ {
$search = $request->has('a') && $request->query('a') == 'search' ? $request->query('q') : null;
$col = $request->query('col') ?? 'id'; $col = $request->query('col') ?? 'id';
$dir = $request->query('dir') ?? 'desc'; $dir = $request->query('dir') ?? 'desc';
$users = User::select('id', 'username', 'status') $offset = $request->has('page') ? $request->input('page') : 1;
->withCount('statuses') $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) ->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) public function userShow(Request $request, $id)

View file

@ -1,16 +1,19 @@
@extends('admin.partial.template-full') @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') @section('section')
<div class="title"> <div class="title d-flex justify-content-between align-items-center">
<h3 class="font-weight-bold">Users</h3> <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> </div>
<hr> <hr>
<div class="table-responsive"> <div class="table-responsive">
@ -36,7 +39,6 @@
<span class="text-danger" class="text-monospace">{{$user->id}}</span> <span class="text-danger" class="text-monospace">{{$user->id}}</span>
</th> </th>
<td class="text-left"> <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 title="{{$user->username}}" data-toggle="tooltip" data-placement="bottom">
<span class="text-danger">{{$user->username}}</span> <span class="text-danger">{{$user->username}}</span>
</span> </span>
@ -53,7 +55,6 @@
<span class="text-monospace">{{$user->id}}</span> <span class="text-monospace">{{$user->id}}</span>
</th> </th>
<td class="text-left"> <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 title="{{$user->username}}" data-toggle="tooltip" data-placement="bottom">
<span>{{$user->username}}</span> <span>{{$user->username}}</span>
@if($user->is_admin) @if($user->is_admin)
@ -63,7 +64,7 @@
</td> </td>
<td> <td>
<span class="action-row font-weight-lighter"> <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 Profile
</a> </a>
@ -71,8 +72,8 @@
Review Review
</a> </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"> <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 Logs Mod Tools
</a> </a>
</span> </span>
</td> </td>
@ -83,7 +84,14 @@
</table> </table>
</div> </div>
<div class="d-flex justify-content-center mt-5 small"> <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> </div>
@endsection @endsection