Skip to content

Commit

Permalink
#9583 Unadvertised resources (#9962)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Igi-ID authored Feb 9, 2024
1 parent a6ef5d6 commit 593c4d5
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 38 deletions.
15 changes: 8 additions & 7 deletions web/client/api/GeoStoreDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import { registerErrorParser } from '../utils/LocaleUtils';
import { encodeUTF8 } from '../utils/EncodeUtils';


const generateMetadata = (name = "", description = "") =>
const generateMetadata = (name = "", description = "", advertised = true) =>
"<description><![CDATA[" + description + "]]></description>"
+ "<metadata></metadata>"
+ "<name><![CDATA[" + (name) + "]]></name>";
+ "<name><![CDATA[" + (name) + "]]></name>"
+ "<advertised>" + advertised + "</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 "<attribute><name>" + key + "</name><value>" + attributes[key] + "</value><type>STRING</type></attribute>";
Expand Down Expand Up @@ -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,
"<Resource>" + generateMetadata(newName, newDescription) + "</Resource>",
"<Resource>" + generateMetadata(newName, newDescription, advertised) + "</Resource>",
this.addBaseUrl(merge({
headers: {
'Content-Type': "application/xml"
Expand All @@ -279,7 +280,7 @@ const Api = {
putResourceMetadataAndAttributes: function(resourceId, metadata, options) {
return axios.put(
"resources/resource/" + resourceId,
"<Resource>" + generateMetadata(metadata.name, metadata.description) + createAttributeList(metadata) + "</Resource>",
"<Resource>" + generateMetadata(metadata.name, metadata.description, metadata.advertised) + createAttributeList(metadata) + "</Resource>",
this.addBaseUrl(merge({
headers: {
'Content-Type': "application/xml"
Expand Down Expand Up @@ -337,7 +338,7 @@ const Api = {
const attributesSection = createAttributeList(metadata);
return axios.post(
"resources/",
"<Resource>" + generateMetadata(name, description) + "<category><name>" + (category || "") + "</name></category>" +
"<Resource>" + generateMetadata(name, description, metadata.advertised) + "<category><name>" + (category || "") + "</name></category>" +
attributesSection +
"<store><data><![CDATA[" + (
data
Expand Down
14 changes: 8 additions & 6 deletions web/client/api/__tests__/GeoStoreDAO-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ describe('Test correctness of the GeoStore APIs', () => {
expect(payload).toBe(SAMPLE_XML_RULES);
});
it('test generate meatadata', () => {
const payload = API.generateMetadata("Special & chars", "&<>'\"");
expect(payload).toBe('<description><![CDATA[&<>\'"]]></description><metadata></metadata><name><![CDATA[Special & chars]]></name>');
const payload = API.generateMetadata("Special & chars", "&<>'\"", false);
expect(payload).toBe('<description><![CDATA[&<>\'"]]></description><metadata></metadata><name><![CDATA[Special & chars]]></name><advertised>false</advertised>');
});

it('test login without credentials', (done) => {
Expand Down Expand Up @@ -176,13 +176,15 @@ describe('Test correctness of the GeoStore APIs', () => {
const metadata = API.generateMetadata();
const name = "";
const description = "";
expect(metadata).toEqual(`<description><![CDATA[${description}]]></description><metadata></metadata><name><![CDATA[${name}]]></name>`);
const advertised = true;
expect(metadata).toEqual(`<description><![CDATA[${description}]]></description><metadata></metadata><name><![CDATA[${name}]]></name><advertised>${advertised}</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(`<description><![CDATA[${description}]]></description><metadata></metadata><name><![CDATA[${name}]]></name>`);
const advertised = false;
const metadata = API.generateMetadata(name, description, advertised);
expect(metadata).toEqual(`<description><![CDATA[${description}]]></description><metadata></metadata><name><![CDATA[${name}]]></name><advertised>${advertised}</advertised>`);
});
it("test createAttributeList default", () => {
expect(API.createAttributeList()).toEqual("");
Expand Down
17 changes: 14 additions & 3 deletions web/client/components/resources/forms/Metadata.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {
Expand All @@ -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) => {
Expand Down Expand Up @@ -120,6 +122,12 @@ class Metadata extends React.Component {
<ControlLabel>{this.props.resource && this.renderDate(this.props.resource.modifiedAt || this.props.resource.createdAt) || ""}</ControlLabel>
</FormGroup>
}
{
<FormGroup>
<ControlLabel>{this.props.unadvertisedText}</ControlLabel>
<Checkbox checked={!this.props.resource?.metadata?.advertised} onChange={this.changeAdvertised} aria-label="advertisedResource"/>
</FormGroup>
}
</form>);
}

Expand All @@ -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);
};
}


Expand Down
16 changes: 10 additions & 6 deletions web/client/components/resources/forms/__tests__/Metadata-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,28 @@ describe('Metadata component', () => {
ReactDOM.render(<Metadata />, 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 = {
modifiedAt: new Date(),
createdAt: new Date(),
metadata: {
name: "NAME",
description: "DESCRIPTION"
description: "DESCRIPTION",
advertised: true
}
};
ReactDOM.render(<Metadata resource={resource}/>, 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 = {
Expand All @@ -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', () => {
Expand All @@ -70,7 +74,7 @@ describe('Metadata component', () => {
ReactDOM.render(<Metadata resource={resource}/>, 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', () => {
Expand Down Expand Up @@ -110,7 +114,7 @@ describe('Metadata component', () => {
ReactDOM.render(<Metadata resource={resource} titleFieldText="Title" createdAtFieldText="Created" modifiedAtFieldText="Modified"/>, 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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class MainForm extends React.Component {
namePlaceholderText={"saveDialog.namePlaceholder"}
descriptionPlaceholderText={"saveDialog.descriptionPlaceholder"}
titlePlaceholderText={"saveDialog.titlePlaceholder"}
unadvertisedText={<Message msgId="saveDialog.unadvertised" />}
/>
</Col>
</Row>);
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.da-DK.json
Original file line number Diff line number Diff line change
Expand Up @@ -2839,7 +2839,8 @@
"saveSuccessTitle": "Success",
"saveSuccessMessage": "Saved successfully",
"saveTooltip": "Save",
"saveAsTooltip": "Save As"
"saveAsTooltip": "Save As",
"unadvertised": "Unadvertised"
},
"mapEditor": {
"modalTitle": "Map Editor",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -3057,7 +3057,8 @@
"saveSuccessTitle": "Erfolg",
"saveSuccessMessage": "Erfolgreich gespeichert",
"saveTooltip": "Speichern",
"saveAsTooltip": "Speichern als"
"saveAsTooltip": "Speichern als",
"unadvertised": "Nicht geworben"
},
"mapEditor": {
"modalTitle": "Karteneditor",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -3030,7 +3030,8 @@
"saveSuccessTitle": "Success",
"saveSuccessMessage": "Saved successfully",
"saveTooltip": "Save",
"saveAsTooltip": "Save As"
"saveAsTooltip": "Save As",
"unadvertised": "Unadvertised"
},
"mapEditor": {
"modalTitle": "Map Editor",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.fi-FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -2114,7 +2114,8 @@
"close": "Sulje",
"cancel": "Peruuta",
"saveSuccessTitle": "Tallennus onnistui",
"saveSuccessMessage": "Tallennettu onnistuneesti"
"saveSuccessMessage": "Tallennettu onnistuneesti",
"unadvertised": "Mainostamaton"
},
"mapEditor": {
"modalTitle": "Karttaeditori",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.hr-HR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.is-IS.json
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,8 @@
"saveSuccessTitle": "Success",
"saveSuccessMessage": "Saved successfully",
"saveTooltip": "Save",
"saveAsTooltip": "Save As"
"saveAsTooltip": "Save As",
"unadvertised": "Óauglýst"
},
"mapEditor": {
"modalTitle": "Map Editor",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -2942,7 +2942,8 @@
"saveSuccessTitle": "Succes",
"saveSuccessMessage": "Succesvol opgeslagen",
"saveTooltip": "Opslaan",
"saveAsTooltip": "Opslaan als"
"saveAsTooltip": "Opslaan als",
"unadvertised": "Niet geadverteerd"
},
"mapEditor": {
"modalTitle": "Kaarteditor",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,8 @@
"close": "Close",
"cancel": "Cancel",
"saveSuccessTitle": "Success",
"saveSuccessMessage": "Dashboard saved successfully"
"saveSuccessMessage": "Dashboard saved successfully",
"unadvertised": "Não anunciado"
},
"errors":{
"loading": {
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.sk-SK.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.sv-SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -2610,7 +2610,8 @@
"saveSuccessTitle": "Framgång",
"saveSuccessMessage": "Sparad framgångsrikt",
"saveTooltip": "Spara",
"saveAsTooltip": "Spara som"
"saveAsTooltip": "Spara som",
"unadvertised": "Oannonserad"
},
"mapEditor": {
"modalTitle": "Kartredigerare",
Expand Down

0 comments on commit 593c4d5

Please sign in to comment.