Skip to content

Commit

Permalink
Fix geosolutions-it#3525 add possiblity to save and load map info con…
Browse files Browse the repository at this point in the history
…figuration
  • Loading branch information
MV88 committed Feb 14, 2019
1 parent 218b7e3 commit 94edbd6
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 29 deletions.
5 changes: 5 additions & 0 deletions web/client/actions/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var {
GET_VECTOR_INFO,
TOGGLE_MAPINFO_STATE,
UPDATE_CENTER_TO_MARKER,
TOGGLE_EMPTY_MESSAGE_GFI, toggleEmptyMessageGFI,
getFeatureInfo,
changeMapInfoState,
newMapInfoRequest,
Expand Down Expand Up @@ -206,4 +207,8 @@ describe('Test correctness of the map actions', () => {
expect(retval.type).toBe(UPDATE_CENTER_TO_MARKER);
expect(retval.status).toBe('enabled');
});
it('toggleEmptyMessageGFI', () => {
const retval = toggleEmptyMessageGFI();
expect(retval.type).toBe(TOGGLE_EMPTY_MESSAGE_GFI);
});
});
4 changes: 4 additions & 0 deletions web/client/actions/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const TOGGLE_MAPINFO_STATE = 'TOGGLE_MAPINFO_STATE';
const UPDATE_CENTER_TO_MARKER = 'UPDATE_CENTER_TO_MARKER';
const CLOSE_IDENTIFY = 'IDENTIFY:CLOSE_IDENTIFY';

const TOGGLE_EMPTY_MESSAGE_GFI = "IDENTIFY:TOGGLE_EMPTY_MESSAGE_GFI";
const toggleEmptyMessageGFI = () => ({type: TOGGLE_EMPTY_MESSAGE_GFI});

/**
* Private
* @return a LOAD_FEATURE_INFO action with the response data to a wms GetFeatureInfo
Expand Down Expand Up @@ -240,6 +243,7 @@ module.exports = {
TOGGLE_MAPINFO_STATE,
UPDATE_CENTER_TO_MARKER,
CLOSE_IDENTIFY,
TOGGLE_EMPTY_MESSAGE_GFI, toggleEmptyMessageGFI,
closeIdentify,
getFeatureInfo,
changeMapInfoState,
Expand Down
8 changes: 5 additions & 3 deletions web/client/components/data/identify/DefaultViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class DefaultViewer extends React.Component {
onNext: PropTypes.func,
onPrevious: PropTypes.func,
onUpdateIndex: PropTypes.func,
setIndex: PropTypes.func
setIndex: PropTypes.func,
showEmptyMessageGFI: PropTypes.bool
};

static defaultProps = {
Expand All @@ -52,6 +53,7 @@ class DefaultViewer extends React.Component {
},
containerProps: {},
index: 0,
showEmptyMessageGFI: true,
onNext: () => {},
onPrevious: () => {},
setIndex: () => {}
Expand Down Expand Up @@ -79,12 +81,12 @@ class DefaultViewer extends React.Component {
const {layerMetadata} = res;
return layerMetadata.title;
});
return (
return this.props.showEmptyMessageGFI ? (
<Alert bsStyle={"info"}>
<Message msgId={"noInfoForLayers"} />
<b>{titles.join(', ')}</b>
</Alert>
);
) : null;
}
return null;
};
Expand Down
4 changes: 3 additions & 1 deletion web/client/components/data/identify/IdentifyContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = props => {
setIndex,
warning,
clearWarning,
zIndex
zIndex,
showEmptyMessageGFI
} = props;

const latlng = point && point.latlng || null;
Expand Down Expand Up @@ -105,6 +106,7 @@ module.exports = props => {
format={format}
missingResponses={missingResponses}
responses={responses}
showEmptyMessageGFI={showEmptyMessageGFI}
{...viewerOptions}/>
</DockablePanel>
<Portal>
Expand Down
3 changes: 2 additions & 1 deletion web/client/epics/mapexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ const {EXPORT_MAP} = require('../actions/mapexport');
const { setControlProperty } = require('../actions/controls');

const { mapSelector } = require('../selectors/map');
const { mapInfoConfigurationSelector } = require('../selectors/mapInfo');
const { layersSelector, groupsSelector } = require('../selectors/layers');
const { mapOptionsToSaveSelector } = require('../selectors/mapsave');
const textSearchConfigSelector = state => state.searchconfig && state.searchconfig.textSearchConfig;

const PersistMap = {
mapstore2: (state) => JSON.stringify(MapUtils.saveMapConfiguration(mapSelector(state), layersSelector(state), groupsSelector(state), textSearchConfigSelector(state), mapOptionsToSaveSelector(state)))
mapstore2: (state) => JSON.stringify(MapUtils.saveMapConfiguration(mapSelector(state), layersSelector(state), groupsSelector(state), textSearchConfigSelector(state), mapOptionsToSaveSelector(state), mapInfoConfigurationSelector(state)))
};


Expand Down
11 changes: 6 additions & 5 deletions web/client/plugins/Identify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const {createSelector} = require('reselect');
const {mapSelector} = require('../selectors/map');
const {layersSelector} = require('../selectors/layers');

const {getFeatureInfo, getVectorInfo, showMapinfoMarker, hideMapinfoMarker, showMapinfoRevGeocode, hideMapinfoRevGeocode, noQueryableLayers, clearWarning, toggleMapInfoState} = require('../actions/mapInfo');
const {getFeatureInfo, getVectorInfo, showMapinfoMarker, hideMapinfoMarker, showMapinfoRevGeocode, hideMapinfoRevGeocode, noQueryableLayers, clearWarning, toggleMapInfoState, changeMapInfoFormat, updateCenterToMarker, closeIdentify, purgeMapInfoResults} = require('../actions/mapInfo');
const {changeMousePointer} = require('../actions/map');
const {changeMapInfoFormat, updateCenterToMarker, closeIdentify, purgeMapInfoResults} = require('../actions/mapInfo');
const {showEmptyMessageGFISelector} = require('../selectors/mapInfo');
const {currentLocaleSelector} = require('../selectors/locale');

const {compose, defaultProps} = require('recompose');
Expand Down Expand Up @@ -46,9 +46,10 @@ const selector = createSelector([
(state) => state.mapInfo && state.mapInfo.reverseGeocodeData,
(state) => state.mapInfo && state.mapInfo.warning,
currentLocaleSelector,
state => mapLayoutValuesSelector(state, {height: true})
], (enabled, responses, requests, format, map, layers, point, layer, showModalReverse, reverseGeocodeData, warning, currentLocale, dockStyle) => ({
enabled, responses, requests, format, map, layers, point, layer, showModalReverse, reverseGeocodeData, warning, currentLocale, dockStyle
state => mapLayoutValuesSelector(state, {height: true}),
state => showEmptyMessageGFISelector(state)
], (enabled, responses, requests, format, map, layers, point, layer, showModalReverse, reverseGeocodeData, warning, currentLocale, dockStyle, showEmptyMessageGFI) => ({
enabled, responses, requests, format, map, layers, point, layer, showModalReverse, reverseGeocodeData, warning, currentLocale, dockStyle, showEmptyMessageGFI
}));
// result panel

Expand Down
13 changes: 9 additions & 4 deletions web/client/plugins/Save.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ const ConfigUtils = require('../utils/ConfigUtils');
const {mapSelector} = require('../selectors/map');
const {layersSelector, groupsSelector} = require('../selectors/layers');
const {mapOptionsToSaveSelector} = require('../selectors/mapsave');

const {mapInfoConfigurationSelector} = require('../selectors/mapinfo');
const MapUtils = require('../utils/MapUtils');
const showSelector = state => state.controls && state.controls.save && state.controls.save.enabled;
const textSearchConfigSelector = state => state.searchconfig && state.searchconfig.textSearchConfig;
const selector = createSelector(mapSelector, mapOptionsToSaveSelector, layersSelector, groupsSelector, showSelector, textSearchConfigSelector, (map, additionalOptions, layers, groups, show, textSearchConfig) => ({

const selector = createSelector(
mapSelector, mapOptionsToSaveSelector, layersSelector, groupsSelector, showSelector, textSearchConfigSelector, mapInfoConfigurationSelector,
(map, additionalOptions, layers, groups, show, textSearchConfig, mapInfoConfiguration) => ({
currentZoomLvl: map && map.zoom,
show,
map,
additionalOptions,
mapId: map && map.mapId,
layers,
textSearchConfig,
groups
groups,
mapInfoConfiguration
}));

class Save extends React.Component {
Expand All @@ -49,6 +53,7 @@ class Save extends React.Component {
map: PropTypes.object,
layers: PropTypes.array,
groups: PropTypes.array,
mapInfoConfiguration: PropTypes.object,
params: PropTypes.object,
textSearchConfig: PropTypes.object
};
Expand Down Expand Up @@ -90,7 +95,7 @@ class Save extends React.Component {
goForTheUpdate = () => {
if (this.props.mapId) {
if (this.props.map && this.props.layers) {
const resultingmap = MapUtils.saveMapConfiguration(this.props.map, this.props.layers, this.props.groups, this.props.textSearchConfig, this.props.additionalOptions);
const resultingmap = MapUtils.saveMapConfiguration(this.props.map, this.props.layers, this.props.groups, this.props.textSearchConfig, this.props.additionalOptions, this.props.mapInfoConfiguration);
const {name, description} = this.props.map.info;
this.props.onMapSave({id: this.props.mapId, data: resultingmap, metadata: {name, description}, category: "MAP"});
this.props.onClose();
Expand Down
12 changes: 8 additions & 4 deletions web/client/plugins/SaveAs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {editMap, updateCurrentMap, errorCurrentMap, resetCurrentMap} = require('.
const {mapSelector} = require('../selectors/map');
const {layersSelector, groupsSelector} = require('../selectors/layers');
const {mapOptionsToSaveSelector} = require('../selectors/mapsave');
const {mapInfoConfigurationSelector} = require('../selectors/mapInfo');
const {mapTypeSelector} = require('../selectors/maptype');
const {indexOf} = require('lodash');
const uuid = require('uuid/v1');
Expand All @@ -41,13 +42,15 @@ const selector = createSelector(
groupsSelector,
mapOptionsToSaveSelector,
saveAsStateSelector,
(map, layers, groups, additionalOptions, saveAsState) => ({
mapInfoConfigurationSelector,
(map, layers, groups, additionalOptions, saveAsState, mapInfoConfiguration) => ({
currentZoomLvl: map && map.zoom,
map,
layers,
groups,
additionalOptions,
...saveAsState
...saveAsState,
mapInfoConfiguration
}));

class SaveAs extends React.Component {
Expand Down Expand Up @@ -75,7 +78,8 @@ class SaveAs extends React.Component {
metadataChanged: PropTypes.func,
onMapSave: PropTypes.func,
loadMapInfo: PropTypes.func,
textSearchConfig: PropTypes.object
textSearchConfig: PropTypes.object,
mapInfoConfiguration: PropTypes.object
};

static contextTypes = {
Expand Down Expand Up @@ -140,7 +144,7 @@ class SaveAs extends React.Component {

// this method creates the content for the Map Resource
createV2Map = () => {
return MapUtils.saveMapConfiguration(this.props.map, this.props.layers, this.props.groups, this.props.textSearchConfig, this.props.additionalOptions);
return MapUtils.saveMapConfiguration(this.props.map, this.props.layers, this.props.groups, this.props.textSearchConfig, this.props.additionalOptions, this.props.mapInfoConfiguration);
};

saveMap = (id, name, description) => {
Expand Down
31 changes: 30 additions & 1 deletion web/client/reducers/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

const expect = require('expect');
const mapInfo = require('../mapInfo');
const { featureInfoClick } = require('../../actions/mapInfo');
const { featureInfoClick, toggleEmptyMessageGFI } = require('../../actions/mapInfo');
const { MAP_CONFIG_LOADED } = require('../../actions/config');
const assign = require('object-assign');

require('babel-polyfill');
Expand Down Expand Up @@ -1426,4 +1427,32 @@ describe('Test the mapInfo reducer', () => {
expect(state.responses[0].layerMetadata.buffer).toBe(2);
});

it('TOGGLE_EMPTY_MESSAGE_GFI', () => {
let state = mapInfo({
infoFormat: "text/html",
configuration: {}
}, toggleEmptyMessageGFI());
expect(state.configuration.showEmptyMessageGFI).toBe(true);
state = mapInfo(state, toggleEmptyMessageGFI());
expect(state.configuration.showEmptyMessageGFI).toBe(false);
});
it('MAP_CONFIG_LOADED', () => {
const oldInfoFormat = "text/html";
const newInfoFormat = "application/json";
let state = mapInfo({
infoFormat: oldInfoFormat,
configuration: {}
}, {
type: MAP_CONFIG_LOADED,
config: {
mapInfoConfiguration: {
infoFormat: newInfoFormat,
showEmptyMessageGFI: true
}
}
});
expect(state.configuration.showEmptyMessageGFI).toBe(true);
expect(state.configuration.infoFormat).toBe(newInfoFormat);
});

});
33 changes: 28 additions & 5 deletions web/client/reducers/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ const {
CLEAR_WARNING,
FEATURE_INFO_CLICK,
TOGGLE_MAPINFO_STATE,
UPDATE_CENTER_TO_MARKER
UPDATE_CENTER_TO_MARKER,
TOGGLE_EMPTY_MESSAGE_GFI
} = require('../actions/mapInfo');
const {
MAP_CONFIG_LOADED
} = require('../actions/config');
const {RESET_CONTROLS} = require('../actions/controls');

const assign = require('object-assign');
Expand All @@ -44,7 +48,10 @@ function receiveResponse(state, action, type) {
}
return state;
}
const initState = {enabled: true};
const initState = {
enabled: true,
configuration: {}
};

function mapInfo(state = initState, action) {
switch (action.type) {
Expand Down Expand Up @@ -92,9 +99,13 @@ function mapInfo(state = initState, action) {
});
}
case CHANGE_MAPINFO_FORMAT: {
return assign({}, state, {
infoFormat: action.infoFormat
});
return {...state,
infoFormat: action.infoFormat,
configuration: {
...state.configuration,
infoFormat: action.infoFormat
}
};
}
case SHOW_MAPINFO_MARKER: {
return assign({}, state, {
Expand Down Expand Up @@ -191,6 +202,18 @@ function mapInfo(state = initState, action) {
centerToMarker: action.status
});
}
case TOGGLE_EMPTY_MESSAGE_GFI: {
return {...state, configuration: {
...state.configuration, showEmptyMessageGFI: !state.configuration.showEmptyMessageGFI
}
};
}
case MAP_CONFIG_LOADED: {
return {...state,
configuration: action.config.mapInfoConfiguration,
infoFormat: action.config.mapInfoConfiguration.infoFormat
};
}
default:
return state;
}
Expand Down
34 changes: 33 additions & 1 deletion web/client/selectors/__tests__/mapinfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@


const expect = require('expect');
const {mapInfoRequestsSelector, generalInfoFormatSelector, stopGetFeatureInfoSelector, isMapInfoOpen} = require('../mapinfo');
const {
mapInfoRequestsSelector,
generalInfoFormatSelector,
stopGetFeatureInfoSelector,
isMapInfoOpen,
mapInfoConfigurationSelector,
showEmptyMessageGFISelector
} = require('../mapinfo');

describe('Test mapinfo selectors', () => {
it('test generalInfoFormatSelector default value', () => {
Expand Down Expand Up @@ -109,5 +116,30 @@ describe('Test mapinfo selectors', () => {
});
expect(props).toEqual(true);
});
it('test mapInfoConfigurationSelector', () => {
const infoFormat = "text/html";
const showEmptyMessageGFI = true;
const props = mapInfoConfigurationSelector({
mapInfo: {
configuration: {
infoFormat,
showEmptyMessageGFI
}
}
});
expect(props.infoFormat).toEqual(infoFormat);
expect(props.showEmptyMessageGFI).toEqual(showEmptyMessageGFI);
});
it('test showEmptyMessageGFISelector', () => {
const showEmptyMessageGFI = true;
const props = showEmptyMessageGFISelector({
mapInfo: {
configuration: {
showEmptyMessageGFI
}
}
});
expect(props).toEqual(showEmptyMessageGFI);
});

});
7 changes: 6 additions & 1 deletion web/client/selectors/mapinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const isMapInfoOpen = state => !!mapInfoRequestsSelector(state) && mapInfoReques
*/
const generalInfoFormatSelector = (state) => get(state, "mapInfo.infoFormat", "text/plain");

const showEmptyMessageGFISelector = (state) => get(state, "mapInfo.configuration.showEmptyMessageGFI", true); // verify if we need to remove this default in austrocontrol
const mapInfoConfigurationSelector = (state) => get(state, "mapInfo.configuration", {});

const measureActiveSelector = (state) => get(state, "measurement.lineMeasureEnabled") || get(state, "measurement.areaMeasureEnabled") || get(state, "measurement.bearingMeasureEnabled");
const drawSupportActiveSelector = (state) => {
const drawStatus = get(state, "draw.drawStatus", false);
Expand Down Expand Up @@ -73,5 +76,7 @@ module.exports = {
isMapInfoOpen,
generalInfoFormatSelector,
mapInfoRequestsSelector,
stopGetFeatureInfoSelector
stopGetFeatureInfoSelector,
showEmptyMessageGFISelector,
mapInfoConfigurationSelector
};
Loading

0 comments on commit 94edbd6

Please sign in to comment.