From 9c89c50560f2b022b248f4cd68a76e0cfdc4bb7d Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Tue, 19 Sep 2023 19:04:00 -0400 Subject: [PATCH 1/8] Set a default property for features that the owner is the current user. https://github.com/umap-project/umap/issues/430 --- umap/static/umap/js/umap.controls.js | 11 +++++++---- umap/static/umap/js/umap.features.js | 5 +++-- umap/static/umap/js/umap.forms.js | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 696e7c3f..c77746a8 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -1553,16 +1553,19 @@ L.U.Editable = L.Editable.extend({ }, createPolyline: function (latlngs) { - return new L.U.Polyline(this.map, latlngs) + return new L.U.Polyline(this.map, latlngs, this._getDefaultProperties()) }, createPolygon: function (latlngs) { - const polygon = new L.U.Polygon(this.map, latlngs) - return polygon + return new L.U.Polygon(this.map, latlngs, this._getDefaultProperties()) }, createMarker: function (latlng) { - return new L.U.Marker(this.map, latlng) + return new L.U.Marker(this.map, latlng, this._getDefaultProperties()) + }, + + _getDefaultProperties: function() { + return { geojson: { properties: { owner: this.map.options.user.id } } } }, connectCreatedToMap: function (layer) { diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 997218ff..77e7e648 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -105,14 +105,15 @@ L.U.FeatureMixin = { let property for (let i = 0; i < this.datalayer._propertiesIndex.length; i++) { property = this.datalayer._propertiesIndex[i] - if (L.Util.indexOf(['name', 'description'], property) !== -1) { + if (L.Util.indexOf(['name', 'description', 'owner'], property) !== -1) { continue } properties.push([`properties.${property}`, { label: property }]) } - // We always want name and description for now (properties management to come) + // We always want name, description, owner for now (properties management to come) properties.unshift('properties.description') properties.unshift('properties.name') + properties.unshift('properties.owner') builder = new L.U.FormBuilder(this, properties, { id: 'umap-feature-properties', callback: this._redraw, // In case we have dynamic options… diff --git a/umap/static/umap/js/umap.forms.js b/umap/static/umap/js/umap.forms.js index 587549a5..085f0518 100644 --- a/umap/static/umap/js/umap.forms.js +++ b/umap/static/umap/js/umap.forms.js @@ -939,6 +939,10 @@ L.U.FormBuilder = L.FormBuilder.extend({ defaultOptions: { name: { label: L._('name') }, + owner: { + label: 'owner', +// handler: 'BlurInput', // this field should be hidden, not sure if blur does it. + }, description: { label: L._('description'), handler: 'Textarea', From e2b789e5751800f5af7fb011be741e79995e9df1 Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Wed, 20 Sep 2023 10:51:01 -0400 Subject: [PATCH 2/8] Do not use the form for the owner property. Only add the owner property to defaultProperties, if there is a user. In other words the user can use the map without logging in. --- umap/static/umap/js/umap.controls.js | 6 +++++- umap/static/umap/js/umap.features.js | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index c77746a8..b0c01c2a 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -1565,7 +1565,11 @@ L.U.Editable = L.Editable.extend({ }, _getDefaultProperties: function() { - return { geojson: { properties: { owner: this.map.options.user.id } } } + const result = {} + if (this.map.options.hasOwnProperty('user')) { + result.geojson = { properties: { owner: this.map.options.user.id } } + } + return result }, connectCreatedToMap: function (layer) { diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 77e7e648..997218ff 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -105,15 +105,14 @@ L.U.FeatureMixin = { let property for (let i = 0; i < this.datalayer._propertiesIndex.length; i++) { property = this.datalayer._propertiesIndex[i] - if (L.Util.indexOf(['name', 'description', 'owner'], property) !== -1) { + if (L.Util.indexOf(['name', 'description'], property) !== -1) { continue } properties.push([`properties.${property}`, { label: property }]) } - // We always want name, description, owner for now (properties management to come) + // We always want name and description for now (properties management to come) properties.unshift('properties.description') properties.unshift('properties.name') - properties.unshift('properties.owner') builder = new L.U.FormBuilder(this, properties, { id: 'umap-feature-properties', callback: this._redraw, // In case we have dynamic options… From 35e37c2d4bea2f557f9c74d49d74fc7d40b6a6ab Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Wed, 20 Sep 2023 10:52:13 -0400 Subject: [PATCH 3/8] Add translation for "owner". --- umap/static/umap/js/umap.forms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/umap/static/umap/js/umap.forms.js b/umap/static/umap/js/umap.forms.js index 085f0518..e151f9d9 100644 --- a/umap/static/umap/js/umap.forms.js +++ b/umap/static/umap/js/umap.forms.js @@ -940,7 +940,7 @@ L.U.FormBuilder = L.FormBuilder.extend({ defaultOptions: { name: { label: L._('name') }, owner: { - label: 'owner', + label: L._('owner'), // handler: 'BlurInput', // this field should be hidden, not sure if blur does it. }, description: { From e76c147b65139f6a280f0b3902a5dd448f9ec910 Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Wed, 20 Sep 2023 10:53:27 -0400 Subject: [PATCH 4/8] owner is no longer a form field. --- umap/static/umap/js/umap.forms.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/umap/static/umap/js/umap.forms.js b/umap/static/umap/js/umap.forms.js index e151f9d9..587549a5 100644 --- a/umap/static/umap/js/umap.forms.js +++ b/umap/static/umap/js/umap.forms.js @@ -939,10 +939,6 @@ L.U.FormBuilder = L.FormBuilder.extend({ defaultOptions: { name: { label: L._('name') }, - owner: { - label: L._('owner'), -// handler: 'BlurInput', // this field should be hidden, not sure if blur does it. - }, description: { label: L._('description'), handler: 'Textarea', From e25fb5d04f54fca6f2cfd35eee8eb437c8f0e504 Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Wed, 20 Sep 2023 12:48:32 -0400 Subject: [PATCH 5/8] Add FeaturesHaveOwners map option. WIP --- umap/settings/base.py | 1 + umap/static/umap/js/umap.js | 8 ++++++++ umap/views.py | 1 + 3 files changed, 10 insertions(+) diff --git a/umap/settings/base.py b/umap/settings/base.py index 6c1a84d7..86b50fe1 100644 --- a/umap/settings/base.py +++ b/umap/settings/base.py @@ -249,6 +249,7 @@ DATABASES = { } UMAP_DEFAULT_SHARE_STATUS = None UMAP_DEFAULT_EDIT_STATUS = None +UMAP_DEFAULT_FEATURES_HAVE_OWNERS = True UMAP_READONLY = env('UMAP_READONLY', default=False) UMAP_GZIP = True diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 27414e33..18641b9f 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -108,6 +108,7 @@ L.U.Map.include({ L.Util.setBooleanFromQueryString(this.options, 'displayCaptionOnLoad') L.Util.setBooleanFromQueryString(this.options, 'captionBar') L.Util.setBooleanFromQueryString(this.options, 'captionMenus') + L.Util.setBooleanFromQueryString(this.options, 'featuresHaveOwners') for (let i = 0; i < this.HIDDABLE_CONTROLS.length; i++) { L.Util.setNullableBooleanFromQueryString( this.options, @@ -1112,6 +1113,7 @@ L.U.Map.include({ 'filterKey', 'facetKey', 'slugKey', + 'featuresHaveOwners', 'showLabel', 'labelDirection', 'labelInteractive', @@ -1457,6 +1459,12 @@ L.U.Map.include({ label: L._('Feature identifier key'), }, ], + [ + 'options.featuesHaveOwners', + { + handler: 'Switch', label: L._('Features have owners') + }, + ], ] builder = new L.U.FormBuilder(this, optionsFields, { diff --git a/umap/views.py b/umap/views.py index f33296d9..58c02797 100644 --- a/umap/views.py +++ b/umap/views.py @@ -509,6 +509,7 @@ class MapDetailMixin: "properties": { "zoom": getattr(settings, "LEAFLET_ZOOM", 6), "datalayers": [], + "features_have_owners": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS, }, } From 6c58bf367d53eea19e366912ef02e0ed74054886 Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Wed, 20 Sep 2023 13:03:36 -0400 Subject: [PATCH 6/8] Use camelcase and fix typo. --- umap/static/umap/js/umap.js | 2 +- umap/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 18641b9f..6c06414f 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -1460,7 +1460,7 @@ L.U.Map.include({ }, ], [ - 'options.featuesHaveOwners', + 'options.featuresHaveOwners', { handler: 'Switch', label: L._('Features have owners') }, diff --git a/umap/views.py b/umap/views.py index 58c02797..ad819e5a 100644 --- a/umap/views.py +++ b/umap/views.py @@ -509,7 +509,7 @@ class MapDetailMixin: "properties": { "zoom": getattr(settings, "LEAFLET_ZOOM", 6), "datalayers": [], - "features_have_owners": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS, + "featuresHaveOwners": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS, }, } From 77b56623ed383363577e2b224723f432a79cf3b1 Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Wed, 20 Sep 2023 13:07:12 -0400 Subject: [PATCH 7/8] Remove field from map settings form. --- umap/static/umap/js/umap.js | 7 ------- umap/views.py | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 6c06414f..4ba5fe14 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -1113,7 +1113,6 @@ L.U.Map.include({ 'filterKey', 'facetKey', 'slugKey', - 'featuresHaveOwners', 'showLabel', 'labelDirection', 'labelInteractive', @@ -1459,12 +1458,6 @@ L.U.Map.include({ label: L._('Feature identifier key'), }, ], - [ - 'options.featuresHaveOwners', - { - handler: 'Switch', label: L._('Features have owners') - }, - ], ] builder = new L.U.FormBuilder(this, optionsFields, { diff --git a/umap/views.py b/umap/views.py index ad819e5a..31f86717 100644 --- a/umap/views.py +++ b/umap/views.py @@ -460,6 +460,7 @@ class MapDetailMixin: (i, str(label)) for i, label in AnonymousMapPermissionsForm.STATUS ], "umap_version": VERSION, + "featuresHaveOwners": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS, } if self.get_short_url(): properties["shortUrl"] = self.get_short_url() @@ -509,7 +510,6 @@ class MapDetailMixin: "properties": { "zoom": getattr(settings, "LEAFLET_ZOOM", 6), "datalayers": [], - "featuresHaveOwners": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS, }, } From 6720f76d85b45d36abdb0799af85b0999ef63da0 Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Wed, 20 Sep 2023 13:16:52 -0400 Subject: [PATCH 8/8] Set the map option. No need for setting boolean from query string. Only add the owner property if the feature flag (map.options.featuresHaveOwner) is enabled. Default to features do NOT have owners. --- umap/settings/base.py | 2 +- umap/static/umap/js/umap.controls.js | 2 +- umap/static/umap/js/umap.js | 2 +- umap/views.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/umap/settings/base.py b/umap/settings/base.py index 86b50fe1..b532fe43 100644 --- a/umap/settings/base.py +++ b/umap/settings/base.py @@ -249,7 +249,7 @@ DATABASES = { } UMAP_DEFAULT_SHARE_STATUS = None UMAP_DEFAULT_EDIT_STATUS = None -UMAP_DEFAULT_FEATURES_HAVE_OWNERS = True +UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False UMAP_READONLY = env('UMAP_READONLY', default=False) UMAP_GZIP = True diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index b0c01c2a..820252bf 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -1566,7 +1566,7 @@ L.U.Editable = L.Editable.extend({ _getDefaultProperties: function() { const result = {} - if (this.map.options.hasOwnProperty('user')) { + if (this.map.options.featuresHaveOwner && this.map.options.hasOwnProperty('user')) { result.geojson = { properties: { owner: this.map.options.user.id } } } return result diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 4ba5fe14..325e071c 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -46,6 +46,7 @@ L.Map.mergeOptions({ easing: false, permissions: {}, permanentCreditBackground: true, + featuresHaveOwner: false, }) L.U.Map.include({ @@ -108,7 +109,6 @@ L.U.Map.include({ L.Util.setBooleanFromQueryString(this.options, 'displayCaptionOnLoad') L.Util.setBooleanFromQueryString(this.options, 'captionBar') L.Util.setBooleanFromQueryString(this.options, 'captionMenus') - L.Util.setBooleanFromQueryString(this.options, 'featuresHaveOwners') for (let i = 0; i < this.HIDDABLE_CONTROLS.length; i++) { L.Util.setNullableBooleanFromQueryString( this.options, diff --git a/umap/views.py b/umap/views.py index 31f86717..9a142f4c 100644 --- a/umap/views.py +++ b/umap/views.py @@ -460,7 +460,7 @@ class MapDetailMixin: (i, str(label)) for i, label in AnonymousMapPermissionsForm.STATUS ], "umap_version": VERSION, - "featuresHaveOwners": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS, + "featuresHaveOwner": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS, } if self.get_short_url(): properties["shortUrl"] = self.get_short_url()