From 9c89c50560f2b022b248f4cd68a76e0cfdc4bb7d Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Tue, 19 Sep 2023 19:04:00 -0400 Subject: [PATCH] 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',