From 5405b213903785e0c215efcf9c7125bddbd14731 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 7 Jul 2020 13:13:29 +0100 Subject: [PATCH] Better sort admin user table. Sort the table when showing search results, and show users without name at the bottom, rather than at the top. --- CHANGELOG.md | 1 + .../FixMyStreet/App/Controller/Admin/Users.pm | 23 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d05be748ce..e36b2017d44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Admin improvements: - Display user name/email for contributed as reports. #2990 - Interface for enabling anonymous reports for certain categories. #2989 + - Better sort admin user table. - Development improvements: - `#geolocate_link` is now easier to re-style. #3006 - Links inside `#front-main` can be customised using `$primary_link_*` Sass variables. #3007 diff --git a/perllib/FixMyStreet/App/Controller/Admin/Users.pm b/perllib/FixMyStreet/App/Controller/Admin/Users.pm index 5bb91341dec..c73f1429b6d 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Users.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Users.pm @@ -47,8 +47,8 @@ sub index :Path : Args(0) { my $search = $c->get_param('search'); my $role = $c->get_param('role'); + my $users = $c->cobrand->users; if ($search || $role) { - my $users = $c->cobrand->users; my $isearch; if ($search) { $search = $self->trim($search); @@ -78,25 +78,20 @@ sub index :Path : Args(0) { join => 'user_roles', }); } - - my @users = $users->all; - $c->stash->{users} = [ @users ]; - if ($search) { - $c->forward('/admin/add_flags', [ { email => { ilike => $isearch } } ]); - } - } else { $c->forward('/auth/get_csrf_token'); $c->forward('/admin/fetch_all_bodies'); $c->cobrand->call_hook('admin_user_edit_extra_data'); # Admin users by default - my $users = $c->cobrand->users->search( - { from_body => { '!=', undef } }, - { order_by => 'name' } - ); - my @users = $users->all; - $c->stash->{users} = \@users; + $users = $users->search({ from_body => { '!=', undef } }); + } + + $users = $users->search(undef, { order_by => [ \"name = ''", 'name' ] }); + my @users = $users->all; + $c->stash->{users} = \@users; + if ($search) { + $c->forward('/admin/add_flags', [ { email => { ilike => "%$search%" } } ]); } my $rs;