aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-04-12 11:52:06 +0100
committerEdmund von der Burg <evdb@mysociety.org>2011-04-12 11:54:13 +0100
commit94f4797c17b9c439579645f202726ba65499a78d (patch)
treec6d487bdf555391c8c5a4e3a1c313051becf0fca
parent61c535ac6f2bff72d401fd217b0f0c75fd639bcc (diff)
Port front stats code over to TT2 and new cobrand
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm40
-rw-r--r--perllib/FixMyStreet/Cobrand/EmptyHomes.pm10
-rw-r--r--perllib/Problems.pm62
-rw-r--r--templates/web/default/front_stats.html43
-rw-r--r--templates/web/default/index.html3
5 files changed, 121 insertions, 37 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 9054af81c..9a2788c08 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -228,15 +228,47 @@ sub recent {
return Problems::recent(@_);
}
-=head2 front_stats
+=item shorten_recency_if_new_greater_than_fixed
-Given a QUERY, return a block of html for showing front stats for the site
+By default we want to shorten the recency so that the numbers are more
+attractive.
=cut
-sub front_stats {
+sub shorten_recency_if_new_greater_than_fixed {
+ return 1;
+}
+
+=head2 front_stats_data
+
+Return a data structure containing the front stats information that a template
+can then format.
+
+=cut
+
+sub front_stats_data {
my $self = shift;
- return Problems::front_stats(@_);
+
+ my $recency = '1 week';
+ my $shorter_recency = '3 days';
+
+ my $fixed = Problems::recent_fixed();
+ my $updates = Problems::number_comments();
+ my $new = Problems::recent_new($recency);
+
+ if ( $new > $fixed && $self->shorten_recency_if_new_greater_than_fixed ) {
+ $recency = $shorter_recency;
+ $new = Problems::recent_new($recency);
+ }
+
+ my $stats = {
+ fixed => $fixed,
+ updates => $updates,
+ new => $new,
+ recency => $recency,
+ };
+
+ return $stats;
}
=head2 disambiguate_location
diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
index 5ebee0d2b..c0de92c5e 100644
--- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
+++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
@@ -68,5 +68,15 @@ sub feed_xsl {
return '/xsl.eha.xsl';
}
+=item shorten_recency_if_new_greater_than_fixed
+
+For empty homes we don't want to shorten the recency
+
+=cut
+
+sub shorten_recency_if_new_greater_than_fixed {
+ return 0;
+}
+
1;
diff --git a/perllib/Problems.pm b/perllib/Problems.pm
index 860ae04a0..76ccdc677 100644
--- a/perllib/Problems.pm
+++ b/perllib/Problems.pm
@@ -149,37 +149,37 @@ sub recent {
return $result;
}
-sub front_stats {
- my ($q) = @_;
- my $fixed = Problems::recent_fixed();
- my $updates = Problems::number_comments();
- my $new = Problems::recent_new('1 week');
- (my $new_pretty = $new) =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g;
- my $new_text = sprintf(mySociety::Locale::nget('<big>%s</big> report in past week',
- '<big>%s</big> reports in past week', $new), $new_pretty);
- if ($q->{site} ne 'emptyhomes' && $new > $fixed) {
- $new = Problems::recent_new('3 days');
- ($new_pretty = $new) =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g;
- $new_text = sprintf(mySociety::Locale::nget('<big>%s</big> report recently', '<big>%s</big> reports recently', $new), $new_pretty);
- }
- (my $fixed_pretty = $fixed) =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g;
- (my $updates_pretty = $updates) =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g;
-
- my $out = '';
- $out .= $q->h2(_('FixMyStreet updates'));
- my $lastmo = '';
- if ($q->{site} ne 'emptyhomes'){
- $lastmo = $q->div(sprintf(mySociety::Locale::nget("<big>%s</big> fixed in past month", "<big>%s</big> fixed in past month", $fixed), $fixed), $fixed_pretty);
- }
- $out .= $q->div({-id => 'front_stats'},
- $q->div($new_text),
- ($q->{site} ne 'emptyhomes' ? $q->div(sprintf(mySociety::Locale::nget("<big>%s</big> fixed in past month", "<big>%s</big> fixed in past month", $fixed), $fixed_pretty)) : ''),
- $q->div(sprintf(mySociety::Locale::nget("<big>%s</big> update on reports",
- "<big>%s</big> updates on reports", $updates), $updates_pretty))
- );
- return $out;
-
-}
+# sub front_stats {
+# my ($q) = @_;
+# my $fixed = Problems::recent_fixed();
+# my $updates = Problems::number_comments();
+# my $new = Problems::recent_new('1 week');
+# (my $new_pretty = $new) =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g;
+# my $new_text = sprintf(mySociety::Locale::nget('<big>%s</big> report in past week',
+# '<big>%s</big> reports in past week', $new), $new_pretty);
+# if ($q->{site} ne 'emptyhomes' && $new > $fixed) {
+# $new = Problems::recent_new('3 days');
+# ($new_pretty = $new) =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g;
+# $new_text = sprintf(mySociety::Locale::nget('<big>%s</big> report recently', '<big>%s</big> reports recently', $new), $new_pretty);
+# }
+# (my $fixed_pretty = $fixed) =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g;
+# (my $updates_pretty = $updates) =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g;
+#
+# my $out = '';
+# $out .= $q->h2(_('FixMyStreet updates'));
+# my $lastmo = '';
+# if ($q->{site} ne 'emptyhomes'){
+# $lastmo = $q->div(sprintf(mySociety::Locale::nget("<big>%s</big> fixed in past month", "<big>%s</big> fixed in past month", $fixed), $fixed), $fixed_pretty);
+# }
+# $out .= $q->div({-id => 'front_stats'},
+# $q->div($new_text),
+# ($q->{site} ne 'emptyhomes' ? $q->div(sprintf(mySociety::Locale::nget("<big>%s</big> fixed in past month", "<big>%s</big> fixed in past month", $fixed), $fixed_pretty)) : ''),
+# $q->div(sprintf(mySociety::Locale::nget("<big>%s</big> update on reports",
+# "<big>%s</big> updates on reports", $updates), $updates_pretty))
+# );
+# return $out;
+#
+# }
# Problems around a location
diff --git a/templates/web/default/front_stats.html b/templates/web/default/front_stats.html
new file mode 100644
index 000000000..847df2497
--- /dev/null
+++ b/templates/web/default/front_stats.html
@@ -0,0 +1,43 @@
+[%
+ USE Comma;
+ # Note - if we want to i18n the commas we should try
+ # 'Template::Plugin::Number::Format'
+%]
+
+
+[%
+ stats = c.cobrand.front_stats_data();
+
+ new_text =
+ stats.recency == '1 week'
+ ? nget(
+ '<big>%s</big> report in past week',
+ '<big>%s</big> reports in past week',
+ stats.new
+ )
+ : nget(
+ '<big>%s</big> report recently',
+ '<big>%s</big> reports recently',
+ stats.new
+ );
+
+ fixed_text = nget(
+ "<big>%s</big> fixed in past month",
+ "<big>%s</big> fixed in past month",
+ stats.fixed
+ );
+
+ updates_text = nget(
+ "<big>%s</big> update on reports",
+ "<big>%s</big> updates on reports",
+ stats.updates
+ );
+
+%]
+
+<div id="front_stats">
+ <div>[% tprintf( new_text, stats.new ) | comma %]</div>
+ <div>[% tprintf( fixed_text, stats.fixed ) | comma %]</div>
+ <div>[% tprintf( updates_text, stats.updates ) | comma %]</div>
+</div>
+
diff --git a/templates/web/default/index.html b/templates/web/default/index.html
index b895390ed..1e64779e9 100644
--- a/templates/web/default/index.html
+++ b/templates/web/default/index.html
@@ -62,8 +62,7 @@
<li>[% loc('We send it to the council on your behalf') %]</li>
</ol>
- <p>FIXME - front stats go here</p>
- [%# c.cobrand.front_stats() %]
+ [% INCLUDE "front_stats.html" %]
</div>