diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 112 | ||||
-rw-r--r-- | templates/web/default/admin/council_list.html | 47 | ||||
-rw-r--r-- | templates/web/default/admin/header.html | 3 |
3 files changed, 98 insertions, 64 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 304eafd1c..fcc55cba0 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -4,7 +4,7 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } -use mySociety::Random qw(random_bytes); +use POSIX qw(strftime strcoll); =head1 NAME @@ -143,6 +143,55 @@ sub questionnaire : Path('questionnaire') : Args(0) { return 1; } + +sub council_list : Path('council_list') : Args(0) { + my ( $self, $c ) = @_; + + my $edit_activity = $c->model('DB::ContactsHistory')->search( + undef, + { + select => [ 'editor', { count => 'contacts_history_id', -as => 'c' } ], + group_by => ['editor'], + order_by => { -desc => 'c' } + } + ); + + $c->stash->{edit_activity} = $edit_activity; + + my @area_types = $c->cobrand->area_types; + my $areas = mySociety::MaPit::call('areas', \@area_types); + + my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; + # this is for norway only - put in cobrand + @councils_ids = grep { $_ ne 301 } @councils_ids; + + my $contacts = $c->model('DB::Contact')->search( + undef, + { + select => [ 'area_id', { count => 'id' }, { count => \'case when deleted then 1 else null end' }, + { count => \'case when confirmed then 1 else null end' } ], + as => [qw/area_id c deleted confirmed/], + group_by => [ 'area_id' ], + result_class => 'DBIx::Class::ResultClass::HashRefInflator' + } + ); + + my %council_info = map { $_->{area_id} => $_ } $contacts->all; + + my @no_info = grep { !$council_info{$_} } @councils_ids; + my @one_plus_deleted = grep { $council_info{$_} && $council_info{$_}->{deleted} } @councils_ids; + my @unconfirmeds = grep { $council_info{$_} && !$council_info{$_}->{deleted} && $council_info{$_}->{confirmed} != $council_info{$_}->{c} } @councils_ids; + my @all_confirmed = grep { $council_info{$_} && !$council_info{$_}->{deleted} && $council_info{$_}->{confirmed} == $council_info{$_}->{c} } @councils_ids; + + $c->stash->{areas} = $areas; + $c->stash->{counts} = \%council_info; + $c->stash->{no_info} = \@no_info; + $c->stash->{one_plus_deleted} = \@one_plus_deleted; + $c->stash->{unconfirmeds} = \@unconfirmeds; + $c->stash->{all_confirmed} = \@all_confirmed; + + return 1; +} # use Encode; # use POSIX qw(strftime strcoll); # use Digest::MD5 qw(md5_hex); @@ -222,67 +271,6 @@ sub questionnaire : Path('questionnaire') : Args(0) { # } # # -# # admin_councils_list CGI -# sub admin_councils_list ($) { -# my ($q) = @_; -# -# print html_head($q, _("Council contacts")); -# print $q->h1(_("Council contacts")); -# -# # Table of editors -# print $q->h2(_("Diligency prize league table")); -# my $edit_activity = dbh()->selectall_arrayref("select count(*) as c, editor from contacts_history group by editor order by c desc"); -# if (@$edit_activity) { -# print $q->ul( -# map { $q->li( sprintf(_('%d edits by %s'), $_->[0], $_->[1])) } @$edit_activity -# ); -# } else { -# print $q->p(_('No edits have yet been made.')); -# } -# -# # Table of councils -# print $q->h2(_("Councils")); -# my $cobrand = Page::get_cobrand($q); -# my @area_types = Cobrand::area_types($cobrand); -# my $areas = mySociety::MaPit::call('areas', \@area_types); -# my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; -# @councils_ids = grep { $_ ne 301 } @councils_ids; -# my $bci_info = dbh()->selectall_hashref(" -# select area_id, count(*) as c, count(case when deleted then 1 else null end) as deleted, -# count(case when confirmed then 1 else null end) as confirmed -# from contacts group by area_id", 'area_id'); -# -# my $list_part = sub { -# my @ids = @_; -# if (!scalar(@ids)) { -# print _("None"); -# return; -# } -# my @li; -# foreach (@ids) { -# my $parent = ''; -# $parent = ', ' . $areas->{$areas->{$_}->{parent_area}}->{name} -# if $areas->{$_}->{parent_area}; -# -# push @li, $q->li($q->a({ href => NewURL($q, area_id => $_, page => 'councilcontacts') }, -# $areas->{$_}->{name}) . $parent . ' ' . -# ($bci_info->{$_} && $q->{site} ne 'emptyhomes' ? -# sprintf(_('%d addresses'), $bci_info->{$_}->{c}) -# : '')); -# } -# print $q->ul(@li); -# }; -# -# print $q->h3(_('No info at all')); -# &$list_part(grep { !$bci_info->{$_} } @councils_ids); -# print $q->h3(_('Currently has 1+ deleted')); -# &$list_part(grep { $bci_info->{$_} && $bci_info->{$_}->{deleted} } @councils_ids); -# print $q->h3(_('Some unconfirmeds')); -# &$list_part(grep { $bci_info->{$_} && !$bci_info->{$_}->{deleted} && $bci_info->{$_}->{confirmed} != $bci_info->{$_}->{c} } @councils_ids); -# print $q->h3(_('All confirmed')); -# &$list_part(grep { $bci_info->{$_} && !$bci_info->{$_}->{deleted} && $bci_info->{$_}->{confirmed} == $bci_info->{$_}->{c} } @councils_ids); -# print html_tail($q); -# } # # # admin_council_contacts CGI AREA_ID # sub admin_council_contacts ($$) { diff --git a/templates/web/default/admin/council_list.html b/templates/web/default/admin/council_list.html new file mode 100644 index 000000000..28aefbc3c --- /dev/null +++ b/templates/web/default/admin/council_list.html @@ -0,0 +1,47 @@ +[% INCLUDE 'admin/header.html' title=loc('Council contacts') -%] + +[%- BLOCK details %] +[%- IF councils.size == 0 %] + [%- loc('None') %] +[%- ELSE %] +[%- FOREACH council IN councils %] + [%- IF council.parent_area %] + [%- + p_area = areas.$council.parent_area + parent = ', ' _ areas.$parent.name + %] + [%- ELSE %] + [%- parent = '' %] + [%- END %] + [%- '<ul>' IF loop.first %] + <li><a href="[% c.uri_for( 'council_contacts', council ) %]">[% areas.$council.name %] [% parent %][% tprintf( loc('%d addresses'), counts.$council.c) IF counts.$council && c.cobrand.moniker != 'emptyhomes' %]</a> + [%- '</ul>' IF loop.last %] +[%- END %] +[%- END %] +[%- END %] + +<h2>[% loc('Diligency prize league table') %]</h2> +[% IF edit_activity.count %] +<ul> + [% WHILE ( editor = edit_activity.next ) %] + <li>[% tprintf( loc('%d edits by %s'), editor.get_column('c'), editor.name ) %]</li> + [% END %] +</ul> +[% ELSE %] +<p> +[% loc('No edits have yet been made.') %] +</p> +[% END %] + +<h2>[% loc('Councils') %]</h2> + +<h3>[% loc('No info at all') %]</h3> +[% PROCESS details councils=no_info %] +<h3>[% loc('Currently has 1+ deleted') %]</h3> +[% PROCESS details councils=one_plus_deleted %] +<h3>[% loc('Some unconfirmeds') %]</h3> +[% PROCESS details councils=unconfirmeds %] +<h3>[% loc('All confirmed') %]</h3> +[% PROCESS details councils=all_confirmed %] + +[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/default/admin/header.html b/templates/web/default/admin/header.html index 725cae9ef..66ffaf770 100644 --- a/templates/web/default/admin/header.html +++ b/templates/web/default/admin/header.html @@ -11,10 +11,9 @@ dd { margin-left: 8em; } <strong>[% loc('FixMyStreet admin:') %]</strong> <a href="[% c.uri_for( '' ) %]">[% loc('Summary') %]</a> - <a href="">[% loc('Council contacts') %]</a> + <a href="[% c.uri_for( 'council_list' ) %]">[% loc('Council contacts') %]</a> <a href="">[% loc('Search Reports') %]</a> <a href="">[% loc('Timeline') %]</a> <a href="[% c.uri_for( 'questionnaire') %]">[% loc('Survey Results') %]</a> <h1>[% title %]</h1> - |