Skip to content

Commit

Permalink
Merge pull request #64 from geosolutions-it/save-plugin
Browse files Browse the repository at this point in the history
#63: Improve Save and Save As plugins for latest version of MapStore
  • Loading branch information
Alessio Fabiani authored Nov 3, 2020
2 parents 50dc57e + 0eee341 commit a1313d8
Show file tree
Hide file tree
Showing 31 changed files with 1,756 additions and 30 deletions.
6 changes: 6 additions & 0 deletions geonode_mapstore_client/client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
debug.log
node_modules/
web/
dist/
module/
coverage/
2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/MapStore2
Submodule MapStore2 updated 1372 files
116 changes: 116 additions & 0 deletions geonode_mapstore_client/client/js/actions/gnresource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2020, 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.
*/

export const RESOURCE_LOADING = 'GEONODE:RESOURCE_LOADING';
export const SET_RESOURCE = 'GEONODE:SET_RESOURCE';
export const RESOURCE_ERROR = 'GEONODE:RESOURCE_ERROR';
export const UPDATE_RESOURCE_PROPERTIES = 'GEONODE:UPDATE_RESOURCE_PROPERTIES';
export const SET_RESOURCE_TYPE = 'GEONODE:SET_RESOURCE_TYPE';
export const SET_NEW_RESOURCE = 'GEONODE:SET_NEW_RESOURCE';
export const SET_RESOURCE_ID = 'GEONODE:SET_RESOURCE_ID';
export const SET_RESOURCE_PERMISSIONS = 'GEONODE:SET_RESOURCE_PERMISSIONS';

/**
* Actions for GeoNode resource
* store information of the resource in use
* @name actions.gnresource
*/

/**
* Initialize loading state
* @memberof actions.gnresource
*/
export function resourceLoading() {
return {
type: RESOURCE_LOADING
};
}

/**
* Set the resource in the state
* @memberof actions.gnresource
* @param {object} data resource data object
*/
export function setResource(data) {
return {
type: SET_RESOURCE,
data
};
}

/**
* Set the resource type in the state
* @memberof actions.gnresource
* @param {object} resourceType resource type
*/
export function setResourceType(resourceType) {
return {
type: SET_RESOURCE_TYPE,
resourceType
};
}

/**
* Set error of resource request
* @memberof actions.gnresource
* @param {object} error error data object
*/
export function resourceError(error) {
return {
type: RESOURCE_ERROR,
error
};
}

/**
* Update resource properties
* @memberof actions.gnresource
* @param {object} properties resource properties to override
*/
export function updateResourceProperties(properties) {
return {
type: UPDATE_RESOURCE_PROPERTIES,
properties
};
}

/**
* Set the current resource as new
* @memberof actions.gnresource
*/
export function setNewResource() {
return {
type: SET_NEW_RESOURCE
};
}

/**
* Set resource id or primary key
* @memberof actions.gnresource
* @param {number|string} id resource id or primary key
*/
export function setResourceId(id) {
return {
type: SET_RESOURCE_ID,
id
};
}

/**
* Set resource permissions
* @memberof actions.gnresource
* @param {object} permissions permissions info
* @param {bool} permissions.canEdit can edit permission
* @param {bool} permissions.canView can view permission
*/
export function setResourcePermissions(permissions) {
return {
type: SET_RESOURCE_PERMISSIONS,
permissions
};
}
91 changes: 91 additions & 0 deletions geonode_mapstore_client/client/js/actions/gnsave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2020, 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.
*/

export const SAVING_RESOURCE = 'GEONODE:SAVING_RESOURCE';
export const SAVE_SUCCESS = 'GEONODE:SAVE_SUCCESS';
export const SAVE_ERROR = 'GEONODE:SAVE_ERROR';
export const CLEAR_SAVE = 'GEONODE:CLEAR_SAVE';
export const SAVE_CONTENT = 'GEONODE:SAVE_CONTENT';
export const UPDATE_RESOURCE_BEFORE_SAVE = 'GEONODE:UPDATE_RESOURCE_BEFORE_SAVE';

/**
* Actions for GeoNode save workflow
* @name actions.gnsave
*/

/**
* Initialize saving loading state
* @memberof actions.gnsave
*/
export function savingResource() {
return {
type: SAVING_RESOURCE
};
}

/**
* Set success response of save workflow
* @memberof actions.gnsave
* @param {object} success success response
*/
export function saveSuccess(success) {
return {
type: SAVE_SUCCESS,
success
};
}

/**
* Set error response of save workflow
* @memberof actions.gnsave
* @param {object} error error response
*/
export function saveError(error) {
return {
type: SAVE_ERROR,
error
};
}

/**
* Clear state of gnsave reducer
* @memberof actions.gnsave
*/
export function clearSave() {
return {
type: CLEAR_SAVE
};
}

/**
* Save or create a resource (trigger epic gnSaveContent)
* @memberof actions.gnsave
* @param {number|string} id resource id or primary key, create a new resource if undefined
* @param {object} metadata properties to update { name, description, thumbnail }
* @param {bool} reload reload page on create
*/
export function saveContent(id, metadata, reload) {
return {
type: SAVE_CONTENT,
id,
metadata,
reload
};
}

/**
* Update current resource properties (trigger epic gnUpdateResource)
* @memberof actions.gnsave
* @param {number|string} id resource id or primary key
*/
export function updateResourceBeforeSave(id) {
return {
type: UPDATE_RESOURCE_BEFORE_SAVE,
id
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2020, 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.
*/

import expect from 'expect';
import MockAdapter from 'axios-mock-adapter';
import axios from '@mapstore/framework/libs/ajax';
import {
creatMapStoreMap,
updateMapStoreMap
} from '@js/api/geonode/adapter';

let mockAxios;

describe('GeoNode adapter api', () => {
beforeEach(done => {
global.__DEVTOOLS__ = true;
mockAxios = new MockAdapter(axios);
setTimeout(done);
});

afterEach(done => {
delete global.__DEVTOOLS__;
mockAxios.restore();
setTimeout(done);
});
it('should post new configuration to mapstore rest (creatMapStoreMap)', (done) => {
const mapConfiguration = {
id: 1,
attributes: [],
data: {},
name: 'Map'
};
mockAxios.onPost(/\/mapstore\/rest\/resources/)
.reply((config) => {
try {
expect(config.data).toBe(JSON.stringify(mapConfiguration));
} catch (e) {
done(e);
}
done();
return [ 200, { }];
});

creatMapStoreMap(mapConfiguration);
});
it('should patch configuration to mapstore rest (updateMapStoreMap)', (done) => {
const id = 1;
const mapConfiguration = {
id: 1,
attributes: [],
data: {},
name: 'Map'
};
mockAxios.onPatch(new RegExp(`/mapstore/rest/resources/${id}`))
.reply((config) => {
try {
expect(config.data).toBe(JSON.stringify(mapConfiguration));
} catch (e) {
done(e);
}
done();
return [ 200, { }];
});

updateMapStoreMap(id, mapConfiguration);
});
});
59 changes: 59 additions & 0 deletions geonode_mapstore_client/client/js/api/geonode/adapter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2020, 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.
*/

import axios from '@mapstore/framework/libs/ajax';
import { getConfigProp } from '@mapstore/framework/utils/ConfigUtils';
import { parseDevHostname } from '@js/utils/APIUtils';

/**
* Api for GeoNode MapStore adapter
* @name api.geonode.adapter
*/

/**
* Create a new MapStore map configuration
* @memberof api.geonode.adapter
* @param {object} body new map configuration
* @return {promise} it returns an object with the success map object response
*/
export const creatMapStoreMap = (body = {}) => {
const baseUrl = getConfigProp('genode_rest_api') || '/mapstore/rest/';
return axios.post(parseDevHostname(`${baseUrl}resources/`),
body,
{
timeout: 10000,
params: {
full: true
}
})
.then(({ data }) => data);
};

/**
* Update an existing MapStore map configuration
* @memberof api.geonode.adapter
* @param {number|string} id resource id
* @param {object} body map configuration
* @return {promise} it returns an object with the success map object response
*/
export const updateMapStoreMap = (id, body = {}) => {
const baseUrl = getConfigProp('genode_rest_api') || '/mapstore/rest/';
return axios.patch(parseDevHostname(`${baseUrl}resources/${id}/`),
body,
{
params: {
full: true
}
})
.then(({ data }) => data);
};

export default {
creatMapStoreMap,
updateMapStoreMap
};
Loading

0 comments on commit a1313d8

Please sign in to comment.