aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2011-05-24 15:32:19 +0100
committerMatthew Somerville <matthew@mysociety.org>2011-05-24 15:32:19 +0100
commitd9395396a76ce8254fca8637d3bde9e10b7f7564 (patch)
tree3aba246065ff5111ffcdb74db11cdde1ccd0cf3c
parent5bda8b1abb7b8fe0ba14ab831c5ec3915eda6852 (diff)
Complete meta line migration, factor line generation out to model and template.
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm92
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm98
-rw-r--r--perllib/FixMyStreet/DB/Result/Questionnaire.pm2
-rw-r--r--perllib/Page.pm108
-rw-r--r--templates/web/default/questionnaire/index.html2
-rw-r--r--templates/web/default/report/_main.html13
7 files changed, 167 insertions, 150 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index fd9c1f1e7..8fd94dfba 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -77,40 +77,7 @@ sub load_problem_or_display_error : Private {
my $problem #
= $id =~ m{\D} # is id non-numeric?
? undef # ...don't even search
- : $c->model('DB::Problem')->find(
- { id => $id },
- {
- select => [
- 'id',
- 'latitude',
- 'longitude',
- 'council',
- 'category',
- 'title', 'detail', 'photo',
- 'used_map',
- 'name',
- 'anonymous',
- 'state',
- 'service',
- 'cobrand',
- 'cobrand_data',
- 'external_body',
- {
- extract => 'epoch from confirmed',
- -as => 'time',
- },
- {
- extract => 'epoch from whensent-confirmed',
- -as => 'whensent'
- },
- {
- extract => 'epoch from ms_current_timestamp()-lastupdate',
- -as => 'duration'
- }
-
- ]
- }
- );
+ : $c->model('DB::Problem')->find( { id => $id } );
# check that the problem is suitable to show.
if ( !$problem || $problem->state eq 'unconfirmed' ) {
@@ -189,7 +156,6 @@ sub format_problem_for_display : Private {
}
$c->forward('generate_map_tags');
- $c->forward('generate_problem_meta');
return 1;
}
@@ -226,62 +192,6 @@ sub generate_map_tags : Private {
return 1;
}
-sub generate_problem_meta : Private {
- my ( $self, $c ) = @_;
-
- my $problem = $c->stash->{problem};
- my $date_time =
- Page::prettify_epoch( $c->req, $problem->get_column('time') );
- my $meta = '';
- if ( $problem->anonymous ) {
- if ( $problem->service
- and $problem->category && $problem->category ne _('Other') )
- {
- $meta =
- sprintf( _('Reported by %s in the %s category anonymously at %s'),
- $problem->service, $problem->category, $date_time );
- }
- elsif ( $problem->service ) {
- $meta = sprintf( _('Reported by %s anonymously at %s'),
- $problem->service, $date_time );
- }
- elsif ( $problem->category and $problem->category ne _('Other') ) {
- $meta = sprintf( _('Reported in the %s category anonymously at %s'),
- $problem->category, $date_time );
- }
- else {
- $meta = sprintf( _('Reported anonymously at %s'), $date_time );
- }
- }
- else {
- if ( $problem->service
- and $problem->category && $problem->category ne _('Other') )
- {
- $meta = sprintf(
- _('Reported by %s in the %s category by %s at %s'),
- $problem->service, $problem->category,
- $problem->name, $date_time
- );
- }
- elsif ( $problem->service ) {
- $meta = sprintf( _('Reported by %s by %s at %s'),
- $problem->service, $problem->name, $date_time );
- }
- elsif ( $problem->category and $problem->category ne _('Other') ) {
- $meta = sprintf( _('Reported in the %s category by %s at %s'),
- $problem->category, $problem->name, $date_time );
- }
- else {
- $meta =
- sprintf( _('Reported by %s at %s'), $problem->name, $date_time );
- }
- }
-
- $c->stash->{meta} = $meta;
-
- return 1;
-}
-
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 552fba5db..839ad38f7 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -783,7 +783,7 @@ sub generate_problem_banner {
my ( $self, $problem ) = @_;
my $banner = {};
- if ($problem->state eq 'confirmed' && $problem->get_column('duration') > 8*7*24*60*60) {
+ if ($problem->state eq 'confirmed' && time() - $problem->lastupdate->epoch > 8*7*24*60*60) {
$banner->{id} = 'unknown';
$banner->{text} = _('This problem is old and of unknown status.');
}
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 0dc673f23..cdfe5a390 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -8,7 +8,7 @@ use warnings;
use base 'DBIx::Class::Core';
-__PACKAGE__->load_components("FilterColumn");
+__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime");
__PACKAGE__->table("problem");
__PACKAGE__->add_columns(
"id",
@@ -251,4 +251,100 @@ sub get_photo_params {
return $photo;
}
+=head2 meta_line
+
+Returns a string to be used on a problem report page, describing some of the
+meta data about the report.
+
+=cut
+
+sub meta_line {
+ my ( $problem, $c ) = @_;
+
+ my $date_time =
+ Page::prettify_epoch( $c->req, $problem->confirmed->epoch );
+ my $meta = '';
+
+ # FIXME Should be in cobrand
+ if ($c->cobrand->moniker eq 'emptyhomes') {
+
+ my $category = _($problem->category);
+ utf8::decode($category);
+ if ($problem->anonymous) {
+ $meta = sprintf(_('%s, reported anonymously at %s'), $category, $date_time);
+ } else {
+ $meta = sprintf(_('%s, reported by %s at %s'), $category, $problem->name, $date_time);
+ }
+
+ } else {
+
+ if ( $problem->anonymous ) {
+ if ( $problem->service
+ and $problem->category && $problem->category ne _('Other') )
+ {
+ $meta =
+ sprintf( _('Reported by %s in the %s category anonymously at %s'),
+ $problem->service, $problem->category, $date_time );
+ }
+ elsif ( $problem->service ) {
+ $meta = sprintf( _('Reported by %s anonymously at %s'),
+ $problem->service, $date_time );
+ }
+ elsif ( $problem->category and $problem->category ne _('Other') ) {
+ $meta = sprintf( _('Reported in the %s category anonymously at %s'),
+ $problem->category, $date_time );
+ }
+ else {
+ $meta = sprintf( _('Reported anonymously at %s'), $date_time );
+ }
+ }
+ else {
+ if ( $problem->service
+ and $problem->category && $problem->category ne _('Other') )
+ {
+ $meta = sprintf(
+ _('Reported by %s in the %s category by %s at %s'),
+ $problem->service, $problem->category,
+ $problem->name, $date_time
+ );
+ }
+ elsif ( $problem->service ) {
+ $meta = sprintf( _('Reported by %s by %s at %s'),
+ $problem->service, $problem->name, $date_time );
+ }
+ elsif ( $problem->category and $problem->category ne _('Other') ) {
+ $meta = sprintf( _('Reported in the %s category by %s at %s'),
+ $problem->category, $problem->name, $date_time );
+ }
+ else {
+ $meta =
+ sprintf( _('Reported by %s at %s'), $problem->name, $date_time );
+ }
+ }
+
+ }
+
+ $meta .= $c->cobrand->extra_problem_meta_text($problem);
+ $meta .= '; ' . _('the map was not used so pin location may be inaccurate')
+ unless $problem->used_map;
+
+ return $meta;
+}
+
+sub duration_string {
+ my $problem = shift;
+ my $body;
+ if ($problem->external_body) {
+ $body = $problem->external_body;
+ } else {
+ (my $council = $problem->council) =~ s/\|.*//g;
+ my @councils = split /,/, $council;
+ my $areas_info = mySociety::MaPit::call('areas', \@councils);
+ $body = join(' and ', map { $areas_info->{$_}->{name} } @councils);
+ }
+ return sprintf(_('Sent to %s %s later'), $body,
+ Page::prettify_duration($problem->whensent->epoch - $problem->confirmed->epoch, 'minute')
+ );
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm
index db569e838..e01fc15e7 100644
--- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm
@@ -8,7 +8,7 @@ use warnings;
use base 'DBIx::Class::Core';
-__PACKAGE__->load_components("FilterColumn");
+__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime");
__PACKAGE__->table("questionnaire");
__PACKAGE__->add_columns(
"id",
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 13c30d81d..27424d02e 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -567,60 +567,60 @@ sub _part {
}
}
-sub display_problem_meta_line($$) {
- my ($q, $problem) = @_;
- my $out = '';
- my $date_time = prettify_epoch($q, $problem->{time});
- if ($q->{site} eq 'emptyhomes') {
- my $category = _($problem->{category});
- utf8::decode($category); # So that Welsh to Welsh doesn't encode already-encoded UTF-8
- if ($problem->{anonymous}) {
- $out .= sprintf(_('%s, reported anonymously at %s'), ent($category), $date_time);
- } else {
- $out .= sprintf(_('%s, reported by %s at %s'), ent($category), ent($problem->{name}), $date_time);
- }
- } else {
- if ($problem->{service} && $problem->{category} && $problem->{category} ne _('Other') && $problem->{anonymous}) {
- $out .= sprintf(_('Reported by %s in the %s category anonymously at %s'), ent($problem->{service}), ent($problem->{category}), $date_time);
- } elsif ($problem->{service} && $problem->{category} && $problem->{category} ne _('Other')) {
- $out .= sprintf(_('Reported by %s in the %s category by %s at %s'), ent($problem->{service}), ent($problem->{category}), ent($problem->{name}), $date_time);
- } elsif ($problem->{service} && $problem->{anonymous}) {
- $out .= sprintf(_('Reported by %s anonymously at %s'), ent($problem->{service}), $date_time);
- } elsif ($problem->{service}) {
- $out .= sprintf(_('Reported by %s by %s at %s'), ent($problem->{service}), ent($problem->{name}), $date_time);
- } elsif ($problem->{category} && $problem->{category} ne _('Other') && $problem->{anonymous}) {
- $out .= sprintf(_('Reported in the %s category anonymously at %s'), ent($problem->{category}), $date_time);
- } elsif ($problem->{category} && $problem->{category} ne _('Other')) {
- $out .= sprintf(_('Reported in the %s category by %s at %s'), ent($problem->{category}), ent($problem->{name}), $date_time);
- } elsif ($problem->{anonymous}) {
- $out .= sprintf(_('Reported anonymously at %s'), $date_time);
- } else {
- $out .= sprintf(_('Reported by %s at %s'), ent($problem->{name}), $date_time);
- }
- }
- my $cobrand = get_cobrand($q);
- $out .= Cobrand::extra_problem_meta_text($cobrand, $problem);
- $out .= '; ' . _('the map was not used so pin location may be inaccurate') unless ($problem->{used_map});
- if ($problem->{council}) {
- if ($problem->{whensent}) {
- my $body;
- if ($problem->{external_body}) {
- $body = $problem->{external_body};
- } else {
- $problem->{council} =~ s/\|.*//g;
- my @councils = split /,/, $problem->{council};
- my $areas_info = mySociety::MaPit::call('areas', \@councils);
- $body = join(' and ', map { $areas_info->{$_}->{name} } @councils);
- }
- $out .= '<small class="council_sent_info">';
- $out .= $q->br() . sprintf(_('Sent to %s %s later'), $body, prettify_duration($problem->{whensent}, 'minute'));
- $out .= '</small>';
- }
- } else {
- $out .= $q->br() . $q->small(_('Not reported to council'));
- }
- return $out;
-}
+# sub display_problem_meta_line($$) {
+# my ($q, $problem) = @_;
+# my $out = '';
+# my $date_time = prettify_epoch($q, $problem->{time});
+# if ($q->{site} eq 'emptyhomes') {
+# my $category = _($problem->{category});
+# utf8::decode($category); # So that Welsh to Welsh doesn't encode already-encoded UTF-8
+# if ($problem->{anonymous}) {
+# $out .= sprintf(_('%s, reported anonymously at %s'), ent($category), $date_time);
+# } else {
+# $out .= sprintf(_('%s, reported by %s at %s'), ent($category), ent($problem->{name}), $date_time);
+# }
+# } else {
+# if ($problem->{service} && $problem->{category} && $problem->{category} ne _('Other') && $problem->{anonymous}) {
+# $out .= sprintf(_('Reported by %s in the %s category anonymously at %s'), ent($problem->{service}), ent($problem->{category}), $date_time);
+# } elsif ($problem->{service} && $problem->{category} && $problem->{category} ne _('Other')) {
+# $out .= sprintf(_('Reported by %s in the %s category by %s at %s'), ent($problem->{service}), ent($problem->{category}), ent($problem->{name}), $date_time);
+# } elsif ($problem->{service} && $problem->{anonymous}) {
+# $out .= sprintf(_('Reported by %s anonymously at %s'), ent($problem->{service}), $date_time);
+# } elsif ($problem->{service}) {
+# $out .= sprintf(_('Reported by %s by %s at %s'), ent($problem->{service}), ent($problem->{name}), $date_time);
+# } elsif ($problem->{category} && $problem->{category} ne _('Other') && $problem->{anonymous}) {
+# $out .= sprintf(_('Reported in the %s category anonymously at %s'), ent($problem->{category}), $date_time);
+# } elsif ($problem->{category} && $problem->{category} ne _('Other')) {
+# $out .= sprintf(_('Reported in the %s category by %s at %s'), ent($problem->{category}), ent($problem->{name}), $date_time);
+# } elsif ($problem->{anonymous}) {
+# $out .= sprintf(_('Reported anonymously at %s'), $date_time);
+# } else {
+# $out .= sprintf(_('Reported by %s at %s'), ent($problem->{name}), $date_time);
+# }
+# }
+# my $cobrand = get_cobrand($q);
+# $out .= Cobrand::extra_problem_meta_text($cobrand, $problem);
+# $out .= '; ' . _('the map was not used so pin location may be inaccurate') unless ($problem->{used_map});
+# if ($problem->{council}) {
+# if ($problem->{whensent}) {
+# my $body;
+# if ($problem->{external_body}) {
+# $body = $problem->{external_body};
+# } else {
+# $problem->{council} =~ s/\|.*//g;
+# my @councils = split /,/, $problem->{council};
+# my $areas_info = mySociety::MaPit::call('areas', \@councils);
+# $body = join(' and ', map { $areas_info->{$_}->{name} } @councils);
+# }
+# $out .= '<small class="council_sent_info">';
+# $out .= $q->br() . sprintf(_('Sent to %s %s later'), $body, prettify_duration($problem->{whensent}, 'minute'));
+# $out .= '</small>';
+# }
+# } else {
+# $out .= $q->br() . $q->small(_('Not reported to council'));
+# }
+# return $out;
+# }
sub display_problem_detail($) {
my $problem = shift;
diff --git a/templates/web/default/questionnaire/index.html b/templates/web/default/questionnaire/index.html
index 142a8b909..2bc28451f 100644
--- a/templates/web/default/questionnaire/index.html
+++ b/templates/web/default/questionnaire/index.html
@@ -1,5 +1,7 @@
[% INCLUDE 'header.html', title = loc('Questionnaire') %]
+[% INCLUDE 'report/_main.html' %]
+
# FIXME The below should be in the template, by including a map template.
[% map_start_html %]
diff --git a/templates/web/default/report/_main.html b/templates/web/default/report/_main.html
index 42cb4895d..53dcb9a13 100644
--- a/templates/web/default/report/_main.html
+++ b/templates/web/default/report/_main.html
@@ -1,6 +1,15 @@
-<h1>[% problem_title %]</h1>
+<h1>[% problem.title | html %]</h1>
-<p><em>[% meta | html %]</em></p>
+<p><em>[% problem.meta_line(c) | html %]
+[% IF problem.council %]
+ [% IF problem.whensent %]
+ <small class="council_sent_info"><br>[% problem.duration_string %]</small>
+ [% END %]
+[% ELSE %]
+<br><small>[% loc('Not reported to council') %]</small>
+[% END %]
+
+</em></p>
[% FOREACH line IN split_into_lines( problem.detail ) %]
<p>