Skip to content

Commit

Permalink
Fix geosolutions-it#1760 update thumbnail with epic
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed May 10, 2017
1 parent a222a30 commit e7ce153
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 16 deletions.
1 change: 1 addition & 0 deletions docma-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"web/client/epics/globeswitcher.js",
"web/client/epics/maptype.js",
"web/client/epics/search.js",
"web/client/epics/maps.js",

"web/client/utils/index.jsdoc",
"web/client/utils/CoordinatesUtils.js",
Expand Down
23 changes: 11 additions & 12 deletions web/client/actions/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,11 @@ function updateMapMetadata(resourceId, newName, newDescription, onReset, options
}

/**
* updates permeissions for the given map.
* updates permissions for the given map.
* @memberof actions.maps
* @param {number} resourceId the identifier of the map
* @param {object} securityRules the new securityRules
* @return {thunk} performs updateResourcePermissions and dispatch permissionsUpdated loadMaps or thumbnailError
* @return {thunk} performs updateResourcePermissions and dispatch permissionsUpdated or thumbnailError
*/
function updatePermissions(resourceId, securityRules) {
if (!securityRules || !securityRules.SecurityRuleList || !securityRules.SecurityRuleList.SecurityRule) {
Expand All @@ -444,7 +444,6 @@ function updatePermissions(resourceId, securityRules) {
return (dispatch) => {
GeoStoreApi.updateResourcePermissions(resourceId, securityRules).then(() => {
dispatch(permissionsUpdated(resourceId, "success"));
dispatch(loadMaps(false, ConfigUtils.getDefaults().initialMapFilter || "*"));
}).catch((e) => {
dispatch(thumbnailError(resourceId, e));
});
Expand All @@ -457,8 +456,8 @@ function updatePermissions(resourceId, securityRules) {
* @param {number} resourceId the id of the resource
* @param {string} name the name of the attribute
* @param {string} value the value of the attribute
* @param {string} [type] the type of the attribute
* @param {object} [options] options for the request
* @param {string} [type] the type of the attribute
* @param {object} [options] options for the request
* @return {thunk} performs the update and dispatch attributeUpdated or thumbnailError
*/
function updateAttribute(resourceId, name, value, type, options) {
Expand All @@ -480,9 +479,9 @@ function updateAttribute(resourceId, name, value, type, options) {
* @param {string} dataThumbnail the data to save for the thumbnail
* @param {string} categoryThumbnail the category for the thumbnails
* @param {number} resourceIdMap the resourceId of the map
* @param {action} [onSuccess] the action to dispatch on success
* @param {action} [onReset] the action to dispatch on reset
* @param {object} [options] options for the request
* @param {action} [onSuccess] the action to dispatch on success
* @param {action} [onReset] the action to dispatch on reset
* @param {object} [options] options for the request
* @return {thunk} perform the thumb creation and dispatch proper actions
*/
function createThumbnail(map, metadataMap, nameThumbnail, dataThumbnail, categoryThumbnail, resourceIdMap, onSuccess, onReset, options) {
Expand Down Expand Up @@ -596,11 +595,11 @@ function deleteThumbnail(resourceId, resourceIdMap, options) {
/**
* Creates a new map.
* @memberof actions.maps
* @param {object} metadata metadata for the new map
* @param {object} content the map object itself
* @param {object} metadata metadata for the new map
* @param {object} content the map object itself
* @param {object} [thumbnail] the thumbnail
* @param {object} [options] options for the request
* @return {thunk} creates the map and dispatches createThumbnail, mapCreated and so on
* @return {thunk} creates the map and dispatches createThumbnail, mapCreated and so on
*/
function createMap(metadata, content, thumbnail, options) {
return (dispatch) => {
Expand All @@ -622,7 +621,7 @@ function createMap(metadata, content, thumbnail, options) {
* @memberof actions.maps
* @param {number} resourceId the id of the resource to delete
* @param {object} options options for the request
* @return {thunk} performs the delete operations and dispatches mapDeleted and loadMaps
* @return {thunk} performs the delete operations and dispatches mapDeleted and loadMaps
*/
function deleteMap(resourceId, options) {
return (dispatch, getState) => {
Expand Down
4 changes: 2 additions & 2 deletions web/client/epics/__tests__/fullscreen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const rootEpic = combineEpics(toggleFullscreenEpic);
const epicMiddleware = createEpicMiddleware(rootEpic);
const mockStore = configureMockStore([epicMiddleware]);

describe('search Epics', () => {
describe('fullscreen Epics', () => {
let store;
beforeEach(() => {
store = mockStore();
Expand All @@ -31,7 +31,7 @@ describe('search Epics', () => {
screenfull.exit();
});

it('produces the search epic', (done) => {
it('produces the fullscreen epic', (done) => {
let changed = false;
let action = toggleFullscreen(true, "html");
if ( screenfull.enabled ) {
Expand Down
40 changes: 40 additions & 0 deletions web/client/epics/__tests__/maps-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

var expect = require('expect');

const configureMockStore = require('redux-mock-store').default;
const { createEpicMiddleware, combineEpics } = require('redux-observable');
const {attributeUpdated, ATTRIBUTE_UPDATED} = require('../../actions/maps');
const {mapsEpic } = require('../maps');
const rootEpic = combineEpics(mapsEpic);
const epicMiddleware = createEpicMiddleware(rootEpic);
const mockStore = configureMockStore([epicMiddleware]);

describe('maps Epics', () => {
let store;
beforeEach(() => {
store = mockStore();
});

afterEach(() => {
epicMiddleware.replaceEpic(rootEpic);
});

it('produces the maps epic', (done) => {
store.dispatch( attributeUpdated(3, "name", "value", "STRING", "success"));

setTimeout(() => {
let actions = store.getActions();
expect(actions.length).toBe(1);
expect(actions[0].type).toBe(ATTRIBUTE_UPDATED);
done();
}, 400);
});
});
36 changes: 36 additions & 0 deletions web/client/epics/maps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

const {
ATTRIBUTE_UPDATED, loadMaps, thumbnailError
} = require('../actions/maps');

const ConfigUtils = require('../utils/ConfigUtils');
const Rx = require('rxjs');

/**
* Gets every `ATTRIBUTE_UPDATED` event.
* Dispatches the reload of the maps after the attributes are updated
* @param {external:Observable} action$
* @memberof epics.maps
* @return {external:Observable}
*/
const mapsEpic = action$ =>
action$.ofType(ATTRIBUTE_UPDATED)
.switchMap( () =>
Rx.Observable.of(loadMaps(false, ConfigUtils.getDefaults().initialMapFilter || "*"))
.catch(e => Rx.Observable.from([thumbnailError(e)]))
);

/**
* Actions for maps
* @name epics.maps
*/
module.exports = {
mapsEpic
};
6 changes: 4 additions & 2 deletions web/client/plugins/Map.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016, GeoSolutions Sas.
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
Expand All @@ -15,6 +15,7 @@ require('./map/css/map.css');

const Message = require('../components/I18N/Message');
const ConfigUtils = require('../utils/ConfigUtils');
const {mapsEpic} = require('../epics/maps');
const {isString} = require('lodash');
let plugins;
/**
Expand Down Expand Up @@ -288,5 +289,6 @@ const selector = createSelector(
);
module.exports = {
MapPlugin: connect(selector)(MapPlugin),
reducers: { draw: require('../reducers/draw') }
reducers: { draw: require('../reducers/draw') },
epics: {mapsEpic}
};

0 comments on commit e7ce153

Please sign in to comment.