Skip to content

Commit 5d0b651

Browse files
committed
Replace "Remove link" button with "Delete geometry" button
1 parent fafc5b7 commit 5d0b651

5 files changed

Lines changed: 129 additions & 66 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ make
3737
* *Style object UUID*: The UUID of the style object to be used for this geometry field
3838
* *WFS URL for map display*: The base URL of the WFS to be used for displaying data on the map provided by the plugin. It has to be a WFS provided by the configured Geoserver instance. No data is changed via this WFS.
3939
* *WFS feature type for map display*: The feature type to use when displaying data on the map
40+
* *WFS URL for editing data*: The base URL of the WFS to be used for editing and deleting geometries. It has to be a WFS-T provided by the configured Geoserver instance.
41+
* *WFS feature type for editing data*: The feature type to use when editing or deleting geometries via WFS
4042
* *Masterportal: Raster layer ID*: The ID of a raster layer that should be displayed in addition to the vector data in Masterportal.
4143
* *Masterportal: Vector layer ID (Default)*: The ID of the default layer used for displaying WFS data in Masterportal. This layer is used if no other layers are configured or if no geometries have been added yet to a geometry field.
4244
* *Masterportal: Name of WFS field for assigning Masterportal vector layer ID*: The value of this field is used for selecting Masterportal layers based on WFS data (see next setting)
4345
* *Masterportal: Vector layer IDs (based on WFS field value)*:
4446
* *Field value*: If this value is found in the configured WFS field, the corresponding layer is shown in Masterportal
4547
* *Layer ID*: The ID of the layer to show in Masterportal
4648
* *Data transfer to geoserver*: If activated, field data is transferred from the fylr object to the Geoserver (via the configured WFS).
47-
* *WFS URL for data transfer*: The base URL of the WFS to be used for transferring data to the Geoserver. It has to be a WFS-T provided by the configured Geoserver instance.
48-
* *WFS feature type for data transfer*: The feature type to use when writing data to the WFS
4949
* *Field data to be transferred*: Mappings of a source field (fylr) to a target field (WFS). For each geometry field defined, entered field data is added to the corresponding geometry via a WFS provided by the configured Geoserver instance
5050
* *Name of WFS target field*: The target field of the WFS to which the data is transferred
5151
* *Name of field in fylr object*: The source field that contains the data to be transferred

l10n/custom-data-type-nfis-geometry.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ custom.data.type.nfis.geometry.search.badge.without,Ohne,Without
88
custom.data.type.nfis.geometry.createNewGeometry,Neue Geometrie anlegen,Create new geometry
99
custom.data.type.nfis.geometry.linkExistingGeometry,Existierende Geometrie verknüpfen,Link existing geometry
1010
custom.data.type.nfis.geometry.editGeometry,Bearbeiten,Edit
11-
custom.data.type.nfis.geometry.removeGeometry,Verknüpfung entfernen,Remove link
11+
custom.data.type.nfis.geometry.deleteGeometry,Geometrie löschen,Delete geometry
1212
custom.data.type.nfis.geometry.viewGeometry,Im Masterportal anzeigen,View in Masterportal
1313
custom.data.type.nfis.geometry.modal.cancel,Abbrechen,cancel
1414
custom.data.type.nfis.geometry.modal.ok,Ok,Ok
@@ -34,6 +34,8 @@ server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields
3434
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.field_path.label,Feldname (inkl. Pfad),Field name (including path)
3535
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.display_wfs_url.label,WFS-URL für Kartendarstellung,WFS URL for map display
3636
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.display_wfs_feature_type.label,WFS-Feature-Type für Kartendarstellung,WFS feature type for map display
37+
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.edit_wfs_url.label,WFS-URL für Bearbeitung,WFS URL for editing data
38+
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.edit_wfs_feature_type.label,WFS-Feature-Type für Bearbeitung,WFS feature type for editing data
3739
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.masterportal_raster_layer_id.label,Masterportal: Raster-Layer-ID,Masterportal: Raster layer ID
3840
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.masterportal_default_vector_layer_id.label,Masterportal: Vektor-Layer-ID (Standard),Masterportal: Vector layer ID (default)
3941
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.masterportal_vector_layer_field_name.label,Masterportal: Name des WFS-Feldes für Zuordnung der Masterportal-Vektor-Layer-ID,Masterportal: Name of WFS field for assigning Masterportal vector layer ID
@@ -42,8 +44,6 @@ server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields
4244
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.masterportal_vector_layer_ids.layer_id.label,Layer-ID,Layer ID
4345
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.send_data_to_geoserver.label,Datenübertragung an Geoserver,Data transfer to geoserver
4446
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.send_data_to_geoserver.checkbox,Aktivieren,Activate
45-
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.edit_wfs_url.label,WFS-URL für Datenübertragung,WFS URL for data transfer
46-
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.edit_wfs_feature_type.label,WFS-Feature-Type für Datenübertragung,WFS feature type for data transfer
4747
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.style_uuid.label,UUID des Style-Objekts,Style object UUID
4848
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.fields.label,Zu übertragende Felddaten,Field data to be transferred
4949
server.config.parameter.system.nfisGeoservices.wfs_configuration.geometry_fields.fields.wfs_field_name.label,Name des WFS-Zielfeldes,Name of WFS target field

manifest.master.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,21 @@ base_config:
6666
- name: display_wfs_feature_type
6767
type: text
6868
position: 3
69-
- name: masterportal_raster_layer_id
69+
- name: edit_wfs_url
7070
type: text
7171
position: 4
72-
- name: masterportal_default_vector_layer_id
72+
- name: edit_wfs_feature_type
7373
type: text
7474
position: 5
75-
- name: masterportal_vector_layer_field_name
75+
- name: masterportal_raster_layer_id
7676
type: text
7777
position: 6
78+
- name: masterportal_default_vector_layer_id
79+
type: text
80+
position: 7
81+
- name: masterportal_vector_layer_field_name
82+
type: text
83+
position: 8
7884
- name: masterportal_vector_layer_ids
7985
type: table
8086
fields:
@@ -84,15 +90,9 @@ base_config:
8490
- name: layer_id
8591
type: text
8692
position: 1
87-
position: 7
93+
position: 9
8894
- name: send_data_to_geoserver
8995
type: bool
90-
position: 8
91-
- name: edit_wfs_url
92-
type: text
93-
position: 9
94-
- name: edit_wfs_feature_type
95-
type: text
9696
position: 10
9797
- name: fields
9898
type: table

src/server/sendDataToGeoserver.js

Lines changed: 108 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ process.stdin.on('end', async () => {
2424
object[object._objecttype],
2525
object._objecttype,
2626
object._uuid,
27+
await getCurrentObjectData(object[object._objecttype], object._objecttype, object._mask),
2728
configuration,
2829
authorizationString
2930
);
@@ -70,7 +71,25 @@ function getAuthorizationString(serverConfiguration) {
7071
return btoa(username + ':' + password);
7172
}
7273

73-
async function updateObject(object, objectType, uuid, configuration, authorizationString) {
74+
async function getCurrentObjectData(object, objectType, mask) {
75+
const url = info.api_url + '/api/v1/db/' + objectType + '/' + mask + '/' + object._id
76+
+ '?access_token=' + info.api_user_access_token;
77+
78+
try {
79+
const response = await fetch(url, {
80+
method: 'GET',
81+
headers: {
82+
'Content-Type': 'application/json'
83+
}
84+
});
85+
const result = await response.json();
86+
return result.length ? result[0][objectType] : undefined;
87+
} catch (err) {
88+
throwErrorToFrontend('Retrieving current object data failed', JSON.stringify(err));
89+
}
90+
}
91+
92+
async function updateObject(object, objectType, uuid, currentObject, configuration, authorizationString) {
7493
const wfsConfiguration = getWFSConfiguration(configuration, objectType);
7594
if (!wfsConfiguration) return;
7695

@@ -80,26 +99,11 @@ async function updateObject(object, objectType, uuid, configuration, authorizati
8099
return throwErrorToFrontend('Eine oder mehrere Geometrien sind bereits mit anderen Objekten verknüpft.', undefined, 'multipleGeometryLinking');
81100
}
82101

83-
const poolName = getPoolName(object, fieldConfiguration);
84-
if (isSendingDataToGeoserverActivated(fieldConfiguration, geometryIds, poolName)) {
85-
const changeMap = getChangeMap(object, fieldConfiguration, poolName);
86-
if (Object.keys(changeMap).length) {
87-
await performTransaction(
88-
geometryIds, changeMap, fieldConfiguration.edit_wfs_url.ValueText,
89-
fieldConfiguration.edit_wfs_feature_type.ValueText, authorizationString
90-
);
91-
}
92-
}
102+
await editGeometries(object, fieldConfiguration, geometryIds, authorizationString);
103+
await deleteGeometries(fieldConfiguration, geometryIds, currentObject, authorizationString);
93104
}
94105
}
95106

96-
function isSendingDataToGeoserverActivated(fieldConfiguration, geometryIds, poolName) {
97-
return fieldConfiguration.send_data_to_geoserver?.ValueBool
98-
&& fieldConfiguration.edit_wfs_url?.ValueText
99-
&& geometryIds?.length
100-
&& poolName !== undefined;
101-
}
102-
103107
function getGeometryIds(object, pathSegments) {
104108
let geometryIds = [];
105109

@@ -156,23 +160,34 @@ function getGeometryFieldPaths(configuration) {
156160
return fieldPaths;
157161
}
158162

159-
function getFieldValues(object, pathSegments) {
160-
const fieldName = pathSegments.shift();
161-
const field = object[fieldName];
162-
163-
if (field === undefined) {
164-
return [];
165-
} else if (pathSegments.length === 0) {
166-
return [field];
167-
} else if (Array.isArray(field)) {
168-
return field.map(entry => getFieldValues(entry, pathSegments.slice()))
169-
.filter(data => data !== undefined)
170-
.reduce((result, fieldValues) => result.concat(fieldValues), []);
171-
} else {
172-
return getFieldValues(field, pathSegments);
163+
async function editGeometries(object, fieldConfiguration, geometryIds, authorizationString) {
164+
const poolName = getPoolName(object, fieldConfiguration);
165+
if (isSendingDataToGeoserverActivated(fieldConfiguration, geometryIds, poolName)) {
166+
const changeMap = getChangeMap(object, fieldConfiguration, poolName);
167+
if (Object.keys(changeMap).length) {
168+
await performEditTransaction(geometryIds, changeMap, fieldConfiguration, authorizationString);
169+
}
173170
}
174171
}
175172

173+
async function deleteGeometries(fieldConfiguration, geometryIds, currentObject, authorizationString) {
174+
if (!currentObject) return;
175+
const deletedGeometryIds = getDeletedGeometryIds(geometryIds, currentObject, fieldConfiguration);
176+
if (deletedGeometryIds.length) await performDeleteTransaction(deletedGeometryIds, fieldConfiguration, authorizationString);
177+
}
178+
179+
function getDeletedGeometryIds(geometryIds, currentObject, fieldConfiguration) {
180+
const currentGeometryIds = getGeometryIds(currentObject, fieldConfiguration.field_path.ValueText.split('.'));
181+
return currentGeometryIds.filter(geometryId => !geometryIds.includes(geometryId));
182+
}
183+
184+
function isSendingDataToGeoserverActivated(fieldConfiguration, geometryIds, poolName) {
185+
return fieldConfiguration.send_data_to_geoserver?.ValueBool
186+
&& fieldConfiguration.edit_wfs_url?.ValueText
187+
&& geometryIds?.length
188+
&& poolName !== undefined;
189+
}
190+
176191
function getPoolName(object, fieldConfiguration) {
177192
if (!object._pool) return undefined;
178193

@@ -210,6 +225,23 @@ function getChangeMap(object, fieldConfiguration, poolName) {
210225
}, changeMap);
211226
}
212227

228+
function getFieldValues(object, pathSegments) {
229+
const fieldName = pathSegments.shift();
230+
const field = object[fieldName];
231+
232+
if (field === undefined) {
233+
return [];
234+
} else if (pathSegments.length === 0) {
235+
return [field];
236+
} else if (Array.isArray(field)) {
237+
return field.map(entry => getFieldValues(entry, pathSegments.slice()))
238+
.filter(data => data !== undefined)
239+
.reduce((result, fieldValues) => result.concat(fieldValues), []);
240+
} else {
241+
return getFieldValues(field, pathSegments);
242+
}
243+
}
244+
213245
function getValueFromCustomFunction(object, functionDefinition) {
214246
const customFunction = new Function('object', functionDefinition);
215247
return customFunction(object);
@@ -239,8 +271,25 @@ function isDanteConcept(fieldValue) {
239271
&& fieldValue.conceptURI !== undefined;
240272
}
241273

242-
async function performTransaction(geometryIds, changeMap, wfsUrl, wfsFeatureType, authorizationString) {
243-
const requestXml = getRequestXml(geometryIds, changeMap, wfsFeatureType);
274+
async function performEditTransaction(geometryIds, changeMap, fieldConfiguration, authorizationString) {
275+
await performTransaction(
276+
geometryIds,
277+
getEditRequestXml(geometryIds, changeMap, fieldConfiguration.edit_wfs_feature_type.ValueText),
278+
fieldConfiguration.edit_wfs_url.ValueText,
279+
authorizationString
280+
);
281+
}
282+
283+
async function performDeleteTransaction(geometryIds, fieldConfiguration, authorizationString) {
284+
await performTransaction(
285+
geometryIds,
286+
getDeleteRequestXml(geometryIds, fieldConfiguration.edit_wfs_feature_type.ValueText),
287+
fieldConfiguration.edit_wfs_url.ValueText,
288+
authorizationString
289+
);
290+
}
291+
292+
async function performTransaction(geometryIds, requestXml, wfsUrl, authorizationString) {
244293
const transactionUrl = wfsUrl + '?service=WFS&version=1.1.0&request=Transaction';
245294

246295
try {
@@ -261,20 +310,34 @@ async function performTransaction(geometryIds, changeMap, wfsUrl, wfsFeatureType
261310
}
262311
}
263312

264-
function getRequestXml(geometryIds, changeMap, featureType) {
265-
return '<?xml version="1.0" ?>'
266-
+ '<wfs:Transaction '
267-
+ 'version="1.1.0" '
268-
+ 'service="WFS" '
269-
+ 'xmlns:ogc="http://www.opengis.net/ogc" '
270-
+ 'xmlns:wfs="http://www.opengis.net/wfs" '
271-
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
272-
+ 'xsi:schemaLocation="http://www.opengis.net/wfs">'
273-
+ '<wfs:Update typeName="' + featureType + '">'
313+
function getEditRequestXml(geometryIds, changeMap, featureType) {
314+
return getTransactionXml(
315+
'<wfs:Update typeName="' + featureType + '">'
274316
+ getPropertiesXml(changeMap)
275317
+ getFilterXml(geometryIds)
276318
+ '</wfs:Update>'
277-
+ '</wfs:Transaction>';
319+
);
320+
}
321+
322+
function getDeleteRequestXml(geometryIds, featureType) {
323+
return getTransactionXml(
324+
'<wfs:Delete typeName="' + featureType + '">'
325+
+ getFilterXml(geometryIds)
326+
+ '</wfs:Delete>'
327+
);
328+
}
329+
330+
function getTransactionXml(actionXml) {
331+
return '<?xml version="1.0" ?>'
332+
+ '<wfs:Transaction '
333+
+ 'version="1.1.0" '
334+
+ 'service="WFS" '
335+
+ 'xmlns:ogc="http://www.opengis.net/ogc" '
336+
+ 'xmlns:wfs="http://www.opengis.net/wfs" '
337+
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
338+
+ 'xsi:schemaLocation="http://www.opengis.net/wfs">'
339+
+ actionXml
340+
+ '</wfs:Transaction>';
278341
}
279342

280343
function getPropertiesXml(changeMap) {
@@ -302,7 +365,6 @@ function getGeometryFilterXml(geometryId) {
302365
+ '</ogc:PropertyIsEqualTo>';
303366
}
304367

305-
306368
function throwErrorToFrontend(error, description, realm) {
307369
console.log(JSON.stringify({
308370
error: {

src/webfrontend/js/contentLoader.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function renderEditorButtons(contentElement, cdata, settings, wfsData, selectedG
146146
}
147147
} else {
148148
buttons.push(createEditGeometryButton(contentElement, cdata, settings, wfsData, selectedGeometryId));
149-
buttons.push(createRemoveGeometryButton(contentElement, cdata, settings, selectedGeometryId));
149+
buttons.push(createDeleteGeometryButton(contentElement, cdata, settings, selectedGeometryId));
150150
}
151151

152152
const buttonBarElement = new CUI.Buttonbar({ buttons: buttons });
@@ -180,11 +180,11 @@ function createEditGeometryButton(contentElement, cdata, settings, wfsData, uuid
180180
});
181181
}
182182

183-
function createRemoveGeometryButton(contentElement, cdata, settings, uuid) {
183+
function createDeleteGeometryButton(contentElement, cdata, settings, uuid) {
184184
return new CUI.Button({
185-
text: $$('custom.data.type.nfis.geometry.removeGeometry'),
185+
text: $$('custom.data.type.nfis.geometry.deleteGeometry'),
186186
icon_left: new CUI.Icon({ class: 'fa-trash' }),
187-
onClick: () => removeGeometryId(contentElement, cdata, settings, uuid)
187+
onClick: () => deleteGeometry(contentElement, cdata, settings, uuid)
188188
});
189189
}
190190

@@ -311,8 +311,9 @@ function setGeometryId(contentElement, cdata, settings, newGeometryId) {
311311
});
312312
}
313313

314-
function removeGeometryId(contentElement, cdata, settings, uuid) {
314+
function deleteGeometry(contentElement, cdata, settings, uuid) {
315315
cdata.geometry_ids = cdata.geometry_ids.filter(geometryId => geometryId !== uuid);
316+
notifyEditor(contentElement);
316317
reloadEditorContent(contentElement, cdata, settings);
317318
}
318319

0 commit comments

Comments
 (0)