From 24b6a29ca1a3a570d6068f327c7487400f834432 Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Tue, 21 Jan 2020 19:54:14 -0600 Subject: [PATCH 1/3] REFACTOR Locator - getTrigger Check if any GET vars exist, or if static $db ResultsOnLoad is true. If so, display results. closes #219 --- src/pages/Locator.php | 14 ++++++++++++++ src/pages/LocatorController.php | 11 +---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/pages/Locator.php b/src/pages/Locator.php index 4d89a95..b823a2b 100644 --- a/src/pages/Locator.php +++ b/src/pages/Locator.php @@ -4,6 +4,7 @@ use Dynamic\SilverStripeGeocoder\AddressDataExtension; use SilverStripe\Core\Manifest\ModuleResourceLoader; +use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; use SilverStripe\Forms\HeaderField; @@ -46,6 +47,7 @@ class Locator extends \Page */ private static $db = array( 'Unit' => 'Enum("m,km","m")', + 'ResultsOnLoad' => 'Boolean', ); /** @@ -55,6 +57,13 @@ class Locator extends \Page 'Categories' => LocationCategory::class, ); + /** + * @var array + */ + private static $defaults = [ + 'ResultsOnLoad' => 0, + ]; + /** * @var string */ @@ -75,6 +84,11 @@ public function getCMSFields() $fields->addFieldsToTab('Root.Settings', array( HeaderField::create('DisplayOptions', 'Display Options', 3), OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), + CheckboxField::create('ResultsOnLoad', 'Show results on page load') + ->setDescription('For larger collections of locations, it is + recommended to only show a limited amount of results after a location + search.' + ) )); // Filter categories diff --git a/src/pages/LocatorController.php b/src/pages/LocatorController.php index e03c6c6..170d74a 100644 --- a/src/pages/LocatorController.php +++ b/src/pages/LocatorController.php @@ -63,13 +63,6 @@ class LocatorController extends \PageController */ private static $list_container = 'loc-list'; - /** - * GET variable which, if isset, will trigger storeLocator init and return XML - * - * @var string - */ - private static $query_trigger = 'action_doFilterLocations'; - /** * @var DataList|ArrayList */ @@ -185,9 +178,7 @@ public function getTrigger(HTTPRequest $request = null) if ($request === null) { $request = $this->getRequest(); } - $trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger')); - - return isset($trigger); + return !empty($this->getRequest()->getVars()) || $this->data()->ResultsOnLoad; } /** From 0da4fc7df9061fc7ab952a7221f12d9fd93074c9 Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Tue, 21 Jan 2020 19:59:11 -0600 Subject: [PATCH 2/3] travis tweak --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b8b5acb..f31a2bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ before_script: script: - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ *.php; fi + - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/; fi after_success: - - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml -F php; fi \ No newline at end of file + - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml -F php; fi From 757e460af77291c3d74fbd50e6f172f89bd2b635 Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Tue, 21 Jan 2020 20:04:21 -0600 Subject: [PATCH 3/3] phpcs --- src/pages/Locator.php | 3 +-- tests/pages/LocatorControllerTest.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/Locator.php b/src/pages/Locator.php index b823a2b..71bcd45 100644 --- a/src/pages/Locator.php +++ b/src/pages/Locator.php @@ -87,8 +87,7 @@ public function getCMSFields() CheckboxField::create('ResultsOnLoad', 'Show results on page load') ->setDescription('For larger collections of locations, it is recommended to only show a limited amount of results after a location - search.' - ) + search.') )); // Filter categories diff --git a/tests/pages/LocatorControllerTest.php b/tests/pages/LocatorControllerTest.php index f9e62d4..f954f71 100644 --- a/tests/pages/LocatorControllerTest.php +++ b/tests/pages/LocatorControllerTest.php @@ -2,7 +2,6 @@ namespace Dynamic\Locator\Tests; -use \DOMDocument; use Dynamic\Locator\LocationCategory; use Dynamic\Locator\Locator; use Dynamic\Locator\LocatorController; @@ -50,7 +49,7 @@ public function testXml() $this->assertEquals(200, $page->getStatusCode()); $this->assertEquals('application/xml', $page->getHeader('content-type')); - $dom = new DOMDocument(); + $dom = new \DOMDocument(); // true if it loads, false if it doesn't $valid = $dom->loadXML($page->getBody()); $this->assertTrue($valid);