aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Admin.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm89
1 files changed, 57 insertions, 32 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index f54a862ab..4e288556f 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -71,25 +71,7 @@ sub index : Path : Args(0) {
return $c->cobrand->admin();
}
- my $problems = $c->cobrand->problems->summary_count;
-
- my %prob_counts =
- map { $_->state => $_->get_column('state_count') } $problems->all;
-
- %prob_counts =
- map { $_ => $prob_counts{$_} || 0 }
- ( FixMyStreet::DB::Result::Problem->all_states() );
- $c->stash->{problems} = \%prob_counts;
- $c->stash->{total_problems_live} += $prob_counts{$_} ? $prob_counts{$_} : 0
- for ( FixMyStreet::DB::Result::Problem->visible_states() );
- $c->stash->{total_problems_users} = $c->cobrand->problems->unique_users;
-
- my $comments = $c->cobrand->updates->summary_count;
-
- my %comment_counts =
- map { $_->state => $_->get_column('state_count') } $comments->all;
-
- $c->stash->{comments} = \%comment_counts;
+ $c->forward('stats_by_state');
my $alerts = $c->model('DB::Alert')->summary_report_alerts( $c->cobrand->restriction );
@@ -129,11 +111,7 @@ sub index : Path : Args(0) {
: _('n/a');
$c->stash->{questionnaires} = \%questionnaire_counts;
- if ($c->get_param('show_categories')) {
- $c->stash->{categories} = $c->cobrand->problems->categories_summary();
- }
-
- $c->stash->{total_bodies} = $c->model('DB::Body')->count();
+ $c->forward('fetch_all_bodies');
return 1;
}
@@ -196,7 +174,7 @@ sub timeline : Path( 'timeline' ) : Args(0) {
return 1;
}
-sub questionnaire : Path('questionnaire') : Args(0) {
+sub questionnaire : Path('stats/questionnaire') : Args(0) {
my ( $self, $c ) = @_;
my $questionnaires = $c->model('DB::Questionnaire')->search(
@@ -232,6 +210,11 @@ sub questionnaire : Path('questionnaire') : Args(0) {
sub bodies : Path('bodies') : Args(0) {
my ( $self, $c ) = @_;
+ if (my $body_id = $c->get_param('body')) {
+ $c->res->redirect( $c->uri_for( 'body', $body_id ) );
+ return;
+ }
+
$c->forward( 'get_token' );
my $edit_activity = $c->model('DB::ContactsHistory')->search(
@@ -784,7 +767,7 @@ sub report_edit : Path('report_edit') : Args(1) {
}
if ( $remove_photo_param || $new_state eq 'hidden' ) {
- unlink glob FixMyStreet->path_to( 'web', 'photo', $problem->id . '.*' );
+ $problem->get_photoset->delete_cached;
}
if ( $problem->is_visible() and $old_state eq 'unconfirmed' ) {
@@ -1005,7 +988,7 @@ sub update_edit : Path('update_edit') : Args(1) {
}
if ( $remove_photo_param || $new_state eq 'hidden' ) {
- unlink glob FixMyStreet->path_to( 'web', 'photo', 'c', $update->id . '.*' );
+ $update->get_photoset->delete_cached;
}
$update->name( $c->get_param('name') || '' );
@@ -1135,9 +1118,21 @@ sub user_edit : Path('user_edit') : Args(1) {
return;
}
- $user->update;
- if ($edited) {
- $c->forward( 'log_edit', [ $id, 'user', 'edit' ] );
+ my $existing_user = $c->model('DB::User')->search({ email => $user->email, id => { '!=', $user->id } })->first;
+ if ($existing_user) {
+ foreach (qw(Problem Comment Alert)) {
+ $c->model("DB::$_")
+ ->search({ user_id => $user->id })
+ ->update({ user_id => $existing_user->id });
+ }
+ $user->delete;
+ $c->forward( 'log_edit', [ $id, 'user', 'merge' ] );
+ $c->res->redirect( $c->uri_for( 'user_edit', $existing_user->id ) );
+ } else {
+ $user->update;
+ if ($edited) {
+ $c->forward( 'log_edit', [ $id, 'user', 'edit' ] );
+ }
}
$c->stash->{status_message} =
@@ -1175,6 +1170,36 @@ sub flagged : Path('flagged') : Args(0) {
return 1;
}
+sub stats_by_state : Path('stats/state') : Args(0) {
+ my ( $self, $c ) = @_;
+
+ my $problems = $c->cobrand->problems->summary_count;
+
+ my %prob_counts =
+ map { $_->state => $_->get_column('state_count') } $problems->all;
+
+ %prob_counts =
+ map { $_ => $prob_counts{$_} || 0 }
+ ( FixMyStreet::DB::Result::Problem->all_states() );
+ $c->stash->{problems} = \%prob_counts;
+ $c->stash->{total_problems_live} += $prob_counts{$_} ? $prob_counts{$_} : 0
+ for ( FixMyStreet::DB::Result::Problem->visible_states() );
+ $c->stash->{total_problems_users} = $c->cobrand->problems->unique_users;
+
+ my $comments = $c->cobrand->updates->summary_count;
+
+ my %comment_counts =
+ map { $_->state => $_->get_column('state_count') } $comments->all;
+
+ $c->stash->{comments} = \%comment_counts;
+}
+
+sub stats_fix_rate : Path('stats/fix-rate') : Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->stash->{categories} = $c->cobrand->problems->categories_summary();
+}
+
sub stats : Path('stats') : Args(0) {
my ( $self, $c ) = @_;
@@ -1273,7 +1298,6 @@ sub set_allowed_pages : Private {
'bodies' => [_('Bodies'), 1],
'reports' => [_('Reports'), 2],
'timeline' => [_('Timeline'), 3],
- 'questionnaire' => [_('Survey'), 4],
'users' => [_('Users'), 5],
'flagged' => [_('Flagged'), 6],
'stats' => [_('Stats'), 7],
@@ -1540,7 +1564,8 @@ sub check_page_allowed : Private {
$c->forward('set_allowed_pages');
- (my $page = $c->req->action) =~ s#admin/?##;
+ (my $page = $c->req->path) =~ s#admin/?##;
+ $page =~ s#/.*##;
$page ||= 'summary';