aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2019-11-26 11:43:01 +0000
committerDave Arter <davea@mysociety.org>2019-12-09 12:48:12 +0000
commit61665b040781a0920b9586c558313cdeb17a99d6 (patch)
tree946173c1219a3d6481588abcbe355f1d85cd5b5e
parent7ad686bc1e05304b26c081856948847f192e1384 (diff)
Group categories on user edit page, if cobrand has grouping enabled
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Users.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm27
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm17
-rw-r--r--templates/web/base/admin/category-checkboxes.html33
4 files changed, 54 insertions, 25 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Users.pm b/perllib/FixMyStreet/App/Controller/Admin/Users.pm
index 802fbb9f5..1520fe990 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Users.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Users.pm
@@ -394,8 +394,10 @@ sub edit : Chained('user') : PathPart('') : Args(0) {
id => $_->id,
category => $_->category,
active => $active_contacts{$_->id},
+ group => $_->get_extra_metadata('group') // '',
} } @live_contacts;
$c->stash->{contacts} = \@all_contacts;
+ $c->forward('/report/stash_category_groups', [ \@all_contacts, 1 ]) if $c->cobrand->enable_category_groups;
}
# this goes after in case we've delete any alerts
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index fde28dcbe..debf27cde 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -661,6 +661,33 @@ sub check_has_permission_to : Private {
return \%permissions;
};
+
+sub stash_category_groups : Private {
+ my ( $self, $c, $contacts, $combine_multiple ) = @_;
+
+ my %category_groups = ();
+ for my $category (@$contacts) {
+ my $group = $category->{group} // $category->get_extra_metadata('group') // [''];
+ # this could be an array ref or a string
+ my @groups = ref $group eq 'ARRAY' ? @$group : ($group);
+ if (scalar @groups > 1 && $combine_multiple) {
+ @groups = sort @groups;
+ $category->{group} = \@groups;
+ push( @{$category_groups{_('Multiple Groups')}}, $category );
+ } else {
+ push( @{$category_groups{$_}}, $category ) for @groups;
+ }
+ }
+
+ my @category_groups = ();
+ for my $group ( grep { $_ ne _('Other') && $_ ne _('Multiple Groups') } sort keys %category_groups ) {
+ push @category_groups, { name => $group, categories => $category_groups{$group} };
+ }
+ push @category_groups, { name => _('Other'), categories => $category_groups{_('Other')} } if ($category_groups{_('Other')});
+ push @category_groups, { name => _('Multiple Groups'), categories => $category_groups{_('Multiple Groups')} } if ($category_groups{_('Multiple Groups')});
+ $c->stash->{category_groups} = \@category_groups;
+}
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 899028ee9..68469472e 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -769,22 +769,7 @@ sub setup_categories_and_bodies : Private {
$c->stash->{missing_details_bodies} = \@missing_details_bodies;
$c->stash->{missing_details_body_names} = \@missing_details_body_names;
- if ( $c->cobrand->enable_category_groups ) {
- my %category_groups = ();
- for my $category (@category_options) {
- my $group = $category->{group} // $category->get_extra_metadata('group') // [''];
- # this could be an array ref or a string
- my @groups = ref $group eq 'ARRAY' ? @$group : ($group);
- push( @{$category_groups{$_}}, $category ) for @groups;
- }
-
- my @category_groups = ();
- for my $group ( grep { $_ ne _('Other') } sort keys %category_groups ) {
- push @category_groups, { name => $group, categories => $category_groups{$group} };
- }
- push @category_groups, { name => _('Other'), categories => $category_groups{_('Other')} } if ($category_groups{_('Other')});
- $c->stash->{category_groups} = \@category_groups;
- }
+ $c->forward('/report/stash_category_groups', [ \@category_options ]) if $c->cobrand->enable_category_groups;
}
sub setup_report_extra_fields : Private {
diff --git a/templates/web/base/admin/category-checkboxes.html b/templates/web/base/admin/category-checkboxes.html
index eacd1a398..cf9530f22 100644
--- a/templates/web/base/admin/category-checkboxes.html
+++ b/templates/web/base/admin/category-checkboxes.html
@@ -1,12 +1,4 @@
-<fieldset>
- <legend>
- [% IF hint %]
- <div class="admin-hint">
- <p>[% hint %]</p>
- </div>
- [% END %]
- [% loc('Categories:') %]
- </legend>
+[% BLOCK checkboxes %]
<ul class="no-bullets no-margin">
<li>
[% loc('Select:') %]
@@ -18,8 +10,31 @@
<label class="inline" title="[% contact.email | html %]">
<input type="checkbox" name="contacts[[% contact.id %]]" [% 'checked' IF contact.active %]/>
[% contact.category %]
+ [% IF contact.group.size > 1 %]<small>([% contact.group.join('; ') | html %])</small>[% END %]
</label>
</li>
[% END %]
</ul>
+[% END %]
+<fieldset>
+ <legend>
+ [% IF hint %]
+ <div class="admin-hint">
+ <p>[% hint %]</p>
+ </div>
+ [% END %]
+ [% loc('Categories:') %]
+ </legend>
+
+ [% IF category_groups %]
+ [% FOR group IN category_groups %]
+ <h3>[% ( group.name OR loc('No Group') ) | html %]</h3>
+ [% IF group.name == loc("Multiple Groups") %]
+ <small>[% loc('These categories appear in more than one group:') %]</small>
+ [% END %]
+ [% INCLUDE checkboxes contacts=group.categories %]
+ [% END %]
+ [% ELSE %]
+ [% INCLUDE checkboxes contacts=contacts %]
+ [% END %]
</fieldset>