-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add new leaflet map background configuration #4881
Conversation
3f7f899
to
ad008b4
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4881 +/- ##
==========================================
+ Coverage 96.59% 96.62% +0.02%
==========================================
Files 758 760 +2
Lines 25787 25822 +35
Branches 3379 3382 +3
==========================================
+ Hits 24910 24951 +41
+ Misses 612 606 -6
Partials 265 265 ☔ View full report in Codecov by Sentry. |
src/openforms/config/models/map.py
Outdated
class LeafletMapBackground(models.Model): | ||
identifier = models.SlugField( | ||
_("identifier"), | ||
help_text=_("A unique identifier for the Leaflet map background"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a max length here, something like max_length=50
) | ||
url = models.URLField( | ||
_("background url"), | ||
help_text=_( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same here (max length).
|
||
|
||
@disable_admin_mfa() | ||
class LeafletMapBackgroundTests(WebTest): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess these were added for test coverage?Otherwise they do not make sense (testing the already tested django code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check, yeah this just tests the creation and pages for the new map object.
The tests aren't particular exciting, but maybe nice as "sanity check" tests :)
identifier=component["backgroundIdentifier"] | ||
) | ||
# Write the background url information | ||
component["url"] = leaflet_map_background.url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this out from the try block and emphasize only on the line which will cause the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sounds good. Will do 👍
fa2ddc5
to
5b507f9
Compare
This PR is depended on open-formulieren/formio-builder#197. When the formio-builder PR is merged, the Once that has been done, this PR can be merged |
9636d7d
to
c5444bc
Compare
The formio-builder has been updated. This PR can now be fully reviewed |
The map background PR (#4881) will implement this properly. For the time being, this will fix the issue
const MAP_TILE_LAYERS = jsonScriptToVar('config-MAP_TILE_LAYERS', { | ||
default: [], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this outside of the method onto the module level - since the data is supposed to already be in the DOM before the JS starts to run, we can evaluate this at load-time rather than doing the same evaluation every time a map gets rendered.
"lat": "43.23", | ||
"lng": "41.23", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these stored as string or floats with the actual formio-builder? The types say number
: https://github.com/open-formulieren/types/blob/5e2e2a219b4280c162c6eeffa6a51e333706bf49/src/formio/components/map.ts#L40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah check, yeah these should be floats. Changing it 👍
if component.get("tileLayerIdentifier", False): | ||
try: | ||
tile_layer = MapTileLayer.objects.get( | ||
identifier=component["tileLayerIdentifier"] | ||
) | ||
except MapTileLayer.DoesNotExist: | ||
return None | ||
|
||
# Add the tile layer url information | ||
component["tileLayerUrl"] = tile_layer.url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With some shortcuts and our beloved :walrus: operator
if component.get("tileLayerIdentifier", False): | |
try: | |
tile_layer = MapTileLayer.objects.get( | |
identifier=component["tileLayerIdentifier"] | |
) | |
except MapTileLayer.DoesNotExist: | |
return None | |
# Add the tile layer url information | |
component["tileLayerUrl"] = tile_layer.url | |
if (identifier := component.get("tileLayerIdentifier")) is not None: | |
tile_layer = MapTileLayer.objects.filter(identifier=identifier).first() | |
if tile_layer is not None: | |
# Add the tile layer url information | |
component["tileLayerUrl"] = tile_layer.url |
the fallback to False
introduces yet another type to handle (now we have str | None
rather than str | None | bool
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay cool. Yeah that objects.filter
is also pretty nice
@@ -189,6 +189,20 @@ def build_serializer_field( | |||
class Map(BasePlugin[Component]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it may be a good idea to define a MapComponent
type that's more specific and includes the extra properties that are component specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah definitely, seeing as this component will get a bit bigger with the other changes..
I've added a MapComponent
type and replaced some instances of Component
with MapComponent
@@ -1,5 +1,6 @@ | |||
[ | |||
"config.RichTextColor", | |||
"config.MapTileLayer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should go in the configuration group, since the unlisted stuff doesn't get displayed to non-superusers, I think
(and that's probably a problem for the rich text colors)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh okay, yeah that would be a big problem..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now i've left RichTextColors in the unlisted file
src/openforms/config/models/map.py
Outdated
_("identifier"), | ||
unique=True, | ||
max_length=50, | ||
help_text=_("A unique identifier for the tile layer"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help_text=_("A unique identifier for the tile layer"), | |
help_text=_("A unique identifier for the tile layer."), |
url = models.URLField( | ||
_("tile layer url"), | ||
max_length=255, | ||
help_text=_( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need a disclaimer that the tiler layers must use EPSG:28992 (Rijksdriehoek coordinate system), using other systems will probably lead to weird results.
src/openforms/config/admin.py
Outdated
fields = [ | ||
"label", | ||
"identifier", | ||
"url", | ||
] | ||
list_display = [ | ||
"label", | ||
"identifier", | ||
"url", | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to favour tuples rather than lists for these properties, because:
- tuples are immutable
- lists defined at the module level are mutable and people tend to try nasty things where they dynamically patch the admin class and add stuff (in tests) and then they get surprises 3 months later
In general I avoid using mutable datastructures at the module-level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert this? We'll handle translations close to release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will do 👍
The map configuration can be edited at any moment. To make sure that we always return the correct tile layer url, fetch the url and add it to the component object dynamically. Using the mutate_config_dynamically we can now use the tile_layer_url for form steps and the form summary.
c5444bc
to
b58cddf
Compare
Part of #2173
Changes
Adds a new admin config page/model for Leaflet map backgrounds. The map components can use these new background definitions to display custom backgrounds on the tile layer (for the formio-builder and sdk).
When a map component is fetched (by the formio-builder and/or sdk), the url for the background is fetched and passed along. This allows admins to update the Leaflet map background urls and makes sure that all map components use the new configuration.
This PR also adds some tests for the existing
rewrite_for_request
map component logic (updating the component, if global config should be used).Checklist
Check off the items that are completed or not relevant.
Impact on features
Release management
I have updated the translations assets (you do NOT need to provide translations)
./bin/makemessages_js.sh
./bin/compilemessages_js.sh
Commit hygiene