Skip to content

Commit

Permalink
Vendor module and front end module support (#174)
Browse files Browse the repository at this point in the history
* vendor module
* shifted more stuff around
* Started to shift things around to prep for front end modules
* Converted all string class refrences to static::class
Started to create tests for new methods

* Re-arranged tests
Added more tests to LocatorTest.php
  - split LocatorTest.php into locator and controller tests respectivly

* Fixed scrutinizer

* Added more tests

* Added another test

* Made locator less of a priority for templates
  - front end modules now get to be first

* moved the loading of google maps outside of trigger check

* Now uses config values to get variable names
  - Allows to change `Controller::curr()->getRequest()->getVar('Radius')` to `Controller::curr()->getRequest()->getVar('radius')`
  - same with category

* Updated docs
  • Loading branch information
mak001 committed Jan 15, 2018
1 parent 15c2d11 commit 14bd8a5
Show file tree
Hide file tree
Showing 26 changed files with 586 additions and 231 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

Expand Down
8 changes: 7 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ checks:
code_rating: true
duplication: true

build:
nodes:
analysis:
tests:
override: [php-scrutinizer-run]

filter:
paths: [tests/*,code/*]
paths: [tests/*,code/*]
19 changes: 18 additions & 1 deletion _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,21 @@ Dynamic\Locator\Location:
extensions:
- Dynamic\SilverStripeGeocoder\DistanceDataExtension
- Dynamic\SilverStripeGeocoder\AddressDataExtension
- SilverStripe\Versioned\Versioned('Stage','Live')
- SilverStripe\Versioned\Versioned('Stage','Live')

Dynamic\Locator\Locator:
infoWindowTemplate: 'dynamic/silverstripe-locator: client/infowindow-description.html'
listTemplate: 'dynamic/silverstripe-locator: client/location-list-description.html'
limit: 50
show_radius: true
radius_var: 'Radius'
category_var: 'CategoryID'

---
Name: modules-locator
After: modules-other
Before: modules-framework
---
SilverStripe\Core\Manifest\ModuleManifest:
module_priority:
- dynamic/silverstripe-locator
File renamed without changes.
File renamed without changes.
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"google maps",
"location"
],
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"license": "BSD-3-Clause",
"authors": [
{
Expand All @@ -21,12 +21,14 @@
],
"require": {
"silverstripe/recipe-cms": "^1.0",
"silverstripe/vendor-plugin": "^1.0",
"muskie9/data-to-arraylist": "^2.0",
"dynamic/silverstripe-geocoder": "^1.0",
"symbiote/silverstripe-gridfieldextensions": "^3.0"
},
"require-dev": {
"phpunit/PHPUnit": "^5.7"
"phpunit/PHPUnit": "^5.7",
"squizlabs/php_codesniffer": "*"
},
"config": {
"process-timeout": 600
Expand All @@ -44,7 +46,11 @@
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"installer-name": "locator",
"expose": [
"thirdparty",
"css",
"client"
],
"branch-alias": {
"dev-master": "3.0.x-dev"
}
Expand Down
46 changes: 46 additions & 0 deletions docs/en/developerguide/customizing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Customizing
Some customization is done through a yml config.

### Limit
Will limit the amount of locations that can be shown at one time. Set to `-1` to have no limit. Having no limit can result in slow load times, or even timeouts when loading the page or new data.
```yaml
Dynamic\Locator\Locator:
limit: 50
```
### Radius
- `show_radius` will determine if a radius dropdown should be shown.
- `radii` is a list of radii to use in the radius dropdown.
```yaml
Dynamic\Locator\Locator:
show_radius: true
radii: [30, 50, 100]
```

### Templates
Overriding the templates for the info window and list can be overridden by using `infoWindowTemplate` and `listTemplate`.
- `infoWindowTemplate` is the popup when a location is clicked.
- `listTemplate` is a single location in the list
```yaml
Dynamic\Locator\Locator:
infoWindowTemplate: 'dynamic/silverstripe-locator: client/infowindow-description.html'
listTemplate: 'dynamic/silverstripe-locator: client/location-list-description.html'
```
The `vendor/module: file` pattern can be used to locate files.

### Custom URL Variables
Sometimes it is useful to override the defaults for url variables.
An example of this is when the module uses title case but you wrote everything for lowercase. It becomes seamless to switch out the variable names.
- `radius_var` is the variable used to send and receive the currently selected radius.
- `category_var` is the variable used to send and receive the currently selected category.
- `address_var` is the variable used to send and receive the searched location.
- `unit_var` is the variable used to send and receive the current unit of measure used for distance.
```yaml
Dynamic\Locator\Locator:
radius_var: 'Radius'
category_var: 'CategoryID'
Dynamic\SilverStripeGeocoder\DistanceDataExtension:
address_var: 'Address'
unit_var: 'Unit'
```
8 changes: 8 additions & 0 deletions docs/en/developerguide/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Setup
To use google maps an api key is required.
In mysite/_config/settings.yml
```yaml
Dynamic\SilverStripeGeocoder\GoogleGeocoder:
geocoder_api_key: YOUR_API_KEY
```
Replace `YOUR_API_KEY` with your google maps api key. If you are unsure where to get an api key, [look here](https://developers.google.com/maps/documentation/javascript/get-api-key).
11 changes: 8 additions & 3 deletions docs/en/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#SilverStripe Locator
# SilverStripe Locator

##Using Locator
## Using Locator

See [User Guide](userguide/index.md) for information on using the Locator module in the CMS.

See [Importing Locations](userguide/import.md) for information on importing Location and Category records.
See [Importing Locations](userguide/import.md) for information on importing Location and Category records.

## Developer guides

- [Setup](developerguide/setup.md)
- [Customizing](developerguide/customizing.md)
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<phpunit bootstrap="cms/tests/bootstrap.php" colors="true">
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
<testsuite name="locator">
<directory>tests</directory>
</testsuite>
Expand Down
10 changes: 6 additions & 4 deletions src/admin/LocationAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Dynamic\Locator;

use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Dev\CsvBulkLoader;
use SilverStripe\Forms\Form;

/**
* Class LocationAdmin
Expand All @@ -14,16 +16,16 @@ class LocationAdmin extends ModelAdmin
* @var array
*/
private static $managed_models = array(
'Dynamic\\Locator\\Location',
'Dynamic\\Locator\\LocationCategory',
Location::class,
LocationCategory::class,
);

/**
* @var array
*/
private static $model_importers = array(
'Dynamic\\Locator\\Location' => 'Dynamic\\Locator\\LocationCsvBulkLoader',
'Dynamic\\Locator\\LocationCategory' => 'SilverStripe\\Dev\\CsvBulkLoader',
Location::class => LocationCsvBulkLoader::class,
LocationCategory::class => CsvBulkLoader::class,
);

/**
Expand Down
20 changes: 3 additions & 17 deletions src/form/LocatorForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@
*/
class LocatorForm extends Form
{
/**
* @var bool
*/
private static $show_radius = true;

/**
* @var array
*/
private static $radius_array = [
'25' => '25',
'50' => '50',
'75' => '75',
'100' => '100',
];

/**
* LocatorForm constructor.
Expand Down Expand Up @@ -64,8 +50,8 @@ public function __construct(Controller $controller, $name)
$fields->push($categoriesField);
}

if (Config::inst()->get(LocatorForm::class, 'show_radius')) {
$radiusArray = Config::inst()->get(LocatorForm::class, 'radius_array');
if ($controller->getShowRadius()) {
$radiusArray = $controller->getRadii();
$this->extend('overrideRadiusArray', $radiusArray);
$fields->push(DropdownField::create('Radius', '', $radiusArray)
->setEmptyString('radius')
Expand Down Expand Up @@ -95,4 +81,4 @@ public function getValidator()
$this->extend('updateRequiredFields', $validator);
return $validator;
}
}
}
5 changes: 5 additions & 0 deletions src/objects/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Location extends DataObject implements PermissionProvider
*/
private static $plural_name = 'Locations';

/**
* @var bool
*/
private static $versioned_gridfield_extensions = true;

/**
* @var array
*/
Expand Down
5 changes: 3 additions & 2 deletions src/objects/LocationCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
Expand Down Expand Up @@ -72,9 +73,9 @@ public function getCMSFields()
if ($this->ID) {
// Locations
$config = GridFieldConfig_RelationEditor::create();
$config->removeComponentsByType('GridFieldAddExistingAutocompleter');
$config->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
$config->addComponent(new GridFieldAddExistingAutocompleter());
$config->removeComponentsByType('GridFieldAddNewButton');
$config->removeComponentsByType(GridFieldAddNewButton::class);
$locations = $this->Locations();
$locationField = GridField::create('Locations', 'Locations', $locations, $config);

Expand Down
Loading

0 comments on commit 14bd8a5

Please sign in to comment.