diff options
-rw-r--r-- | perl-external/files.txt | 1 | ||||
-rw-r--r-- | perl-external/minicpan/modules/02packages.details.txt.gz | bin | 19553 -> 317 bytes | |||
-rw-r--r-- | perl-external/modules.txt | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 139 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Alert.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Questionnaire.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Alert.pm | 38 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Comment.pm | 27 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 30 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm | 18 | ||||
-rw-r--r-- | templates/web/default/admin/timeline.html | 46 |
11 files changed, 252 insertions, 88 deletions
diff --git a/perl-external/files.txt b/perl-external/files.txt index dba014f2f..e31874c94 100644 --- a/perl-external/files.txt +++ b/perl-external/files.txt @@ -149,6 +149,7 @@ /authors/id/J/JH/JHOBLITT/DateTime-Format-ISO8601-0.07.tar.gz /authors/id/J/JP/JPEACOCK/version-0.88.tar.gz /authors/id/J/JR/JROCKWAY/Context-Preserve-0.01.tar.gz +/authors/id/J/JR/JROCKWAY/Template-Plugin-DateTime-Format-0.02.tar.gz /authors/id/K/KA/KASEI/Class-Accessor-0.34.tar.gz /authors/id/K/KW/KWILLIAMS/Path-Class-0.23.tar.gz /authors/id/K/KW/KWILLIAMS/Probe-Perl-0.01.tar.gz diff --git a/perl-external/minicpan/modules/02packages.details.txt.gz b/perl-external/minicpan/modules/02packages.details.txt.gz Binary files differindex a166b7223..3e590b347 100644 --- a/perl-external/minicpan/modules/02packages.details.txt.gz +++ b/perl-external/minicpan/modules/02packages.details.txt.gz diff --git a/perl-external/modules.txt b/perl-external/modules.txt index 25c957fb7..d3fb346c6 100644 --- a/perl-external/modules.txt +++ b/perl-external/modules.txt @@ -44,6 +44,7 @@ Sort::Key Spiffy Sub::Override Template::Plugin::Comma +Template::Plugin::DateTime::Format Term::Size::Any Test::More Test::WWW::Mechanize diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 22cbf78c0..930739718 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -41,7 +41,7 @@ sub index : Path : Args(0) { $c->forward('set_allowed_pages'); - my ( $sql_resttriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); + my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); my $cobrand_restriction = $c->cobrand->moniker eq 'fixmystreet' ? {} : { cobrand => $c->cobrand->moniker }; my $problems = $c->model('DB::Problem')->search( @@ -141,6 +141,57 @@ sub index : Path : Args(0) { return 1; } +sub timeline : Path( 'timeline' ) : Args(0) { + my ($self, $c) = @_; + + $c->forward('set_allowed_pages'); + + my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); + my $cobrand_restriction = { cobrand => $c->cobrand->moniker }; + my %time; + + $c->model('DB')->schema->storage->sql_maker->quote_char( '"' ); + + my $probs = $c->model('DB::Problem')->timeline( $site_restriction ); + + foreach ($probs->all) { + push @{$time{$_->created->epoch}}, { type => 'problemCreated', date => $_->created_local, obj => $_ }; + push @{$time{$_->confirmed->epoch}}, { type => 'problemConfirmed', date => $_->confirmed_local, obj => $_ } if $_->confirmed; + push @{$time{$_->whensent->epoch}}, { type => 'problemSent', date => $_->whensent_local, obj => $_ } if $_->whensent; + } + + my $questionnaires = $c->model('DB::Questionnaire')->timeline( $cobrand_restriction ); + + foreach ($questionnaires->all) { + push @{$time{$_->whensent->epoch}}, { type => 'quesSent', date => $_->whensent_local, obj => $_ }; + push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered_local, obj => $_ } if $_->whenanswered; + } + + my $updates = $c->model('DB::Comment')->timeline( $site_restriction ); + + foreach ($updates->all) { + push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created_local, obj => $_} ; + } + + my $alerts = $c->model('DB::Alert')->timeline_created( $cobrand_restriction ); + + foreach ($alerts->all) { + push @{$time{$_->whensubscribed->epoch}}, { type => 'alertSub', date => $_->whensubscribed_local, obj => $_ }; + } + + $alerts = $c->model('DB::Alert')->timeline_disabled( $cobrand_restriction ); + + foreach ($alerts->all) { + push @{$time{$_->whendisabled->epoch}}, { type => 'alertDel', date => $_->whendisabled_local, obj => $_ }; + } + + $c->model('DB')->schema->storage->sql_maker->quote_char( '' ); + + $c->stash->{time} = \%time; + + return 1; +} + sub questionnaire : Path('questionnaire') : Args(0) { my ( $self, $c ) = @_; @@ -740,92 +791,6 @@ sub update_edit : Path('update_edit') : Args(1) { return 1; } -# sub admin_timeline { -# my $q = shift; -# my $cobrand = Page::get_cobrand($q); -# print html_head($q, _('Timeline')); -# print $q->h1(_('Timeline')); -# -# my %time; -# #my $backto_unix = time() - 60*60*24*7; -# -# my $probs = Problems::timeline_problems(); -# foreach (@$probs) { -# push @{$time{$_->{created}}}, { type => 'problemCreated', %$_ }; -# push @{$time{$_->{confirmed}}}, { type => 'problemConfirmed', %$_ } if $_->{confirmed}; -# push @{$time{$_->{whensent}}}, { type => 'problemSent', %$_ } if $_->{whensent}; -# } -# -# my $questionnaire = Problems::timeline_questionnaires($cobrand); -# foreach (@$questionnaire) { -# push @{$time{$_->{whensent}}}, { type => 'quesSent', %$_ }; -# push @{$time{$_->{whenanswered}}}, { type => 'quesAnswered', %$_ } if $_->{whenanswered}; -# } -# -# my $updates = Problems::timeline_updates(); -# foreach (@$updates) { -# push @{$time{$_->{created}}}, { type => 'update', %$_} ; -# } -# -# my $alerts = Problems::timeline_alerts($cobrand); -# -# -# foreach (@$alerts) { -# push @{$time{$_->{whensubscribed}}}, { type => 'alertSub', %$_ }; -# } -# $alerts = Problems::timeline_deleted_alerts($cobrand); -# foreach (@$alerts) { -# push @{$time{$_->{whendisabled}}}, { type => 'alertDel', %$_ }; -# } -# -# my $date = ''; -# my $cobrand_data; -# foreach (reverse sort keys %time) { -# my $curdate = decode_utf8(strftime('%A, %e %B %Y', localtime($_))); -# if ($date ne $curdate) { -# print '</dl>' if $date; -# print "<h2>$curdate</h2> <dl>"; -# $date = $curdate; -# } -# print '<dt><b>', decode_utf8(strftime('%H:%M:%S', localtime($_))), ':</b></dt> <dd>'; -# foreach (@{$time{$_}}) { -# my $type = $_->{type}; -# if ($type eq 'problemCreated') { -# my $name_str = '; ' . sprintf(_("by %s"), ent($_->{name})) . " <" . ent($_->{email}) . ">, '" . ent($_->{title}) . "'"; -# print sprintf(_("Problem %d created"), $_->{id}) . $name_str; -# } elsif ($type eq 'problemConfirmed') { -# my $name_str = '; ' . sprintf(_("by %s"), ent($_->{name})) . " <" . ent($_->{email}) . ">, '" . ent($_->{title}) . "'"; -# $cobrand_data = get_cobrand_data_from_hash($cobrand, $_); -# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . "/report/$_->{id}"; -# print sprintf(_("Problem %s confirmed"), "<a href='$url'>$_->{id}</a>") . $name_str; -# } elsif ($type eq 'problemSent') { -# $cobrand_data = get_cobrand_data_from_hash($cobrand, $_); -# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . "/report/$_->{id}"; -# print sprintf(_("Problem %s sent to council %s"), "<a href='$url'>$_->{id}</a>", $_->{council}); -# } elsif ($type eq 'quesSent') { -# print sprintf(_("Questionnaire %d sent for problem %d"), $_->{id}, $_->{problem_id}); -# } elsif ($type eq 'quesAnswered') { -# print sprintf(_("Questionnaire %d answered for problem %d, %s to %s"), $_->{id}, $_->{problem_id}, $_->{old_state}, $_->{new_state}); -# } elsif ($type eq 'update') { -# $cobrand_data = get_cobrand_data_from_hash($cobrand, $_); -# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . "/report/$_->{problem_id}#$_->{id}"; -# my $name = ent($_->{name} || 'anonymous'); -# print sprintf(_("Update %s created for problem %d; by %s"), "<a href='$url'>$_->{id}</a>", $_->{problem_id}, $name) . " <" . ent($_->{email}) . ">"; -# } elsif ($type eq 'alertSub') { -# my $param = $_->{parameter} || ''; -# my $param2 = $_->{parameter2} || ''; -# print sprintf(_("Alert %d created for %s, type %s, parameters %s / %s"), $_->{id}, ent($_->{email}), $_->{alert_type}, $param, $param2); -# } elsif ($type eq 'alertDel') { -# my $sub = decode_utf8(strftime('%H:%M:%S %e %B %Y', localtime($_->{whensubscribed}))); -# print sprintf(_("Alert %d disabled (created %s)"), $_->{id}, $sub); -# } -# print '<br>'; -# } -# print "</dd>\n"; -# } -# print html_tail($q); -# -# } # # # sub main { diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm index 53cb96ff4..3a2dc9a9f 100644 --- a/perllib/FixMyStreet/DB/Result/Alert.pm +++ b/perllib/FixMyStreet/DB/Result/Alert.pm @@ -69,11 +69,31 @@ __PACKAGE__->has_many( # You can replace this text with custom code or comments, and it will be preserved on regeneration +use DateTime::TimeZone; use Moose; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; +my $tz = DateTime::TimeZone->new( name => "local" ); + + +sub whensubscribed_local { + my $self = shift; + + return $self->whensubscribed + ? $self->whensubscribed->set_time_zone($tz) + : $self->whensubscribed; +} + +sub whendisabled_local { + my $self = shift; + + return $self->whendisabled + ? $self->whendisabled->set_time_zone($tz) + : $self->whendisabled; +} + =head2 confirm $alert->confirm(); diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index a36c07535..5a507645f 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -43,6 +43,24 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-05-24 15:32:43 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BAWTYKAQ84VeOI6D2gtQOQ +use DateTime::TimeZone; + +my $tz = DateTime::TimeZone->new( name => "local" ); + +sub whensent_local { + my $self = shift; + + return $self->whensent + ? $self->whensent->set_time_zone($tz) + : $self->whensent; +} + +sub whenanswered_local { + my $self = shift; + + return $self->whenanswered + ? $self->whenanswered->set_time_zone($tz) + : $self->whenanswered; +} -# You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Alert.pm b/perllib/FixMyStreet/DB/ResultSet/Alert.pm new file mode 100644 index 000000000..62e6120e4 --- /dev/null +++ b/perllib/FixMyStreet/DB/ResultSet/Alert.pm @@ -0,0 +1,38 @@ +package FixMyStreet::DB::ResultSet::Alert; +use base 'DBIx::Class::ResultSet'; + +use strict; +use warnings; + +sub timeline_created { + my ( $rs, $restriction ) = @_; + + my $prefetch = + FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ? + [ qw/alert_type user/ ] : + [ qw/alert_type/ ]; + + return $rs->search( + { + whensubscribed => { '>=', \"ms_current_timestamp()-'7 days'::interval" }, + confirmed => 1, + %{ $restriction }, + }, + { + prefetch => $prefetch, + } + ); +} + +sub timeline_disabled { + my ( $rs, $restriction ) = @_; + + return $rs->search( + { + whendisabled => { '>=', \"ms_current_timestamp()-'7 days'::interval" }, + %{ $restriction }, + }, + ); +} + +1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Comment.pm b/perllib/FixMyStreet/DB/ResultSet/Comment.pm new file mode 100644 index 000000000..4719c7a24 --- /dev/null +++ b/perllib/FixMyStreet/DB/ResultSet/Comment.pm @@ -0,0 +1,27 @@ +package FixMyStreet::DB::ResultSet::Comment; +use base 'DBIx::Class::ResultSet'; + +use strict; +use warnings; + +sub timeline { + my ( $rs, $restriction ) = @_; + + my $prefetch = + FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ? + [ qw/user/ ] : + []; + + return $rs->search( + { + state => 'confirmed', + created => { '>=', \"ms_current_timestamp()-'7 days'::interval" }, + %{ $restriction }, + }, + { + prefetch => $prefetch, + } + ); +} + +1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm new file mode 100644 index 000000000..8d798a7c1 --- /dev/null +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -0,0 +1,30 @@ +package FixMyStreet::DB::ResultSet::Problem; +use base 'DBIx::Class::ResultSet'; + +use strict; +use warnings; + +sub timeline { + my ( $rs, $restriction ) = @_; + + my $prefetch = + FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ? + [ qw/user/ ] : + []; + + return $rs->search( + { + -or => { + created => { '>=', \"ms_current_timestamp()-'7 days'::interval" }, + confirmed => { '>=', \"ms_current_timestamp()-'7 days'::interval" }, + whensent => { '>=', \"ms_current_timestamp()-'7 days'::interval" }, + %{ $restriction }, + } + }, + { + prefetch => $prefetch, + } + ); +} + +1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index 80f62f495..1f5e26197 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -112,4 +112,22 @@ sub send_questionnaires_period { } } +sub timeline { + my ( $rs, $restriction ) = @_; + + return $rs->search( + { + -or => { + whenanswered => { '>=', \"ms_current_timestamp()-'7 days'::interval" }, + 'me.whensent' => { '>=', \"ms_current_timestamp()-'7 days'::interval" }, + }, + %{ $restriction }, + }, + { + -select => [qw/me.*/], + prefetch => [qw/problem/], + } + ); +} + 1; diff --git a/templates/web/default/admin/timeline.html b/templates/web/default/admin/timeline.html new file mode 100644 index 000000000..a7f4f3628 --- /dev/null +++ b/templates/web/default/admin/timeline.html @@ -0,0 +1,46 @@ +[% INCLUDE 'admin/header.html' title=loc('Timeline') %] +[%- USE f = DateTime::Format('DateTime::Format::Strptime', { pattern => "%A, %e %B %Y" }) %] +[%- USE alert_format = DateTime::Format('DateTime::Format::Strptime', { pattern => "%H:%M:%S %e %B %Y" }) %] + +[%- BLOCK problem_name %] + [%- tprintf(loc('by %s'), problem.name) | html %] <[% problem.user.email | html %]>, '[% problem.title | html %]' +[%- END %] + +[%- date = '' %] +[% FOREACH moment IN time.keys.sort.reverse %] + [%- curdate = f.format(time.$moment.0.date) -%] + [%- IF date != curdate %] + [% '</dl>' IF date %] + <h2>[% curdate %]</h2> + + <dl> + [%- date = curdate -%] + [%- END -%] + <dt><b>[% time.$moment.0.date.hms %]</b></dt> + <dd> + [% FOREACH item IN time.$moment %] + [%- SWITCH item.type -%] + [% CASE 'problemCreated' %] + [%- tprintf(loc('Problem %d created'), item.obj.id) %]; [% PROCESS problem_name problem=item.obj -%] + [% CASE 'problemConfirmed' %] + [%- tprintf( loc('Problem %s confirmed'), '<a href="' _ c.uri_for_email( '/report', item.obj.id, c.cobrand_data ) _ '">' _ item.obj.id _ '</a>') %]; [% PROCESS problem_name problem=item.obj -%] + [% CASE 'problemSent' %] + [% tprintf(loc("Problem %s sent to council %s"), '<a href="' _ c.uri_for_email( '/report', item.obj.id, c.cobrand_data ) _ '">' _ item.obj.id _ '</a>', item.obj.council ) %] + [% CASE 'quesSent' %] + [% tprintf(loc("Questionnaire %d sent for problem %d"), item.obj.id, item.obj.problem_id ) %] + [% CASE 'quesAnswered' %] + [% tprintf(loc("Questionnaire %d answered for problem %d, %s to %s"), item.obj.id, item.obj.problem_id, item.obj.old_state, item.obj.new_state ) %] + [% CASE 'update' %] + [% name = ( item.obj.name || 'anonymous' ) | html %] + [% tprintf(loc("Update %s created for problem %d; by %s"), "<a href='" _ c.uri_for_email( '/report', item.obj.problem_id, c.cobrand_data ) _ "#update_" _ item.obj.id _ "'>" _ item.obj.id _ "</a>", item.obj.problem_id, name) %]<[% item.obj.user.email | html %]> + [% CASE 'alertSub' %] + [% tprintf(loc("Alert %d created for %s, type %s, parameters %s / %s"), item.obj.id, item.obj.user.email, item.obj.alert_type.ref, item.obj.parameter, item.obj.parameter2) | html %] + [% CASE 'alertDel' %] + [% tprintf(loc("Alert %d disabled (created %s)"), item.obj.id, alert_format.format( item.obj.whensubscribed_local ) ) %] + [%- END %] + <br /> + [%- END %] + </dd> +[% END %] + +[% INCLUDE 'admin/footer.html' %] |