aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Cobrand.pm21
-rw-r--r--perllib/Page.pm21
-rwxr-xr-xt/Cobrand.t18
-rw-r--r--t/Cobrands/Mysite/Util.pm9
-rwxr-xr-xt/Page.t28
-rwxr-xr-xweb/ajax.cgi5
-rwxr-xr-xweb/index.cgi4
7 files changed, 93 insertions, 13 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm
index 96dddd359..32bf35377 100644
--- a/perllib/Cobrand.pm
+++ b/perllib/Cobrand.pm
@@ -7,7 +7,7 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: Cobrand.pm,v 1.24 2009-09-30 10:00:37 louise Exp $
+# $Id: Cobrand.pm,v 1.25 2009-10-07 08:18:42 louise Exp $
package Cobrand;
use strict;
@@ -426,6 +426,25 @@ sub site_title {
}
}
+=item on_map_list_limit COBRAND
+
+Return the maximum number of items to be given in the list of reports
+on the map
+
+=cut
+sub on_map_list_limit {
+ my ($cobrand) = @_;
+ my $handle;
+ if ($cobrand){
+ $handle = cobrand_handle($cobrand);
+ }
+ if ( !$cobrand || !$handle || !$handle->can('on_map_list_limit')){
+ return undef;
+ } else{
+ return $handle->on_map_list_limit();
+ }
+}
+
1;
diff --git a/perllib/Page.pm b/perllib/Page.pm
index f9312fb78..a234389a7 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Page.pm,v 1.188 2009-09-28 16:26:55 louise Exp $
+# $Id: Page.pm,v 1.189 2009-10-07 08:18:42 louise Exp $
#
package Page;
@@ -1004,4 +1004,23 @@ sub scambs_categories {
'Litter', 'Neighbourhood noise');
}
+=item apply_on_map_list_limit ON_MAP AROUND_MAP LIMIT
+
+Apply any defined limit to the list of reports on the map, moving any extra items to the
+'around the map' list
+
+=cut
+sub apply_on_map_list_limit {
+ my ($on_map, $around_map, $limit) = @_;
+ my $on_map_size = scalar @{$on_map};
+ if (!$limit || $limit >= $on_map_size){
+ return ($on_map, $around_map);
+ }
+ my @on_map = @$on_map;
+ my @around_map = @$around_map;
+ my @extras = @on_map[$limit..$on_map_size-1];
+ @on_map = @on_map[0..$limit-1];
+ push (@extras, @around_map);
+ return (\@on_map, \@extras);
+}
1;
diff --git a/t/Cobrand.t b/t/Cobrand.t
index 933a03cfa..21c601987 100755
--- a/t/Cobrand.t
+++ b/t/Cobrand.t
@@ -6,12 +6,12 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Cobrand.t,v 1.14 2009-09-28 15:38:30 louise Exp $
+# $Id: Cobrand.t,v 1.15 2009-10-07 08:18:42 louise Exp $
#
use strict;
use warnings;
-use Test::More tests => 44;
+use Test::More tests => 47;
use Test::Exception;
use FindBin;
@@ -205,6 +205,18 @@ sub test_site_title {
is($site_title, '', 'site_title returns an empty string if no site title');
}
+sub test_on_map_list_limit {
+ my $cobrand = 'mysite';
+ my $limit = Cobrand::on_map_list_limit($cobrand);
+
+ is($limit, 30, 'on_map_list_limit returns output from cobrand module');
+
+ $cobrand = 'nosite';
+ $limit = Cobrand::on_map_list_limit($cobrand);
+ is($limit, undef, 'on_map_list_limit returns undef if there is no limit defined by the cobrand');
+
+}
+
ok(test_cobrand_handle() == 1, 'Ran all tests for the cobrand_handle function');
ok(test_cobrand_page() == 1, 'Ran all tests for the cobrand_page function');
ok(test_site_restriction() == 1, 'Ran all tests for the site_restriction function');
@@ -219,4 +231,4 @@ ok(test_extra_params() == 1, 'Ran all tests for extra_params');
ok(test_header_params() == 1, 'Ran all tests for header_params');
ok(test_root_path_js() == 1, 'Ran all tests for root_js');
ok(test_site_title() == 1, 'Ran all tests for site_title');
-
+ok(test_on_map_list_limit() == 1, 'Ran all tests for on_map_list_limit');
diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm
index 36b04f596..e39e378d8 100644
--- a/t/Cobrands/Mysite/Util.pm
+++ b/t/Cobrands/Mysite/Util.pm
@@ -7,7 +7,7 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: Util.pm,v 1.13 2009-09-28 15:39:05 louise Exp $
+# $Id: Util.pm,v 1.14 2009-10-07 08:18:42 louise Exp $
package Cobrands::Mysite::Util;
use Page;
@@ -72,11 +72,14 @@ sub header_params {
sub root_path_js {
- return 'root path js';
+ return 'root path js';
}
sub site_title {
- return 'Mysite Title';
+ return 'Mysite Title';
}
+sub on_map_list_limit {
+ return 30;
+}
1;
diff --git a/t/Page.t b/t/Page.t
index 44530b21f..d69a26c4c 100755
--- a/t/Page.t
+++ b/t/Page.t
@@ -6,12 +6,12 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Page.t,v 1.5 2009-09-15 18:00:39 louise Exp $
+# $Id: Page.t,v 1.6 2009-10-07 08:18:42 louise Exp $
#
use strict;
use warnings;
-use Test::More tests => 15;
+use Test::More tests => 22;
use Test::Exception;
use FindBin;
@@ -90,7 +90,31 @@ sub test_base_url_with_lang {
}
+sub test_apply_on_map_list_limit {
+ my @original_on_map = ('a', 'b', 'c', 'd', 'e', 'f');
+ my @original_around_map = ('g', 'h', 'i', 'j', 'k');
+ my $limit = undef;
+
+ my ($on_map, $around_map) = Page::apply_on_map_list_limit(\@original_on_map, \@original_around_map, $limit);
+ is_deeply($on_map, \@original_on_map, 'On map list should be returned unaltered if no limit is given');
+ is_deeply($around_map, \@original_around_map, 'Around map list should be returned unaltered if no limit is given');
+
+ $limit = 20;
+ ($on_map, $around_map) = Page::apply_on_map_list_limit(\@original_on_map, \@original_around_map, $limit);
+ is_deeply($on_map, \@original_on_map, 'On map list should be returned unaltered if the limit is higher than the size of the on map list') or diag("Got @$on_map for @original_on_map");
+ is_deeply($around_map, \@original_around_map, 'Around map list should be returned unaltered if the limit is higher than the size of the on map list') or diag("Got @$around_map");
+
+ $limit = 3;
+ ($on_map, $around_map) = Page::apply_on_map_list_limit(\@original_on_map, \@original_around_map, $limit);
+ my @expected_on_map = ('a', 'b' ,'c');
+ my @expected_around_map = ( 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k');
+ is_deeply($on_map, \@expected_on_map, 'On map list is cropped to limit size') or diag("Got @$on_map");
+ is_deeply($around_map, \@expected_around_map, 'Around map list has extra items prepended') or diag("Got ");
+
+}
+
ok(test_base_url_with_lang() == 1, 'Ran all tests for base_url_with_lang');
ok(test_footer() == 1, 'Ran all tests for the footer function');
ok(test_header() == 1, 'Ran all tests for the header function');
ok(test_geocode_string() == 1, 'Ran all tests for the geocode_string function');
+ok(test_apply_on_map_list_limit() == 1, 'Ran all tests for apply_on_map_list_limit');
diff --git a/web/ajax.cgi b/web/ajax.cgi
index 61f2d649b..e00fe7100 100755
--- a/web/ajax.cgi
+++ b/web/ajax.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: ajax.cgi,v 1.12 2009-09-28 15:40:28 louise Exp $
+# $Id: ajax.cgi,v 1.13 2009-10-07 08:18:42 louise Exp $
use strict;
use Standard;
@@ -36,7 +36,8 @@ sub main {
$interval = '6 months';
}
my ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $sx, $sy, $interval);
-
+ my $limit = Cobrand::on_map_list_limit(Page::get_cobrand($q));
+ ($on_map, $around_map) = Page::apply_on_map_list_limit($on_map, $around_map, $limit);
my $list = '';
my $link = '';
foreach (@$on_map) {
diff --git a/web/index.cgi b/web/index.cgi
index 0827e3139..b9a999a02 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.293 2009-10-04 16:41:59 matthew Exp $
+# $Id: index.cgi,v 1.294 2009-10-07 08:18:42 louise Exp $
use strict;
use Standard;
@@ -797,6 +797,8 @@ sub display_location {
$interval = '6 months';
}
my ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $x, $y, $interval);
+ my $limit = Cobrand::on_map_list_limit(Page::get_cobrand($q));
+ ($on_map, $around_map) = Page::apply_on_map_list_limit($on_map, $around_map, $limit);
if ($input{no_pins}) {
$hide_link = NewURL($q, -retain=>1, no_pins=>undef);
$hide_text = _('Show pins');