Skip to content

Commit 7448ca3

Browse files
committed
Keep other tags when setting temporary geometry tag (except tag from same group if group is of type "choice")
1 parent 18ccdd2 commit 7448ca3

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/server/sendDataToGeoserver.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ process.stdin.on('data', d => {
1616

1717
process.stdin.on('end', async () => {
1818
const data = JSON.parse(input);
19+
const tagGroups = await getTagGroups();
1920
const changedObjects = [];
2021

2122
for (let object of data.objects) {
2223
await updateObject(
2324
getObjectData(object),
2425
object._current ? getObjectData(object._current) : undefined
2526
);
26-
if (await handleNewlyDrawnGeometries(object)) changedObjects.push(object);
27+
if (await handleNewlyDrawnGeometries(object, tagGroups)) changedObjects.push(object);
2728
}
2829

2930
console.log(JSON.stringify({ objects: changedObjects }));
@@ -435,7 +436,7 @@ function getGeometryFilterXml(geometryId) {
435436
+ '</ogc:PropertyIsEqualTo>';
436437
}
437438

438-
async function handleNewlyDrawnGeometries(object) {
439+
async function handleNewlyDrawnGeometries(object, tagGroups) {
439440
const configuration = getPluginConfiguration();
440441
const wfsConfiguration = getWFSConfiguration(configuration, object._objecttype);
441442
if (!wfsConfiguration) return false;
@@ -454,7 +455,7 @@ async function handleNewlyDrawnGeometries(object) {
454455
if (wfsTemporaryGeometryFieldName) {
455456
await markGeometriesAsTemporary(newlyDrawnGeometryIds, fieldConfiguration, wfsTemporaryGeometryFieldName);
456457
}
457-
if (temporaryGeometryTagId) object._tags = [{ _id: temporaryGeometryTagId }];
458+
if (temporaryGeometryTagId) setTag(object, temporaryGeometryTagId, tagGroups);
458459
}
459460
}
460461

@@ -473,6 +474,26 @@ function getAuthorizationString(configuration) {
473474
return btoa(username + ':' + password);
474475
}
475476

477+
function setTag(object, tagId, tagGroups) {
478+
const tagGroup = tagGroups.find(group => group._tags.find(entry => entry.tag._id === tagId));
479+
const tagsIdsToRemove = tagGroup.taggroup.type === 'choice'
480+
? tagGroup._tags.map(entry => entry.tag._id)
481+
: [tagId];
482+
object._tags = object._tags.filter(tag => !tagsIdsToRemove.includes(tag._id))
483+
.concat([{ _id: tagId }]);
484+
}
485+
486+
async function getTagGroups() {
487+
const url = info.api_url + '/api/v1/tags?access_token=' + info.api_user_access_token;
488+
489+
try {
490+
const response = await fetch(url, { method: 'GET' });
491+
return await response.json();
492+
} catch (err) {
493+
throwErrorToFrontend('Die Abfrage der konfigurierten Tags ist fehlgeschlagen.', JSON.stringify(err));
494+
}
495+
}
496+
476497
function throwErrorToFrontend(error, description, realm) {
477498
console.log(JSON.stringify({
478499
error: {

0 commit comments

Comments
 (0)