From 6dc6bce3e414762f00eb26dfb1e1e0b8d1e85211 Mon Sep 17 00:00:00 2001 From: allyoucanmap Date: Tue, 2 May 2017 17:11:32 +0200 Subject: [PATCH 1/2] Added boolean type to query builder --- .../components/data/query/FilterField.jsx | 2 +- .../components/data/query/GroupField.jsx | 7 +++ web/client/localConfig.json | 2 +- web/client/reducers/query.js | 61 ++++++++++++++++++- webpack.config.js | 5 +- 5 files changed, 73 insertions(+), 4 deletions(-) diff --git a/web/client/components/data/query/FilterField.jsx b/web/client/components/data/query/FilterField.jsx index eb818decff..2fc808f5e7 100644 --- a/web/client/components/data/query/FilterField.jsx +++ b/web/client/components/data/query/FilterField.jsx @@ -89,7 +89,7 @@ const FilterField = React.createClass({ this.props.onUpdateExceptionField(rowId, message); }, updateFieldElement(rowId, name, value, type) { - this.props.onUpdateField(rowId, name, value, type); + this.props.onUpdateField(rowId, name, value, type === 'boolean' ? 'string' : type); if (name === "value") { // For cascading: filter the attributes that depends on diff --git a/web/client/components/data/query/GroupField.jsx b/web/client/components/data/query/GroupField.jsx index 97cd566aec..64eb2658e5 100644 --- a/web/client/components/data/query/GroupField.jsx +++ b/web/client/components/data/query/GroupField.jsx @@ -95,6 +95,9 @@ const GroupField = React.createClass({ case "string": { return ["=", "like", "ilike", "isNull"]; } + case "boolean": { + return ["="]; + } default: return ["=", ">", "<", ">=", "<=", "<>", "><"]; } @@ -129,6 +132,10 @@ const GroupField = React.createClass({ + diff --git a/web/client/localConfig.json b/web/client/localConfig.json index 768d01cc33..2dd643798d 100644 --- a/web/client/localConfig.json +++ b/web/client/localConfig.json @@ -152,7 +152,7 @@ "wrap": true, "initialCatalogURL": { "csw": "http://demo.geo-solutions.it/geoserver/csw", - "wms": "http://demo.geo-solutions.it/geoserver/wms", + "wms": "/geoserver/wms", "wmts": "http://demo.geo-solutions.it/geoserver/gwc/service/wmts" } } diff --git a/web/client/reducers/query.js b/web/client/reducers/query.js index 1f47ef5be0..cd28c7ce4b 100644 --- a/web/client/reducers/query.js +++ b/web/client/reducers/query.js @@ -23,13 +23,72 @@ const {QUERY_FORM_RESET} = require('../actions/queryform'); const {RESET_CONTROLS} = require('../actions/controls'); const assign = require('object-assign'); - +/* const types = { 'xsd:string': 'string', 'xsd:dateTime': 'date', 'xsd:number': 'number', 'xsd:int': 'number' }; +*/ + +const types = { + // string + 'xsd:ENTITIES': 'string', + 'xsd:ENTITY': 'string', + 'xsd:ID': 'string', + 'xsd:IDREF': 'string', + 'xsd:IDREFS': 'string', + 'xsd:language': 'string', + 'xsd:Name': 'string', + 'xsd:NCName': 'string', + 'xsd:NMTOKEN': 'string', + 'xsd:NMTOKENS': 'string', + 'xsd:normalizedString': 'string', + 'xsd:QName': 'string', + 'xsd:string': 'string', + 'xsd:token': 'string', + + // date + 'xsd:date': 'date', + 'xsd:dateTime': 'date', + 'xsd:duration': 'date', + 'xsd:gDay': 'date', + 'xsd:gMonth': 'date', + 'xsd:gMonthDay': 'date', + 'xsd:gYear': 'date', + 'xsd:gYearMonth': 'date', + 'xsd:time': 'date', + + // number + 'xsd:byte': 'number', + 'xsd:decimal': 'number', + 'xsd:int': 'number', + 'xsd:integer': 'number', + 'xsd:long': 'number', + 'xsd:negativeInteger': 'number', + 'xsd:nonNegativeInteger': 'number', + 'xsd:nonPositiveInteger': 'number', + 'xsd:positiveInteger': 'number', + 'xsd:short': 'number', + 'xsd:unsignedLong': 'number', + 'xsd:unsignedInt': 'number', + 'xsd:unsignedShort': 'number', + 'xsd:unsignedByte': 'number', + + // from old object + 'xsd:number': 'number', + + // misc + 'xsd:anyURI': 'string', + 'xsd:base64Binary': 'number', + 'xsd:boolean': 'boolean', + 'xsd:double': 'number', + 'xsd:float': 'number', + 'xsd:hexBinary': 'string', + 'xsd:NOTATION': 'string' +}; + const fieldConfig = {}; const extractInfo = (featureType) => { return { diff --git a/webpack.config.js b/webpack.config.js index 7899bdd008..3b758b6af8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -132,11 +132,14 @@ module.exports = { target: "http://dev.mapstore2.geo-solutions.it" }, '/mapstore/proxy': { - target: "http://dev.mapstore2.geo-solutions.it" + target: "http://localhost:8082" }, '/docs': { target: "http://localhost:8081", pathRewrite: {'/docs': '/mapstore/docs'} + }, + '/geoserver': { + target: "http://sit.comune.bolzano.it" } } }, From e9076cd965a6576c1bb23d275621e9d484d4dbe0 Mon Sep 17 00:00:00 2001 From: allyoucanmap Date: Thu, 11 May 2017 11:12:38 +0200 Subject: [PATCH 2/2] Added additional tests --- .../data/query/__tests__/FilterField-test.jsx | 109 +++++++++++++++++- .../data/query/__tests__/GroupField-test.jsx | 19 ++- 2 files changed, 125 insertions(+), 3 deletions(-) diff --git a/web/client/components/data/query/__tests__/FilterField-test.jsx b/web/client/components/data/query/__tests__/FilterField-test.jsx index d1c0624d3a..352e453940 100644 --- a/web/client/components/data/query/__tests__/FilterField-test.jsx +++ b/web/client/components/data/query/__tests__/FilterField-test.jsx @@ -62,7 +62,10 @@ describe('FilterField', () => { {id: "attribute10", name: "attribute10"} ], valueId: "id", - valueLabel: "name" + valueLabel: "name", + dependson: { + field: "Attribute1" + } } ]; @@ -110,6 +113,9 @@ describe('FilterField', () => { const valueSelect = filterFieldDOMNode.actual.getElementsByClassName('rw-input')[2]; expect(valueSelect.childNodes[0].nodeValue).toBe("attribute1"); + + filterfield.updateFieldElement(200, "value", "value", "string"); + filterfield.updateExceptionFieldElement(200, "error"); }); it('creates the FilterField component with fieldOptions', () => { @@ -185,4 +191,105 @@ describe('FilterField', () => { expect(valueSelectContainer.style.display).toBe('none'); }); + + it('tests the FilterField actions', () => { + + const actions = { + onUpdateField: () => {}, + onUpdateExceptionField: () => {}, + onChangeCascadingValue: () => {} + }; + + const filterField = { + attribute: "attribute" + }; + + const attributes = [ + { + attribute: "Attribute1", + label: "Attribute1", + type: "list", + values: [ + {id: "attribute1", name: "attribute1"}, + {id: "Attribute2", name: "attribute2"}, + {id: "attribute3", name: "attribute3"}, + {id: "attribute4", name: "attribute4"}, + {id: "attribute5", name: "attribute5"} + ], + valueId: "id", + valueLabel: "name", + fieldOptions: {"style": {display: "none"}}, + dependson: { + field: "attribute" + } + } + ]; + + const spyUpdateField = expect.spyOn(actions, 'onUpdateField'); + const spyUpdateExceptionField = expect.spyOn(actions, 'onUpdateExceptionField'); + const spyChangeCascadingValue = expect.spyOn(actions, 'onChangeCascadingValue'); + + const filterfield = ReactDOM.render(, document.getElementById("container")); + + filterfield.props.onUpdateField(); + expect(filterfield).toExist(); + filterfield.updateFieldElement(200, "name", "value", "string"); + expect(spyUpdateField).toHaveBeenCalled(); + expect(spyChangeCascadingValue).toNotHaveBeenCalled(); + expect(spyUpdateField).toHaveBeenCalledWith(200, "name", "value", "string"); + filterfield.updateFieldElement(200, "value", "value", "boolean"); + expect(spyUpdateField).toHaveBeenCalled(); + expect(spyChangeCascadingValue).toHaveBeenCalled(); + expect(spyUpdateField).toHaveBeenCalledWith(200, "name", "value", "string"); + expect(spyChangeCascadingValue).toHaveBeenCalledWith(attributes); + filterfield.updateExceptionFieldElement(200, 'error'); + expect(spyUpdateExceptionField).toHaveBeenCalled(); + expect(spyUpdateExceptionField).toHaveBeenCalledWith(200, 'error'); + expect.restoreSpies(); + }); + + it('tests the FilterField actions without dependson field attribute', () => { + + const actions = { + onUpdateField: () => {}, + onUpdateExceptionField: () => {}, + onChangeCascadingValue: () => {} + }; + + const filterField = { + attribute: "attribute" + }; + + const attributes = [ + { + attribute: "Attribute1", + label: "Attribute1", + type: "list", + values: [ + {id: "attribute1", name: "attribute1"}, + {id: "Attribute2", name: "attribute2"}, + {id: "attribute3", name: "attribute3"}, + {id: "attribute4", name: "attribute4"}, + {id: "attribute5", name: "attribute5"} + ], + valueId: "id", + valueLabel: "name", + fieldOptions: {"style": {display: "none"}}, + dependson: {} + } + ]; + + const spyUpdateField = expect.spyOn(actions, 'onUpdateField'); + const spyChangeCascadingValue = expect.spyOn(actions, 'onChangeCascadingValue'); + + const filterfield = ReactDOM.render(, document.getElementById("container")); + + expect(filterfield).toExist(); + filterfield.updateFieldElement(200, "value", "value", "string"); + expect(spyUpdateField).toHaveBeenCalled(); + expect(spyUpdateField).toHaveBeenCalledWith(200, "value", "value", "string"); + expect(spyChangeCascadingValue).toNotHaveBeenCalled(); + + expect.restoreSpies(); + }); }); diff --git a/web/client/components/data/query/__tests__/GroupField-test.jsx b/web/client/components/data/query/__tests__/GroupField-test.jsx index a9a15c48cb..ea3c525435 100644 --- a/web/client/components/data/query/__tests__/GroupField-test.jsx +++ b/web/client/components/data/query/__tests__/GroupField-test.jsx @@ -10,7 +10,7 @@ const ReactDOM = require('react-dom'); const expect = require('expect'); -const GroupField = require('../QueryBuilder.jsx'); +const GroupField = require('../GroupField.jsx'); describe('GroupField', () => { @@ -114,7 +114,22 @@ describe('GroupField', () => { } const buttons = document.getElementsByClassName('btn btn-default'); - expect(buttons.length).toBe(6); + expect(buttons.length).toBe(4); + + const list = groupfield.getOperator({type: "list"}); + expect(list).toEqual(["="]); + const string = groupfield.getOperator({type: "string"}); + expect(string).toEqual(["=", "like", "ilike", "isNull"]); + const boolean = groupfield.getOperator({type: "boolean"}); + expect(boolean).toEqual(["="]); + const noType = groupfield.getOperator(); + expect(noType).toEqual(["=", ">", "<", ">=", "<=", "<>", "><"]); + + const noSelected = groupfield.getComboValues(); + expect(noSelected).toBe(null); + + const selectedDependsOn = groupfield.getComboValues({dependson: { field: 'field'}}, attributes); + expect(selectedDependsOn).toBe(null); }); it('creates the GroupField with cascading', () => {