From e1a24b61808e7286c8cfa917b72bcd03d0385868 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 12 Nov 2024 13:27:29 +0100 Subject: [PATCH] chore: fix updaters to use umap instead of map and properties instead of options --- umap/static/umap/js/modules/rendering/map.js | 2 +- umap/static/umap/js/modules/slideshow.js | 2 +- umap/static/umap/js/modules/sync/updaters.js | 16 ++++++++-------- umap/static/umap/js/modules/umap.js | 2 +- umap/static/umap/js/modules/utils.js | 5 ++++- umap/tests/integration/test_websocket_sync.py | 6 +++--- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/umap/static/umap/js/modules/rendering/map.js b/umap/static/umap/js/modules/rendering/map.js index 92e10a8e..8a042f93 100644 --- a/umap/static/umap/js/modules/rendering/map.js +++ b/umap/static/umap/js/modules/rendering/map.js @@ -252,7 +252,7 @@ const ControlsMixin = { }) const updateConnectedPeersCount = () => { - connectedPeersCount.innerHTML = this.sync.getNumberOfConnectedPeers() + connectedPeersCount.innerHTML = this.umap.sync.getNumberOfConnectedPeers() } updateConnectedPeersCount() } diff --git a/umap/static/umap/js/modules/slideshow.js b/umap/static/umap/js/modules/slideshow.js index 6d3e8a67..2294249f 100644 --- a/umap/static/umap/js/modules/slideshow.js +++ b/umap/static/umap/js/modules/slideshow.js @@ -83,7 +83,7 @@ export default class Slideshow extends WithTemplate { play() { if (this._id) return - if (this.umap.editEnabled || !this.umap.options.slideshow.active) return + if (this.umap.editEnabled || !this.umap.properties.slideshow.active) return L.DomUtil.addClass(document.body, this.CLASSNAME) this._id = window.setInterval(L.bind(this.loop, this), this.options.delay) this.startSpinner() diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index 77992acc..09169f99 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -6,8 +6,8 @@ import { fieldInSchema } from '../utils.js' */ class BaseUpdater { - constructor(map) { - this.map = map + constructor(umap) { + this.umap = umap } updateObjectValue(obj, key, value) { @@ -32,8 +32,8 @@ class BaseUpdater { } getDataLayerFromID(layerId) { - if (layerId) return this.map.getDataLayerByUmapId(layerId) - return this.map.defaultEditDataLayer() + if (layerId) return this.umap.getDataLayerByUmapId(layerId) + return this.umap.defaultEditDataLayer() } applyMessage(payload) { @@ -45,18 +45,18 @@ class BaseUpdater { export class MapUpdater extends BaseUpdater { update({ key, value }) { if (fieldInSchema(key)) { - this.updateObjectValue(this.map, key, value) + this.updateObjectValue(this.umap, key, value) } - this.map.render([key]) + this.umap.render([key]) } } export class DataLayerUpdater extends BaseUpdater { upsert({ value }) { // Inserts does not happen (we use multiple updates instead). - this.map.createDataLayer(value, false) - this.map.render([]) + this.umap.createDataLayer(value, false) + this.umap.render([]) } update({ key, metadata, value }) { diff --git a/umap/static/umap/js/modules/umap.js b/umap/static/umap/js/modules/umap.js index b543f747..a5e93400 100644 --- a/umap/static/umap/js/modules/umap.js +++ b/umap/static/umap/js/modules/umap.js @@ -1245,7 +1245,7 @@ export default class Umap extends ServerStored { render(fields) { if (fields.includes('numberOfConnectedPeers')) { - this.renderEditToolbar() + this._leafletMap.renderEditToolbar() this.propagate() } diff --git a/umap/static/umap/js/modules/utils.js b/umap/static/umap/js/modules/utils.js index 8ce52c99..26829f99 100644 --- a/umap/static/umap/js/modules/utils.js +++ b/umap/static/umap/js/modules/utils.js @@ -66,7 +66,10 @@ export function getImpactsFromSchema(fields, schema) { export function fieldInSchema(field, schema) { const current_schema = schema || U.SCHEMA if (typeof field !== 'string') return false - const field_name = field.replace('options.', '').split('.')[0] + const field_name = field + .replace('options.', '') + .replace('properties.', '') + .split('.')[0] return current_schema[field_name] !== undefined } diff --git a/umap/tests/integration/test_websocket_sync.py b/umap/tests/integration/test_websocket_sync.py index 83f49e32..87dd729e 100644 --- a/umap/tests/integration/test_websocket_sync.py +++ b/umap/tests/integration/test_websocket_sync.py @@ -161,7 +161,7 @@ def test_websocket_connection_can_sync_polygons( @pytest.mark.xdist_group(name="websockets") def test_websocket_connection_can_sync_map_properties( - context, live_server, websocket_server, tilelayer + new_page, live_server, websocket_server, tilelayer ): map = MapFactory(name="sync", edit_status=Map.ANONYMOUS) map.settings["properties"]["syncEnabled"] = True @@ -169,9 +169,9 @@ def test_websocket_connection_can_sync_map_properties( DataLayerFactory(map=map, data={}) # Create two tabs - peerA = context.new_page() + peerA = new_page() peerA.goto(f"{live_server.url}{map.get_absolute_url()}?edit") - peerB = context.new_page() + peerB = new_page() peerB.goto(f"{live_server.url}{map.get_absolute_url()}?edit") # Name change is synced