Skip to content

Commit

Permalink
Merge pull request #129 from collective/revert-117-ajax-geojson
Browse files Browse the repository at this point in the history
Revert "implement AJAX geoJSON feature"
  • Loading branch information
petschki authored May 28, 2021
2 parents a0ab115 + 3254bc9 commit 1d09003
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 79 deletions.
3 changes: 0 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ Breaking Change:
- Fix search which include the terms "and", "or" and "not"
[jeffersonbledsoe]

- implement AJAX geoJSON feature (needs ``plone.patternslib>=1.2.2``)
[petschki]


3.4.2 (2021-02-25)
------------------
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def read(*rnames):
# support for latitude/longitude catalog index
"collective.geolocationbehavior >= 1.6.0",
# refactored map configuration
'plone.formwidget.geolocation >= 2.2.0',
# AJAX geoJSON feature
'plone.patternslib >= 1.2.2.dev0',
"plone.formwidget.geolocation >= 2.2.0",
# leaflet JS events for map filter
"plone.patternslib >= 1.1.0",
],
"test": [
"plone.app.mosaic",
Expand Down
47 changes: 10 additions & 37 deletions src/collective/collectionfilter/baseviews.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from Products.CMFPlone.utils import get_top_request
from Products.CMFPlone.utils import safe_unicode
from Products.Five import BrowserView
from collective.collectionfilter import PLONE_VERSION
from collective.collectionfilter.filteritems import get_filter_items
from collective.collectionfilter.interfaces import IGroupByCriteria
Expand All @@ -20,6 +17,8 @@
from plone.i18n.normalizer.interfaces import IIDNormalizer
from plone.memoize import instance
from plone.uuid.interfaces import IUUID
from Products.CMFPlone.utils import get_top_request
from Products.CMFPlone.utils import safe_unicode
from six.moves.urllib.parse import urlencode
from zope.component import getUtility
from zope.component import queryUtility
Expand Down Expand Up @@ -284,19 +283,6 @@ def ajax_url(self):
)
return ajax_url

@property
def geojson_ajax_url(self):
# Recursively transform all to unicode
request_params = safe_decode(self.top_request.form)
urlquery = base_query(
request_params, extra_ignores=['latitude', 'longitude'])
query_param = urlencode(safe_encode(urlquery), doseq=True)
geojson_ajax_url = u'{}/@@geodata.json{}'.format(
self.url,
'?' + query_param if query_param else '',
)
return geojson_ajax_url

@property
def locations(self):
custom_query = {} # Additional query to filter the collection
Expand All @@ -320,11 +306,8 @@ def locations(self):
def data_geojson(self):
"""Return the geo location as GeoJSON string."""
features = []
locations = self.locations
count = len(locations)
limit = self.settings.geojson_properties_limit

for it in locations:
for it in self.locations:
if not it.longitude or not it.latitude:
# these ``it`` are brains, so anything which got lat/lng
# indexed can be used.
Expand All @@ -343,14 +326,13 @@ def data_geojson(self):
},
}

if count < limit:
props = IGeoJSONProperties(it.getObject(), None)
if getattr(props, 'popup', None):
feature['properties']['popup'] = props.popup
if getattr(props, 'color', None):
feature['properties']['color'] = props.color
if getattr(props, 'extraClasses', None):
feature['properties']['extraClasses'] = props.extraClasses
props = IGeoJSONProperties(it.getObject(), None)
if getattr(props, "popup", None):
feature["properties"]["popup"] = props.popup
if getattr(props, "color", None):
feature["properties"]["color"] = props.color
if getattr(props, "extraClasses", None):
feature["properties"]["extraClasses"] = props.extraClasses

features.append(feature)

Expand All @@ -374,12 +356,3 @@ def map_configuration(self):
],
}
return json.dumps(config)

class GeoJSON(BrowserView):

def __call__(self):
""" AJAX response of GeoJSON data """
self.request.response.setHeader("Content-type", "application/json")
if not hasattr(self.context, 'data_geojson'):
return {}
return self.context.data_geojson
8 changes: 0 additions & 8 deletions src/collective/collectionfilter/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@
handler=".contentfilter.set_content_filter"
/>

<browser:page
zcml:condition="installed collective.geolocationbehavior"
name="geodata.json"
class=".baseviews.GeoJSON"
for="*"
permission="zope2.View"
/>

<genericsetup:registerProfile
name="default"
title="collective.collectionfilter base"
Expand Down
14 changes: 1 addition & 13 deletions src/collective/collectionfilter/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,4 @@ class ICollectionMapsSchema(ICollectionFilterBaseSchema):
value_type=schema.Choice(
vocabulary="plone.formwidget.geolocation.vocabularies.map_layers"
),
)

geojson_properties_limit = schema.Int(
title=_(
u'geojson_properties_limit',
default=u"Limit for GeoJSON properties"),
description=_(
u'help_geojson_properties_limit',
default=u"If the search result is larger than this limit, no additional "
"GeoJSON properties (like popup information) are shown."),
required=False,
default=500,
)
) # noqa: E501
5 changes: 3 additions & 2 deletions src/collective/collectionfilter/portlets/maps.pt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

<header class="portletHeader" tal:condition="view/title" tal:content="view/title">Title</header>
<tal:if condition="view/collection|nothing">
<tal:def define="geojson view/data_geojson">
<header tal:condition="view/title" tal:content="view/title">Title</header>
<div class="pat-leaflet" data-pat-leaflet='${view/map_configuration}' data-url="${view/ajax_url}" data-narrow-down-result="${view/settings/narrow_down}"
data-geojson="${view/geojson_ajax_url}"></div>
<div class="plone-loader"><div class="loader" /></div>
tal:attributes="data-geojson python:geojson or None"></div>
</tal:def>
</tal:if>
</aside>

Large diffs are not rendered by default.

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

Loading

0 comments on commit 1d09003

Please sign in to comment.