Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate API controller for base locator module #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,454 changes: 2,453 additions & 1 deletion client/dist/js/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/main.js.map

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion client/dist/js/map.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72,762 changes: 72,694 additions & 68 deletions client/dist/js/vendor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/vendor.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions client/src/js/actions/locationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import ActionType from 'actions/ActionTypes';

// eslint-disable-next-line import/prefer-default-export
export function fetchLocations(params) {
const loc = window.location;

// removed unused query variables
if (params.address === '') {
delete params.address;
Expand All @@ -24,7 +22,7 @@ export function fetchLocations(params) {
return {
type: ActionType.FETCH_LOCATIONS,
payload: axios.get(
`${loc.protocol}//${loc.host}${loc.pathname}/json`,
`${window.dynamic_locator.dataLocation}`,
{
// same as "params: params"
params,
Expand Down
44 changes: 36 additions & 8 deletions client/src/js/components/search/SearchBar.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* global window, document */
import React, { Component } from 'react';
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {connect} from 'react-redux';
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
import { faSearch, faCheckCircle } from '@fortawesome/fontawesome-free-solid';
import {faCheckCircle, faSearch} from '@fortawesome/fontawesome-free-solid';
import PlacesAutocomplete from 'react-places-autocomplete';

import { fetchLocations } from 'actions/locationActions';
import { search } from 'actions/searchActions';
import { changePage } from 'actions/listActions';
import {fetchLocations} from 'actions/locationActions';
import {search} from 'actions/searchActions';
import {changePage} from 'actions/listActions';
import RadiusDropDown from 'components/search/RadiusDropDown';
import CategoryDropDown from 'components/search/CategoryDropDown';

Expand Down Expand Up @@ -57,6 +57,34 @@ export class SearchBar extends Component {
this.handleAddressChange = this.handleAddressChange.bind(this);
}

componentDidMount() {
if (!navigator.geolocation) {
return;
}

const success = position => {
const {latitude, longitude} = position.coords;
const geocoder = new google.maps.Geocoder;

geocoder.geocode({
location: {
lat: latitude,
lng: longitude,
}
}, (results, status) => {
if (status === 'OK') {
if (results[0]) {
this.handleSubmit(results[0].formatted_address);
}
}
});
};

const error = () => {
};

navigator.geolocation.getCurrentPosition(success, error);
}

/**
* 'Submits' form. Really just fires state change and changes the url.
Expand All @@ -82,7 +110,7 @@ export class SearchBar extends Component {

// selects dispatch and unit from this.props.
// const dispatch = this.props.dispatch; const unit = this.props.unit;
const { dispatch, unit } = this.props;
const {dispatch, unit} = this.props;

// dispatches search (updates search values)
dispatch(search({
Expand Down Expand Up @@ -157,7 +185,7 @@ export class SearchBar extends Component {
const {
address, category, radii, categories, unit, autocomplete
} = this.props;
let { radius } = this.props;
let {radius} = this.props;
if (typeof radius === 'string') {
radius = Number(radius);
}
Expand Down
1,026 changes: 1,025 additions & 1 deletion css/locator.css

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/Extensions/LocatorControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Dynamic\Locator\React\Extensions;

use Dynamic\Locator\Control\APIController;
use Dynamic\SilverStripeGeocoder\GoogleGeocoder;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Extension;
use SilverStripe\Core\Manifest\ModuleResourceLoader;
Expand Down Expand Up @@ -43,6 +45,8 @@ public function onBeforeInit()
*/
public function customScript()
{
$path = Controller::join_links(APIController::create()->Link(), 'json');

$radii = $this->owner->getShowRadius() ? $this->owner->getRadii() : [];
$radiiString = json_encode($radii);

Expand All @@ -63,6 +67,7 @@ public function customScript()

Requirements::customScript("
window.dynamic_locator = {
'dataLocation': '{$path}',
'radii': {$radiiString},
'categories': {$categoriesString},
'unit': '{$unit}',
Expand Down
8 changes: 0 additions & 8 deletions src/Extensions/LocatorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,13 @@ class LocatorExtension extends DataExtension
{

private static $db = [
'DefaultLat' => 'Decimal(10,7)',
'DefaultLng' => 'Decimal(10,7)',
'Clusters' => 'Boolean',
'Autocomplete' => 'Boolean',
];

public function updateCMSFields(FieldList $fields)
{
$fields->addFieldsToTab('Root.Settings', [
NumericField::create('DefaultLat')
->setTitle('Default Latitude')
->setScale(7),
NumericField::create('DefaultLng')
->setTitle('Default Longitude')
->setScale(7),
CheckboxField::create('Clusters')
->setRightTitle('Cluster the markers when zoomed out.'),
CheckboxField::create('Autocomplete')
Expand Down