aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm6
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm38
-rw-r--r--templates/web/default/admin/bodies.html30
3 files changed, 67 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 7479bdba5..de69880c1 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -1325,7 +1325,11 @@ sub fetch_all_bodies : Private {
my ($self, $c ) = @_;
my @bodies = $c->model('DB::Body')->all;
- @bodies = sort { strcoll($a->name, $b->name) } @bodies;
+ if ( $c->cobrand->moniker eq 'zurich' ) {
+ @bodies = $c->cobrand->admin_fetch_all_bodies( @bodies );
+ } else {
+ @bodies = sort { strcoll($a->name, $b->name) } @bodies;
+ }
$c->stash->{bodies} = \@bodies;
return 1;
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 1c4718da7..b2d68014a 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -334,4 +334,42 @@ sub _admin_send_email {
} );
}
+sub admin_fetch_all_bodies {
+ my ( $self, @bodies ) = @_;
+
+ my %sorted;
+ foreach (@bodies) {
+ my $p = $_->parent ? $_->parent->id : 0;
+ push @{$sorted{$p}}, $_;
+ }
+
+ sub tree_sort {
+ my ( $level, $array, $out ) = @_;
+
+ my @sorted;
+ if ( $level == 0 ) {
+ @sorted = sort {
+ # Want Zurich itself at the top.
+ return -1 if $sorted{$a->id};
+ return 1 if $sorted{$b->id};
+ # Otherwise, by name
+ strcoll($a->name, $b->name)
+ } @$array;
+ } else {
+ @sorted = sort { strcoll($a->name, $b->name) } @$array;
+ }
+ foreach ( @sorted ) {
+ $_->api_key( $level ); # Misuse
+ push @$out, $_;
+ if ($sorted{$_->id}) {
+ tree_sort( $level+1, $sorted{$_->id}, $out );
+ }
+ }
+ }
+
+ my @out;
+ tree_sort( 0, $sorted{0}, \@out );
+ return @out;
+}
+
1;
diff --git a/templates/web/default/admin/bodies.html b/templates/web/default/admin/bodies.html
index d6c706fce..ccd2e801b 100644
--- a/templates/web/default/admin/bodies.html
+++ b/templates/web/default/admin/bodies.html
@@ -2,14 +2,31 @@
[% INCLUDE 'admin/edit-league.html' %]
+<table cellspacing="0" cellpadding="2" border="1">
+ <tr>
+ <th>[% loc('Name') %]</th>
+ [% IF c.cobrand.moniker == 'zurich' %]
+ <th>[% loc('Email') %]</th>
+ [% ELSE %]
+ <th>[% loc('Category') %]</th>
+ [% END %]
+ </tr>
[%- FOREACH body IN bodies %]
[%- SET id = body.id %]
- [%- '<ul>' IF loop.first %]
[% NEXT IF c.cobrand.moniker == 'zurich' AND admin_type == 'dm' AND (body.parent OR body.bodies) %]
- <li><a href="[% c.uri_for( 'body', id ) %]">[% body.name %]</a>
- [%- ', ' _ body.parent.name IF body.parent -%]
- [% IF c.cobrand.moniker != 'zurich' %]
- &ndash;
+ <tr>
+ <td>
+ [% IF c.cobrand.moniker == 'zurich' %]
+ [% FILTER repeat(4*body.api_key) %]&nbsp;[% END %]
+ [% END %]
+ <a href="[% c.uri_for( 'body', id ) %]">[% body.name %]</a>
+ [% IF c.cobrand.moniker != 'zurich' %]
+ [%- ', ' _ body.parent.name IF body.parent -%]
+ [% END %]
+ </td>
+ [% IF c.cobrand.moniker == 'zurich' %]
+ <td>[% body.endpoint %]</td>
+ [% ELSE %]
[% IF counts.$id %]
[% tprintf( loc('%d addresses'), counts.$id.c) IF c.cobrand.moniker != 'emptyhomes' %]
[% IF counts.$id.deleted %]
@@ -21,8 +38,9 @@
no categories
[% END %]
[% END %]
- [%- '</ul>' IF loop.last %]
+ </tr>
[%- END %]
+</table>
<h2>[% loc('Add body') %]</h2>
[% INCLUDE 'admin/body-form.html', body='' %]