From dcf57487522f5f3402d2986a72890a028193a1ff Mon Sep 17 00:00:00 2001
From: Igor Dimov <90094775+Igi-ID@users.noreply.github.com>
Date: Thu, 8 Feb 2024 14:18:06 +0100
Subject: [PATCH 1/2] Tweaked generateMetadata and putResourceMetadata calls in
GeoStoreDAO.js Added unadvertised field in Metadata.jsx, shown in modal form.
Checkbox, controlled. Adjust handleResourceData.jsx enhancer, include
unadvertised field from resource originalData unto props passed to
Metadata.jsx.
Added translations for unadvertised field.
---
web/client/api/GeoStoreDAO.js | 15 ++++++++-------
web/client/api/__tests__/GeoStoreDAO-test.jsx | 14 ++++++++------
.../components/resources/forms/Metadata.jsx | 17 ++++++++++++++---
.../resources/forms/__tests__/Metadata-test.jsx | 16 ++++++++++------
.../modals/enhancers/handleResourceData.jsx | 8 +++++---
.../resources/modals/fragments/MainForm.jsx | 1 +
web/client/translations/data.da-DK.json | 3 ++-
web/client/translations/data.de-DE.json | 3 ++-
web/client/translations/data.en-US.json | 3 ++-
web/client/translations/data.es-ES.json | 3 ++-
web/client/translations/data.fi-FI.json | 3 ++-
web/client/translations/data.fr-FR.json | 3 ++-
web/client/translations/data.hr-HR.json | 3 ++-
web/client/translations/data.is-IS.json | 3 ++-
web/client/translations/data.it-IT.json | 3 ++-
web/client/translations/data.nl-NL.json | 3 ++-
web/client/translations/data.pt-PT.json | 3 ++-
web/client/translations/data.sk-SK.json | 3 ++-
web/client/translations/data.sv-SE.json | 3 ++-
19 files changed, 72 insertions(+), 38 deletions(-)
diff --git a/web/client/api/GeoStoreDAO.js b/web/client/api/GeoStoreDAO.js
index 9b227fcf86..c7af5fa39a 100644
--- a/web/client/api/GeoStoreDAO.js
+++ b/web/client/api/GeoStoreDAO.js
@@ -18,12 +18,13 @@ import { registerErrorParser } from '../utils/LocaleUtils';
import { encodeUTF8 } from '../utils/EncodeUtils';
-const generateMetadata = (name = "", description = "") =>
+const generateMetadata = (name = "", description = "", advertised = true) =>
""
+ ""
- + "";
+ + ""
+ + "" + advertised + "";
const createAttributeList = (metadata = {}) => {
- const attributes = metadata.attributes || omit(metadata, ["name", "description", "id"]);
+ const attributes = metadata.attributes || omit(metadata, ["name", "description", "id", "advertised"]);
const xmlAttrs = Object.keys(attributes).map((key) => {
return "" + key + "" + attributes[key] + "STRING";
@@ -266,10 +267,10 @@ const Api = {
.then(rl => castArray( withSelector ? get(rl, 'SecurityRuleList.SecurityRule') : rl))
.then(rules => (rules && rules[0] && rules[0] !== "") ? rules : []);
},
- putResourceMetadata: function(resourceId, newName, newDescription, options) {
+ putResourceMetadata: function(resourceId, newName, newDescription, advertised, options) {
return axios.put(
"resources/resource/" + resourceId,
- "" + generateMetadata(newName, newDescription) + "",
+ "" + generateMetadata(newName, newDescription, advertised) + "",
this.addBaseUrl(merge({
headers: {
'Content-Type': "application/xml"
@@ -279,7 +280,7 @@ const Api = {
putResourceMetadataAndAttributes: function(resourceId, metadata, options) {
return axios.put(
"resources/resource/" + resourceId,
- "" + generateMetadata(metadata.name, metadata.description) + createAttributeList(metadata) + "",
+ "" + generateMetadata(metadata.name, metadata.description, metadata.advertised) + createAttributeList(metadata) + "",
this.addBaseUrl(merge({
headers: {
'Content-Type': "application/xml"
@@ -337,7 +338,7 @@ const Api = {
const attributesSection = createAttributeList(metadata);
return axios.post(
"resources/",
- "" + generateMetadata(name, description) + "" + (category || "") + "" +
+ "" + generateMetadata(name, description, metadata.advertised) + "" + (category || "") + "" +
attributesSection +
" {
expect(payload).toBe(SAMPLE_XML_RULES);
});
it('test generate meatadata', () => {
- const payload = API.generateMetadata("Special & chars", "&<>'\"");
- expect(payload).toBe('\'"]]>');
+ const payload = API.generateMetadata("Special & chars", "&<>'\"", false);
+ expect(payload).toBe('\'"]]>false');
});
it('test login without credentials', (done) => {
@@ -176,13 +176,15 @@ describe('Test correctness of the GeoStore APIs', () => {
const metadata = API.generateMetadata();
const name = "";
const description = "";
- expect(metadata).toEqual(``);
+ const advertised = true;
+ expect(metadata).toEqual(`${advertised}`);
});
- it("test generateMetadata with name and desc", () => {
+ it("test generateMetadata with name, desc and advertised", () => {
const name = "Map 1";
const description = "this map shows high traffic zones";
- const metadata = API.generateMetadata(name, description);
- expect(metadata).toEqual(``);
+ const advertised = false;
+ const metadata = API.generateMetadata(name, description, advertised);
+ expect(metadata).toEqual(`${advertised}`);
});
it("test createAttributeList default", () => {
expect(API.createAttributeList()).toEqual("");
diff --git a/web/client/components/resources/forms/Metadata.jsx b/web/client/components/resources/forms/Metadata.jsx
index 97a2f86440..673f8d9aca 100644
--- a/web/client/components/resources/forms/Metadata.jsx
+++ b/web/client/components/resources/forms/Metadata.jsx
@@ -16,7 +16,7 @@
import moment from 'moment';
import PropTypes from 'prop-types';
import React from 'react';
-import { FormControl as BFormControl, ControlLabel, FormGroup } from 'react-bootstrap';
+import { FormControl as BFormControl, ControlLabel, FormGroup, Checkbox } from 'react-bootstrap';
import get from 'lodash/get';
import ConfigUtils from '../../../utils/ConfigUtils';
@@ -42,7 +42,8 @@ class Metadata extends React.Component {
descriptionPlaceholderText: PropTypes.string,
titlePlaceholderText: PropTypes.string,
createdAtFieldText: PropTypes.string,
- modifiedAtFieldText: PropTypes.string
+ modifiedAtFieldText: PropTypes.string,
+ unadvertisedText: PropTypes.string
};
static contextTypes = {
@@ -58,7 +59,8 @@ class Metadata extends React.Component {
descriptionFieldText: "Description",
nameFieldFilter: () => {},
namePlaceholderText: "Map Name",
- descriptionPlaceholderText: "Map Description"
+ descriptionPlaceholderText: "Map Description",
+ unadvertisedText: "Unadvertised"
};
renderDate = (date) => {
@@ -120,6 +122,12 @@ class Metadata extends React.Component {
{this.props.resource && this.renderDate(this.props.resource.modifiedAt || this.props.resource.createdAt) || ""}
}
+ {
+
+ {this.props.unadvertisedText}
+
+
+ }
);
}
@@ -134,6 +142,9 @@ class Metadata extends React.Component {
changeTitle = (e) => {
this.props.onChange('attributes.title', e.target.value);
};
+ changeAdvertised = (e) => {
+ this.props.onChange('metadata.advertised', !e.target.checked);
+ };
}
diff --git a/web/client/components/resources/forms/__tests__/Metadata-test.jsx b/web/client/components/resources/forms/__tests__/Metadata-test.jsx
index a1489eb2c4..8a460db2ab 100644
--- a/web/client/components/resources/forms/__tests__/Metadata-test.jsx
+++ b/web/client/components/resources/forms/__tests__/Metadata-test.jsx
@@ -26,7 +26,7 @@ describe('Metadata component', () => {
ReactDOM.render(, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelectorAll('input');
- expect(el.length).toBe(2);
+ expect(el.length).toBe(3);
});
it('Metadata rendering with meta-data', () => {
const resource = {
@@ -34,16 +34,20 @@ describe('Metadata component', () => {
createdAt: new Date(),
metadata: {
name: "NAME",
- description: "DESCRIPTION"
+ description: "DESCRIPTION",
+ advertised: true
}
};
ReactDOM.render(, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelectorAll('input');
const labels = container.querySelectorAll('label');
- expect(labels.length).toBe(6);
+ expect(labels.length).toBe(8);
expect(el[0].value).toBe("NAME");
expect(el[1].value).toBe("DESCRIPTION");
+ // the visualisation of the advertised resource attribute is represented as "Unadvertised"
+ // so, it should be always visualized as the opposite boolean of the value processed by the app.
+ expect(el[2].checked).toBe(false);
});
it('Metadata rendering with attributes', () => {
const resource = {
@@ -57,7 +61,7 @@ describe('Metadata component', () => {
const container = document.getElementById('container');
const el = container.querySelectorAll('input');
const labels = container.querySelectorAll('label');
- expect(labels.length).toBe(7);
+ expect(labels.length).toBe(9);
expect(el[1].value).toBe("TITLE");
});
it('Metadata rendering without timestamp', () => {
@@ -70,7 +74,7 @@ describe('Metadata component', () => {
ReactDOM.render(, document.getElementById("container"));
const container = document.getElementById('container');
const labels = container.querySelectorAll('label');
- expect(labels.length).toBe(2);
+ expect(labels.length).toBe(4);
});
it('Test Metadata onChange', () => {
@@ -110,7 +114,7 @@ describe('Metadata component', () => {
ReactDOM.render(, document.getElementById("container"));
const container = document.getElementById('container');
const labels = container.querySelectorAll('label');
- expect(labels.length).toBe(6);
+ expect(labels.length).toBe(8);
expect(labels[2].innerText).toBe('Created');
expect(labels[4].innerText).toBe('Modified');
});
diff --git a/web/client/components/resources/modals/enhancers/handleResourceData.jsx b/web/client/components/resources/modals/enhancers/handleResourceData.jsx
index 658b7199c2..6437773abf 100644
--- a/web/client/components/resources/modals/enhancers/handleResourceData.jsx
+++ b/web/client/components/resources/modals/enhancers/handleResourceData.jsx
@@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/
-import {isString} from 'lodash';
+import {isString, isUndefined} from 'lodash';
import React from 'react';
import { branch, compose, renderComponent, withHandlers, withState, withStateHandlers } from 'recompose';
@@ -54,10 +54,12 @@ export default compose(
},
metadata: {
name: resource.name,
- description: resource.description
+ description: resource.description,
+ advertised: isUndefined(resource.advertised) ? true : resource.advertised
},
createdAt: resource.creation,
- modifiedAt: resource.lastUpdate
+ modifiedAt: resource.lastUpdate,
+ creator: resource.creator
},
linkedResources
};
diff --git a/web/client/components/resources/modals/fragments/MainForm.jsx b/web/client/components/resources/modals/fragments/MainForm.jsx
index 6392382eee..c25d80ebda 100644
--- a/web/client/components/resources/modals/fragments/MainForm.jsx
+++ b/web/client/components/resources/modals/fragments/MainForm.jsx
@@ -75,6 +75,7 @@ class MainForm extends React.Component {
namePlaceholderText={"saveDialog.namePlaceholder"}
descriptionPlaceholderText={"saveDialog.descriptionPlaceholder"}
titlePlaceholderText={"saveDialog.titlePlaceholder"}
+ unadvertisedText={}
/>
);
diff --git a/web/client/translations/data.da-DK.json b/web/client/translations/data.da-DK.json
index 907110b610..8d4de759b5 100644
--- a/web/client/translations/data.da-DK.json
+++ b/web/client/translations/data.da-DK.json
@@ -2839,7 +2839,8 @@
"saveSuccessTitle": "Success",
"saveSuccessMessage": "Saved successfully",
"saveTooltip": "Save",
- "saveAsTooltip": "Save As"
+ "saveAsTooltip": "Save As",
+ "unadvertised": "Unadvertised"
},
"mapEditor": {
"modalTitle": "Map Editor",
diff --git a/web/client/translations/data.de-DE.json b/web/client/translations/data.de-DE.json
index 9b729673e3..2d51e9036e 100644
--- a/web/client/translations/data.de-DE.json
+++ b/web/client/translations/data.de-DE.json
@@ -3057,7 +3057,8 @@
"saveSuccessTitle": "Erfolg",
"saveSuccessMessage": "Erfolgreich gespeichert",
"saveTooltip": "Speichern",
- "saveAsTooltip": "Speichern als"
+ "saveAsTooltip": "Speichern als",
+ "unadvertised": "Nicht geworben"
},
"mapEditor": {
"modalTitle": "Karteneditor",
diff --git a/web/client/translations/data.en-US.json b/web/client/translations/data.en-US.json
index 747d4b019a..5ffec13166 100644
--- a/web/client/translations/data.en-US.json
+++ b/web/client/translations/data.en-US.json
@@ -3030,7 +3030,8 @@
"saveSuccessTitle": "Success",
"saveSuccessMessage": "Saved successfully",
"saveTooltip": "Save",
- "saveAsTooltip": "Save As"
+ "saveAsTooltip": "Save As",
+ "unadvertised": "Unadvertised"
},
"mapEditor": {
"modalTitle": "Map Editor",
diff --git a/web/client/translations/data.es-ES.json b/web/client/translations/data.es-ES.json
index d64956fac3..39dfe4d36f 100644
--- a/web/client/translations/data.es-ES.json
+++ b/web/client/translations/data.es-ES.json
@@ -3019,7 +3019,8 @@
"saveSuccessTitle": "éxito",
"saveSuccessMessage": "Guardado con éxito",
"saveTooltip": "Salvar",
- "saveAsTooltip": "Guardar como"
+ "saveAsTooltip": "Guardar como",
+ "unadvertised": "Sin publicidad"
},
"mapEditor": {
"modalTitle": "Map Editor",
diff --git a/web/client/translations/data.fi-FI.json b/web/client/translations/data.fi-FI.json
index a0f223af6a..f4378f9583 100644
--- a/web/client/translations/data.fi-FI.json
+++ b/web/client/translations/data.fi-FI.json
@@ -2114,7 +2114,8 @@
"close": "Sulje",
"cancel": "Peruuta",
"saveSuccessTitle": "Tallennus onnistui",
- "saveSuccessMessage": "Tallennettu onnistuneesti"
+ "saveSuccessMessage": "Tallennettu onnistuneesti",
+ "unadvertised": "Mainostamaton"
},
"mapEditor": {
"modalTitle": "Karttaeditori",
diff --git a/web/client/translations/data.fr-FR.json b/web/client/translations/data.fr-FR.json
index c1790f4f65..8ed3564799 100644
--- a/web/client/translations/data.fr-FR.json
+++ b/web/client/translations/data.fr-FR.json
@@ -3020,7 +3020,8 @@
"saveSuccessTitle": "Succès",
"saveSuccessMessage": "Enregistré avec succès",
"saveTooltip": "Enregistrer",
- "saveAsTooltip": "Enregistrer sous"
+ "saveAsTooltip": "Enregistrer sous",
+ "unadvertised": "Non annoncé"
},
"mapEditor": {
"modalTitle": "Editeur de carte",
diff --git a/web/client/translations/data.hr-HR.json b/web/client/translations/data.hr-HR.json
index 538497fba6..ffac3cb41e 100644
--- a/web/client/translations/data.hr-HR.json
+++ b/web/client/translations/data.hr-HR.json
@@ -1632,7 +1632,8 @@
"close": "Zatvori",
"cancel": "Odustani",
"saveSuccessTitle": "Uspješno",
- "saveSuccessMessage": "Ploča je uspješno spremljena"
+ "saveSuccessMessage": "Ploča je uspješno spremljena",
+ "unadvertised": "Nenamjerno"
},
"errors":{
"loading": {
diff --git a/web/client/translations/data.is-IS.json b/web/client/translations/data.is-IS.json
index 1cde433caf..61bbcd3d6f 100644
--- a/web/client/translations/data.is-IS.json
+++ b/web/client/translations/data.is-IS.json
@@ -2859,7 +2859,8 @@
"saveSuccessTitle": "Success",
"saveSuccessMessage": "Saved successfully",
"saveTooltip": "Save",
- "saveAsTooltip": "Save As"
+ "saveAsTooltip": "Save As",
+ "unadvertised": "Óauglýst"
},
"mapEditor": {
"modalTitle": "Map Editor",
diff --git a/web/client/translations/data.it-IT.json b/web/client/translations/data.it-IT.json
index 29d3e96ede..1b35cd0eed 100644
--- a/web/client/translations/data.it-IT.json
+++ b/web/client/translations/data.it-IT.json
@@ -3020,7 +3020,8 @@
"saveSuccessTitle": "Successo",
"saveSuccessMessage": "Salvata con successo",
"saveTooltip": "Salva",
- "saveAsTooltip": "Salva con nome"
+ "saveAsTooltip": "Salva con nome",
+ "unadvertised": "Non pubblicizzato"
},
"mapEditor": {
"modalTitle": "Editor di Mappa",
diff --git a/web/client/translations/data.nl-NL.json b/web/client/translations/data.nl-NL.json
index 0dc80014ea..4fdb1eaf6a 100644
--- a/web/client/translations/data.nl-NL.json
+++ b/web/client/translations/data.nl-NL.json
@@ -2942,7 +2942,8 @@
"saveSuccessTitle": "Succes",
"saveSuccessMessage": "Succesvol opgeslagen",
"saveTooltip": "Opslaan",
- "saveAsTooltip": "Opslaan als"
+ "saveAsTooltip": "Opslaan als",
+ "unadvertised": "Niet geadverteerd"
},
"mapEditor": {
"modalTitle": "Kaarteditor",
diff --git a/web/client/translations/data.pt-PT.json b/web/client/translations/data.pt-PT.json
index 51c4972050..804fac8e8a 100644
--- a/web/client/translations/data.pt-PT.json
+++ b/web/client/translations/data.pt-PT.json
@@ -1599,7 +1599,8 @@
"close": "Close",
"cancel": "Cancel",
"saveSuccessTitle": "Success",
- "saveSuccessMessage": "Dashboard saved successfully"
+ "saveSuccessMessage": "Dashboard saved successfully",
+ "unadvertised": "Não anunciado"
},
"errors":{
"loading": {
diff --git a/web/client/translations/data.sk-SK.json b/web/client/translations/data.sk-SK.json
index 008910dbac..109fd92156 100644
--- a/web/client/translations/data.sk-SK.json
+++ b/web/client/translations/data.sk-SK.json
@@ -2598,7 +2598,8 @@
"close": "Zatvoriť",
"cancel": "Zrušiť",
"saveSuccessTitle": "Úspech",
- "saveSuccessMessage": "Úspešne uložené"
+ "saveSuccessMessage": "Úspešne uložené",
+ "unadvertised": "Neinzerované"
},
"mapEditor": {
"modalTitle": "Mapový editor",
diff --git a/web/client/translations/data.sv-SE.json b/web/client/translations/data.sv-SE.json
index d54c88b5c3..f563d0f605 100644
--- a/web/client/translations/data.sv-SE.json
+++ b/web/client/translations/data.sv-SE.json
@@ -2610,7 +2610,8 @@
"saveSuccessTitle": "Framgång",
"saveSuccessMessage": "Sparad framgångsrikt",
"saveTooltip": "Spara",
- "saveAsTooltip": "Spara som"
+ "saveAsTooltip": "Spara som",
+ "unadvertised": "Oannonserad"
},
"mapEditor": {
"modalTitle": "Kartredigerare",
From 0335da2f08bcfb743f2f22c62326a2ac5d12b924 Mon Sep 17 00:00:00 2001
From: Igor Dimov <90094775+Igi-ID@users.noreply.github.com>
Date: Wed, 21 Feb 2024 15:53:38 +0100
Subject: [PATCH 2/2] Fix SaveAs plugin showing persisted data in the modal.
Creator, editor, created, lastUpdate and advertised are now removed and will
not be shown / default to unspecified.
---
web/client/plugins/SaveAs.jsx | 9 +++++----
web/client/plugins/__tests__/SaveAs-test.jsx | 21 +++++++++++++++++++-
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/web/client/plugins/SaveAs.jsx b/web/client/plugins/SaveAs.jsx
index 11388322e2..912195d284 100644
--- a/web/client/plugins/SaveAs.jsx
+++ b/web/client/plugins/SaveAs.jsx
@@ -20,6 +20,10 @@ import {resetMapSaveError} from '../actions/config';
import SaveBaseDialog from './maps/MapSave';
const showMapSaveAsSelector = state => state.controls && state.controls.mapSaveAs && state.controls.mapSaveAs.enabled;
+export const omitResourceProperties = (show, resource) => {
+ const {id, attributes, name, description, detailsSettings, creator, editor, advertised, creation, lastUpdate, ...others} = resource || {};
+ return { show, resource: others };
+};
/**
* Plugin for Create/Clone a Map. Saves the map as a new Resource (using the persistence API).
@@ -33,10 +37,7 @@ export default createPlugin('SaveAs', {
connect(createSelector(
showMapSaveAsSelector,
mapInfoSelector,
- (show, resource) => {
- const {id, attributes, name, description, detailsSettings, ...others} = resource || {};
- return {show, resource: others};
- }),
+ omitResourceProperties),
{
onClose: toggleControl.bind(null, 'mapSaveAs', false),
onResetMapSaveError: resetMapSaveError
diff --git a/web/client/plugins/__tests__/SaveAs-test.jsx b/web/client/plugins/__tests__/SaveAs-test.jsx
index 5c971994dc..09721ecec8 100644
--- a/web/client/plugins/__tests__/SaveAs-test.jsx
+++ b/web/client/plugins/__tests__/SaveAs-test.jsx
@@ -10,7 +10,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-dom/test-utils';
-import MapSaveAs from '../SaveAs';
+import MapSaveAs, { omitResourceProperties } from '../SaveAs';
import { getPluginForTest } from './pluginsTestUtils';
import { createStateMocker } from '../../reducers/__tests__/reducersTestUtils';
@@ -83,6 +83,25 @@ describe('MapSave Plugins (MapSave, MapSaveAs)', () => {
TestUtils.Simulate.change(inputEl);
expect(inputEl.value).toBe('f');
});
+ it('does not show creator, editor, created and lastUpdate fields. Advertised field is unchecked.', () => {
+ const _resources = {
+ creator: 'creator',
+ editor: 'editor',
+ advertised: 'advertised',
+ creation: 'creation',
+ lastUpdate: 'lastUpdate',
+ shownProperty: 'shownProperty'
+ };
+
+ const filtered = omitResourceProperties(true, _resources);
+ expect(filtered.resource.creator).toBeFalsy();
+ expect(filtered.resource.editor).toBeFalsy();
+ expect(filtered.resource.advertised).toBeFalsy();
+ expect(filtered.resource.creation).toBeFalsy();
+ expect(filtered.resource.lastUpdate).toBeFalsy();
+
+ expect(filtered.resource.shownProperty).toBeTruthy();
+ });
});
});