Skip to content

Commit

Permalink
Merge pull request #495 from maykinmedia/feature/1156-add-email-phone…
Browse files Browse the repository at this point in the history
…number-to-location-cards

[#1156] Add email and phonenumber to map and location cards
  • Loading branch information
alextreme authored Mar 3, 2023
2 parents 51401c8 + f48d098 commit a54aa30
Show file tree
Hide file tree
Showing 8 changed files with 1,277 additions and 20,381 deletions.
21,541 changes: 1,192 additions & 20,349 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@tarekraafat/autocomplete.js": "^10.2.6",
"bem.js": "^1.0.10",
"emojibase-data": "^7.0.1",
"escape-html": "^1.0.3",
"flatpickr": "^4.6.9",
"gumshoejs": "^5.1.2",
"html-minifier": "^4.0.0",
Expand All @@ -62,7 +63,7 @@
"@babel/preset-env": "latest",
"@types/leaflet": "^1.7.6",
"autoprefixer": "^9.0.0",
"babel-loader": "latest",
"babel-loader": "^8.2.5",
"chai": "latest",
"css-loader": "latest",
"cssnano": "latest",
Expand Down
25 changes: 16 additions & 9 deletions src/open_inwoner/js/components/map/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import escapeHTML from 'escape-html'
import 'leaflet'
import { RD_CRS } from './rd'
import { isMobile } from '../../lib/device/is-mobile'
Expand Down Expand Up @@ -74,16 +75,22 @@ class Map {
*/
featureToHTML(feature) {
const { name, ...properties } = feature.properties
const displayName = name ? name : ''
const displayName = name ? escapeHTML(name) : ''
let finalHTML = ``

Object.entries(properties).forEach((property) => {
finalHTML += `<p class="p">${escapeHTML(property[1])}</p>`
})

return `
<h4 class="h4">
${displayName}
</h4>
<p class="p">
${Object.entries(properties)
.map(([key, value]) => value)
.join(' ')}
</p>
<div class="leaflet-content-name">
<h4 class="h4">
${displayName}
</h4>
</div>
<div class="leaflet-content-details p--no-margin">
${finalHTML}
</div>
`
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/open_inwoner/pdc/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,24 @@ def get_geojson_geometry(self) -> str:

def get_serialized_fields(self) -> dict:
"""
Returns fields listed in serializable_fields (see below) as dict if JSON serializable.
Returns fields (and combination of fields via method) listed in serializable_fields (see below)
as dict if JSON serializable.
"""
serializable_fields = ["name", "street", "housenumber", "postcode", "city"]
serializable_fields = [
"name",
"address_line_1",
"address_line_2",
"email",
"phonenumber",
]
serialized_fields = {}

for name in serializable_fields:
if not self._meta.get_field(name):
try:
value = getattr(self, name)
except AttributeError:
continue

value = getattr(self, name)

try:
json.dumps(value) # Check if json serializable.
serialized_fields[name] = value
Expand Down
40 changes: 24 additions & 16 deletions src/open_inwoner/pdc/tests/test_product_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def test_get_geojson_feature(self):
housenumber="117",
postcode="1015 CJ",
city="Amsterdam",
email="[email protected]",
phonenumber="+31666767676",
geometry=Point(4.8876515, 52.3775941),
)
product = ProductFactory.create(locations=(product_location,))
Expand All @@ -84,10 +86,10 @@ def test_get_geojson_feature(self):
},
"properties": {
"name": "Maykin Media",
"street": "Keizersgracht",
"housenumber": "117",
"postcode": "1015 CJ",
"city": "Amsterdam",
"address_line_1": "Keizersgracht 117",
"address_line_2": "1015CJ Amsterdam",
"email": "[email protected]",
"phonenumber": "+31666767676",
},
}
),
Expand All @@ -114,14 +116,16 @@ def test_get_serialized_fields(self):
housenumber="117",
postcode="1015 CJ",
city="Amsterdam",
email="[email protected]",
phonenumber="+31666767676",
)
self.assertEqual(
{
"city": "Amsterdam",
"housenumber": "117",
"name": "Maykin Media",
"postcode": "1015 CJ",
"street": "Keizersgracht",
"address_line_1": "Keizersgracht 117",
"address_line_2": "1015CJ Amsterdam",
"email": "[email protected]",
"phonenumber": "+31666767676",
},
product_location.get_serialized_fields(),
)
Expand All @@ -133,6 +137,8 @@ def test_queryset_get_geojson_feature_collection(self):
housenumber="4",
postcode="7411 KT",
city="Deventer",
email="[email protected]",
phonenumber="+31999767676",
geometry=Point(6.155650, 52.251550),
)
product_location_2 = ProductLocationFactory.create(
Expand All @@ -141,6 +147,8 @@ def test_queryset_get_geojson_feature_collection(self):
housenumber="204",
postcode="1015 KL",
city="Amsterdam",
email="[email protected]",
phonenumber="+31666767676",
geometry=Point(4.883400, 52.380260),
)
product_1 = ProductFactory(locations=(product_location_1,))
Expand All @@ -158,10 +166,10 @@ def test_queryset_get_geojson_feature_collection(self):
},
"properties": {
"name": "Gemeente Deventer",
"street": "Grote Kerkhof",
"housenumber": "4",
"postcode": "7411 KT",
"city": "Deventer",
"address_line_1": "Grote Kerkhof 4",
"address_line_2": "7411KT Deventer",
"email": "[email protected]",
"phonenumber": "+31999767676",
},
},
{
Expand All @@ -172,10 +180,10 @@ def test_queryset_get_geojson_feature_collection(self):
},
"properties": {
"name": "Gemeente Amsterdam",
"street": "Lindengracht",
"housenumber": "204",
"postcode": "1015 KL",
"city": "Amsterdam",
"address_line_1": "Lindengracht 204",
"address_line_2": "1015KL Amsterdam",
"email": "[email protected]",
"phonenumber": "+31666767676",
},
},
],
Expand Down
13 changes: 13 additions & 0 deletions src/open_inwoner/scss/components/Map/_Map.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@
.p + .map {
margin-top: var(--spacing-large);
}

.leaflet-content-name {
& > h4 {
margin: 0 !important;
}
}

.leaflet-content-details {
display: flex;
flex-direction: column;
row-gap: var(--spacing-small);
flex-wrap: wrap;
}
8 changes: 8 additions & 0 deletions src/open_inwoner/scss/components/Typography/P.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@
.p .link {
text-decoration: underline;
}

.p--no-margin {
margin-top: var(--spacing-small);

& > .p {
margin: 0 !important;
}
}
11 changes: 10 additions & 1 deletion src/open_inwoner/templates/pages/product/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ <h3 class="h3">{% trans "U komt niet in aanmerking" %}</h3>
{% render_card_container columns=3 %}
{% for location in object.locations.all %}
{% render_card title=location.name %}
<p class="p">{{ location.address_line_1 }}<br>{{ location.address_line_2 }}</p>
<div class="p--no-margin">
<p class="p">{{ location.address_line_1 }}</p>
<p class="p">{{ location.address_line_2 }}</p>
{% if location.phonenumber %}
<p class="p">{{ location.phonenumber }}</p>
{% endif %}
{% if location.email %}
<p class="p">{{ location.email }}</p>
{% endif %}
</div>
{% endrender_card %}
{% endfor %}
{% endrender_card_container %}
Expand Down

0 comments on commit a54aa30

Please sign in to comment.