Skip to content

Commit

Permalink
Added map version to state
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap committed Jul 20, 2017
1 parent 607dc51 commit 32f9105
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 35 deletions.
12 changes: 11 additions & 1 deletion web/client/actions/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var {
CHANGE_MAP_STYLE,
CHANGE_ROTATION,
CREATION_ERROR_LAYER,
UPDATE_VERSION,
creationError,
changeMapView,
clickOnMap,
Expand All @@ -25,7 +26,8 @@ var {
changeMapCrs,
changeMapScales,
changeMapStyle,
changeRotation
changeRotation,
updateVersion
} = require('../map');

describe('Test correctness of the map actions', () => {
Expand Down Expand Up @@ -121,4 +123,12 @@ describe('Test correctness of the map actions', () => {
expect(retval.rotation).toEqual(angle);
expect(retval.mapStateSource).toEqual(mapStateSource);
});

it('updateVersion', () => {
const version = 2;
const retval = updateVersion(version);
expect(retval).toExist();
expect(retval.type).toEqual(UPDATE_VERSION);
expect(retval.version).toEqual(2);
});
});
12 changes: 11 additions & 1 deletion web/client/actions/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const CHANGE_MAP_SCALES = 'CHANGE_MAP_SCALES';
const CHANGE_MAP_STYLE = 'CHANGE_MAP_STYLE';
const CHANGE_ROTATION = 'CHANGE_ROTATION';
const CREATION_ERROR_LAYER = 'CREATION_ERROR_LAYER';
const UPDATE_VERSION = 'UPDATE_VERSION';

function creationError(options) {
return {
Expand Down Expand Up @@ -113,6 +114,13 @@ function changeMapStyle(style, mapStateSource) {
mapStateSource
};
}
function updateVersion(version) {
return {
type: UPDATE_VERSION,
version
};
}

module.exports = {
CHANGE_MAP_VIEW,
CLICK_ON_MAP,
Expand All @@ -126,6 +134,7 @@ module.exports = {
CHANGE_ROTATION,
ZOOM_TO_POINT,
CREATION_ERROR_LAYER,
UPDATE_VERSION,
changeMapView,
clickOnMap,
changeMousePointer,
Expand All @@ -137,5 +146,6 @@ module.exports = {
changeMapStyle,
changeRotation,
zoomToPoint,
creationError
creationError,
updateVersion
};
25 changes: 0 additions & 25 deletions web/client/epics/__tests__/automapupdate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,6 @@ describe('automapupdate Epics', () => {

});

it('update map without login', (done) => {

let configuration = configureMap({
version: 2
}, "id");

let information = mapInfoLoaded({
canEdit: true
}, "id");

store.dispatch(configuration);
store.dispatch(information);

setTimeout( () => {
try {
const actions = store.getActions();
expect(actions.length).toBe(2);
} catch (e) {
return done(e);
}
done();
}, 500);

});

it('update map info on login success no id', (done) => {

let login = loginSuccess("userDetails", "username", "password", "authProvider");
Expand Down
9 changes: 5 additions & 4 deletions web/client/epics/automapupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const {warning, success} = require('../actions/notifications');
const {toggleControl} = require('../actions/controls');
const {loadMapInfo} = require('../actions/config');
const {LOGIN_SUCCESS} = require('../actions/security');
const {updateVersion} = require('../actions/map');
const ConfigUtils = require('../utils/ConfigUtils');
const {mapIdSelector} = require('../selectors/map');
const {mapIdSelector, mapVersionSelector} = require('../selectors/map');
const { LOCATION_CHANGE } = require('react-router-redux');

/**
Expand All @@ -23,12 +24,12 @@ const { LOCATION_CHANGE } = require('react-router-redux');
* @return {external:Observable}
*/

const manageAutoMapUpdate = action$ =>
const manageAutoMapUpdate = (action$, store) =>
action$.ofType(MAP_CONFIG_LOADED)
.switchMap((mapConfigLoaded) =>
action$.ofType(MAP_INFO_LOADED)
.switchMap((mapInfoLoaded) => {
const version = mapConfigLoaded.config && mapConfigLoaded.config.version || 1;
const version = mapVersionSelector(store.getState());
const canEdit = mapInfoLoaded.info && mapInfoLoaded.info.canEdit || false;
let layers = mapConfigLoaded.config && mapConfigLoaded.config.map && mapConfigLoaded.config.map.layers && mapConfigLoaded.config.map.layers.filter((l) => l.type === 'wms' && l.group !== 'background') || [];
const options = {bbox: true, search: true, dimensions: true, title: false};
Expand Down Expand Up @@ -61,7 +62,7 @@ const manageAutoMapUpdate = action$ =>
autoDismiss: 6,
position: "tc"
});
return Rx.Observable.of(notification, toggleControl('save'));
return Rx.Observable.of(notification, toggleControl('save'), updateVersion(2));
}))
: Rx.Observable.empty();
}).takeUntil(action$.ofType(LOCATION_CHANGE)));
Expand Down
10 changes: 10 additions & 0 deletions web/client/reducers/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,14 @@ describe('Test the map reducer', () => {
expect(state.bbox.rotation).toEqual(rotation);
expect(state.mapStateSource).toBe("test");
});

it('change map version', () => {
let version = 2;
const action = {
type: 'UPDATE_VERSION',
version
};
let state = mapConfig({}, action);
expect(state.version).toEqual(version);
});
});
2 changes: 1 addition & 1 deletion web/client/reducers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function mapConfig(state = null, action) {
// we get from the configuration what will be used as the initial state
let mapState = action.legacy && !hasVersion ? ConfigUtils.convertFromLegacy(action.config) : ConfigUtils.normalizeConfig(action.config.map);

mapState.map = assign({}, mapState.map, {mapId: action.mapId, size});
mapState.map = assign({}, mapState.map, {mapId: action.mapId, size, version: hasVersion ? action.config.version : 1});
// we store the map initial state for future usage
return assign({}, mapState, {mapInitialConfig: mapState.map});
case MAP_CONFIG_LOAD_ERROR:
Expand Down
5 changes: 4 additions & 1 deletion web/client/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

var {CHANGE_MAP_VIEW, CHANGE_MOUSE_POINTER,
CHANGE_ZOOM_LVL, CHANGE_MAP_CRS, CHANGE_MAP_SCALES, ZOOM_TO_EXTENT, PAN_TO,
CHANGE_MAP_STYLE, CHANGE_ROTATION, ZOOM_TO_POINT} = require('../actions/map');
CHANGE_MAP_STYLE, CHANGE_ROTATION, UPDATE_VERSION, ZOOM_TO_POINT} = require('../actions/map');
const {isArray} = require('lodash');


Expand Down Expand Up @@ -134,6 +134,9 @@ function mapConfig(state = null, action) {
let newBbox = assign({}, state.bbox, {rotation: action.rotation});
return assign({}, state, {bbox: newBbox, mapStateSource: action.mapStateSource});
}
case UPDATE_VERSION: {
return assign({}, state, {version: action.version});
}
default:
return state;
}
Expand Down
7 changes: 6 additions & 1 deletion web/client/selectors/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

const expect = require('expect');
const {mapSelector, mapIdSelector} = require('../map');
const {mapSelector, mapIdSelector, mapVersionSelector} = require('../map');

describe('Test map selectors', () => {
it('test mapSelector from config', () => {
Expand Down Expand Up @@ -41,4 +41,9 @@ describe('Test map selectors', () => {
const props = mapIdSelector({map: {present: {mapId: "id"}}});
expect(props).toBe("id");
});

it('test mapVersionSelector', () => {
const props = mapVersionSelector({map: {present: {version: 2}}});
expect(props).toBe(2);
});
});
4 changes: 3 additions & 1 deletion web/client/selectors/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ const scalesSelector = createSelector(
);

const mapIdSelector = (state) => state.map && state.map.present && state.map.present.mapId || null;
const mapVersionSelector = (state) => state.map && state.map.present && state.map.present.version || 1;

module.exports = {
mapSelector,
scalesSelector,
mapIdSelector
mapIdSelector,
mapVersionSelector
};

0 comments on commit 32f9105

Please sign in to comment.