Skip to content

Commit

Permalink
Fixes geosolutions-it#3070: thematic style removed on opacity change, f…
Browse files Browse the repository at this point in the history
…ixes geosolutions-it#3071: validation of thematic classes ranges
  • Loading branch information
mbarto committed Jul 12, 2018
1 parent 022b8a9 commit d168e7e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 10 deletions.
12 changes: 12 additions & 0 deletions web/client/components/TOC/fragments/settings/ThematicLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class ThematicLayer extends React.Component {
</Row>
<Row><Col xs={12}>
{this.props.classificationLoading.status ? <LoadingView width={this.props.loaderSize} height={this.props.loaderSize}/> : null}
{this.renderInputError('classification')}
<ThemaClassesEditor className={this.props.classificationLoading.status ? "loading" : ""} classification={this.getClassification()} onUpdateClasses={this.updateClassification}/>
{this.props.classificationLoading.error ? this.renderError(this.props.classificationLoading.error, 'classification_error') : null}
</Col></Row>
Expand Down Expand Up @@ -480,9 +481,20 @@ class ThematicLayer extends React.Component {
classification
})
}));
if (!this.validClassification(classification)) {
this.props.onInvalidInput('classification', 'toc.thematic.invalid_classes');
} else {
this.props.onValidInput('classification');
}
this.props.onDirtyStyle();
};

validClassification = (classification = []) => {
return !classification.reduce((previous, current) => {
return previous || (current.max < current.min);
}, false);
};

createRamp = (item) => item.colors;

isConfigurationValid = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,22 @@ describe('test ThematicLayer module component', () => {
TestUtils.Simulate.mouseDown(intervalsPicker.querySelector('.rw-btn'));
expect(spyInvalid).toHaveBeenCalled();
});

it('tests ThematicLayer component with configured thematic thema style invalid classification', () => {
const actions = {
onInvalidInput: () => { }
};
const spyInvalid = expect.spyOn(actions, 'onInvalidInput');

const comp = ReactDOM.render(<ThematicLayer
onInvalidInput={actions.onInvalidInput}
maxClasses={3}
layer={layerWithConfiguredThematic} adminCfg={{ open: false, current: "{}" }} classification={classification} />, document.getElementById("container"));

const domNode = ReactDOM.findDOMNode(comp);
expect(domNode).toExist();
const input = domNode.querySelectorAll('input.rw-input')[7];
TestUtils.Simulate.change(input, { "target": { "value": "5" } });
expect(spyInvalid).toHaveBeenCalled();
});
});
14 changes: 11 additions & 3 deletions web/client/components/map/leaflet/plugins/WMSLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const FilterUtils = require('../../../../utils/FilterUtils');
const WMSUtils = require('../../../../utils/leaflet/WMSUtils');
const L = require('leaflet');
const objectAssign = require('object-assign');
const {isArray} = require('lodash');
const {isArray, isNil} = require('lodash');
const SecurityUtils = require('../../../../utils/SecurityUtils');
const ElevationUtils = require('../../../../utils/ElevationUtils');
require('leaflet.nontiledlayer');
Expand Down Expand Up @@ -147,6 +147,14 @@ L.tileLayer.elevationWMS = function(urls, options, nodata) {
return new L.TileLayer.ElevationWMS(urls, options, nodata);
};

const removeNulls = (obj = {}) => {
return Object.keys(obj).reduce((previous, key) => {
return isNil(obj[key]) ? previous : objectAssign(previous, {
[key]: obj[key]
});
}, {});
};


function wmsToLeafletOptions(options) {
var opacity = options.opacity !== undefined ? options.opacity : 1;
Expand Down Expand Up @@ -181,7 +189,7 @@ function getWMSURLs( urls ) {
Layers.registerType('wms', {
create: (options) => {
const urls = getWMSURLs(isArray(options.url) ? options.url : [options.url]);
const queryParameters = wmsToLeafletOptions(options) || {};
const queryParameters = removeNulls(wmsToLeafletOptions(options) || {});
urls.forEach(url => SecurityUtils.addAuthenticationParameter(url, queryParameters, options.securityToken));
if (options.useForElevation) {
return L.tileLayer.elevationWMS(urls, queryParameters, options.nodata || -9999);
Expand Down Expand Up @@ -221,7 +229,7 @@ Layers.registerType('wms', {
return objectAssign({}, accumulator, {[currentValue]: newQueryParameters[currentValue] });
}, newParams);
// set new options as parameters, merged with params
layer.setParams(objectAssign(newParams, newParams.params, SecurityUtils.addAuthenticationToSLD(newOptions.params || {}, newOptions)));
layer.setParams(removeNulls(objectAssign(newParams, newParams.params, SecurityUtils.addAuthenticationToSLD(newOptions.params || {}, newOptions))));
}/* else if (!isEqual(newOptions.params, oldOptions.params)) {
layer.setParams(newOptions.params);
}*/
Expand Down
40 changes: 39 additions & 1 deletion web/client/epics/__tests__/thematic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

const expect = require('expect');
const { testEpic } = require('./epicTestUtils');
const { testEpic ,TEST_TIMEOUT, addTimeoutEpic } = require('./epicTestUtils');

const {
FIELDS_LOADED, FIELDS_ERROR, CLASSIFICATION_LOADED, CLASSIFICATION_ERROR, loadFields, loadClassification
Expand Down Expand Up @@ -157,4 +157,42 @@ describe('thematic epic', () => {
done();
}, BASE_STATE);
});

it('removeStyleEpic', (done) => {
const startActions = [updateNode('mylayer', 'layer', { thematic: null })];
testEpic(removeThematicEpic, 1, startActions, actions => {
expect(actions.length).toBe(1);
actions.forEach((action) => {
switch (action.type) {
case CHANGE_LAYER_PARAMS:
expect(action.layer).toExist();
expect(action.params).toExist();
expect(action.params.SLD).toNotExist();
expect(action.params.viewparams).toNotExist();
done();
break;
default:
done(new Error("Action not recognized"));
}
});
done();
}, BASE_STATE);
});

it('removeStyleEpic not run', (done) => {
const startActions = [updateNode('mylayer', 'layer', { })];
testEpic(addTimeoutEpic(removeThematicEpic), 1, startActions, actions => {
expect(actions.length).toBe(1);
actions.forEach((action) => {
switch (action.type) {
case TEST_TIMEOUT:
done();
break;
default:
done(new Error("Action not recognized"));
}
});
done();
}, BASE_STATE);
});
});
2 changes: 1 addition & 1 deletion web/client/epics/thematic.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = (config) => ({
action$.ofType(UPDATE_NODE)
.switchMap((action) => {
const layer = head(store.getState().layers.flat.filter(l => l.id === action.node));
if (layer && !action.options.thematic && config.hasThematicStyle(layer)) {
if (layer && action.options.thematic === null && config.hasThematicStyle(layer)) {
const newParams = config.removeThematicStyle(layer.params);
return Rx.Observable.of(changeLayerParams(action.node, newParams));
}
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.de-DE
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@
"fields_error": "Fehler beim Laden der Felderliste: {message}",
"interval_limit": "Intervalle sollten eine Zahl zwischen {min} und {max} sein",
"invalid_object": "Ungültige Serviceantwort",
"invalid_geometry": "Der Geometrietyp ist nicht gültig, kein Punkt, Linie oder Polygon"
"invalid_geometry": "Der Geometrietyp ist nicht gültig, kein Punkt, Linie oder Polygon",
"invalid_classes": "Max muss in jeder Klasse größer als min sein"
}
},
"print":{
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.en-US
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@
"fields_error": "Error loading fields list: {message}",
"interval_limit": "Intervals should be a number between {min} and {max}",
"invalid_object": "Invalid service response",
"invalid_geometry": "Geometry type is not valid, not a point, line or polygon"
"invalid_geometry": "Geometry type is not valid, not a point, line or polygon",
"invalid_classes": "Max must be greater than min in every class"
}
},
"print":{
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.es-ES
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@
"fields_error": "Error al cargar la lista de campos: {message}",
"interval_limit": "Los intervalos deben ser un número entre {min} y {max}",
"invalid_object": "Respuesta de servicio inválida",
"invalid_geometry": "El tipo de geometría no es válido, no es un punto, línea o polígono"
"invalid_geometry": "El tipo de geometría no es válido, no es un punto, línea o polígono",
"invalid_classes": "Max debe ser mayor que min en todas las clases"
}
},
"print":{
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.fr-FR
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@
"fields_error": "Erreur lors du chargement de la liste des champs: {message}",
"interval_limit": "Les intervalles doivent être compris entre {min} et {max}",
"invalid_object": "Réponse au service non valide",
"invalid_geometry": "Le type de géométrie n'est pas valide, pas un point, une ligne ou un polygone"
"invalid_geometry": "Le type de géométrie n'est pas valide, pas un point, une ligne ou un polygone",
"invalid_classes": "Max doit être supérieur à min dans chaque classe"
}
},
"print":{
Expand Down
3 changes: 2 additions & 1 deletion web/client/translations/data.it-IT
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@
"fields_error": "Errore durante il caricamento dell'elenco dei campi: {message}",
"interval_limit": "Inserisci un valore tra {min} e {max}",
"invalid_object": "Risposta del servizio non valida",
"invalid_geometry": "Il tipo di geometria non è valido, deve essere un punto, una linea o un poligono"
"invalid_geometry": "Il tipo di geometria non è valido, deve essere un punto, una linea o un poligono",
"invalid_classes": "Il valore massimo di ogni classe deve essere maggiore del relativo minimo"
}
},
"print":{
Expand Down

0 comments on commit d168e7e

Please sign in to comment.