Skip to content

Commit

Permalink
Fixes #1302: current version in the UI (#1816)
Browse files Browse the repository at this point in the history
* Fixes #1302: current version in the UI

* Added tests and docs

* Fixed build.sh and tests comments
  • Loading branch information
mbarto authored and MV88 committed May 12, 2017
1 parent ab6ea7e commit 7183c93
Show file tree
Hide file tree
Showing 21 changed files with 273 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"react/jsx-uses-vars": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
"react/no-did-mount-set-state": [2, "allow-in-func"], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
"react/no-did-update-set-state": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
"react/no-multi-comp": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
"react/no-multi-comp": 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
"react/no-unknown-property": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
"react/prop-types": [2, { ignore: ["children"]}], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
"react/react-in-jsx-scope": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MapStore 2 is a framework to build *web mapping* applications using standard map
MapStore 2 has several example applications:
* MapViewer is a simple viewer of preconfigured maps (optionally stored in a database using GeoStore)
* MapPublisher has been developed to create, save and share in a simple and intuitive way maps and mashups created selecting contents by server like OpenStreetMap, Google Maps, MapQuest or specific servers provided by your organization or third party.

For more information check the [MapStore documentation](https://dev.mapstore2.geo-solutions.it/mapstore/docs/).

Download
Expand Down Expand Up @@ -84,7 +84,9 @@ Install latest Maven, if needed, from [here](https://maven.apache.org/download.c

Build the deployable war:

`./build.sh`
`./build.sh [version_identifier]`

Where version_identifier is an optional identifier of the generated war that will be shown in the settings panel of the application.

Deploy the generated mapstore.war file (in web/target) to your favourite J2EE container (e.g. Tomcat).

Expand Down
8 changes: 7 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ npm run cleandoc
npm run lint
npm test
npm run doc
mvn clean install
if [ $# -eq 0 ]
then
mvn clean install
else
mvn clean install -Dmapstore2.version=$1
fi

npm run cleandoc
18 changes: 10 additions & 8 deletions docs/developer-guide/building-and-developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ Maven is the main tool for building and deploying a complete application. It tak
To create the final war, you have several options:
* full build, including submodules and frontend (e.g. GeoStore)

`./build.sh`
`./build.sh [version_identifier]`

Where version_identifier is an optional identifier of the generated war that will be shown in the settings panel of the application.

* fast build (will use the last compiled version of submodules and compiled frontend)

`mvn clean install`
`mvn clean install` -Dmapstore2.version=[version_identifier]

### Changelog generation

Expand All @@ -129,22 +131,22 @@ sudo gem install github_changelog_generator
```

**Configure**
* [Generate a github token](https://github.com/settings/tokens/new?description=GitHub%20Changelog%20Generator%20token) and place it in your .bashrc this:
* [Generate a github token](https://github.com/settings/tokens/new?description=GitHub%20Changelog%20Generator%20token) and place it in your .bashrc this:
```
export CHANGELOG_GITHUB_TOKEN="«your-40-digit-github-token»"
export CHANGELOG_GITHUB_TOKEN="«your-40-digit-github-token»"
```
as an alternative use --token

* cd to MapStore2
* edit `.github_changelog_generator` file :
* set `since-tag ` (the first tag you want to exclude)
* edit `.github_changelog_generator` file :
* set `since-tag ` (the first tag you want to exclude)
* if you are creating the changelog before creating the tag set `future-release`=YYYY.NN.mm with the release tag

For example the `.github_changelog_generator` file for the changes between 2017.02.00 and 2017.03.00 release can look like the following:

future-release=2017.03.00
since-tag=2017.01.00

**Run**
```
github_changelog_generator
Expand Down
4 changes: 3 additions & 1 deletion docs/developer-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Install latest Maven, if needed, from [here](https://maven.apache.org/download.c

Build the deployable war:

`./build.sh`
`./build.sh [version_identifier]`

Where version_identifier is an optional identifier of the generated war that will be shown in the settings panel of the application.

Deploy the generated mapstore.war file (in web/target) to your favourite J2EE container (e.g. Tomcat).

Expand Down
36 changes: 36 additions & 0 deletions web/client/actions/__tests__/version-test.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.
*/

var expect = require('expect');
var {
CHANGE_VERSION,
changeVersion,
loadVersion
} = require('../version');

describe('Test correctness of the version actions', () => {

it('change version', () => {
const action = changeVersion('version');
expect(action.type).toBe(CHANGE_VERSION);
expect(action.version).toBe('version');
});

it('load version', (done) => {
loadVersion('base/web/client/test-resources/testVersion.txt')((a) => {
try {
expect(a).toExist();
expect(a.type).toBe(CHANGE_VERSION);
expect(a.version.indexOf('myVersion')).toBe(0);
done();
} catch(ex) {
done(ex);
}
});
});
});
57 changes: 57 additions & 0 deletions web/client/actions/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 axios = require('../libs/ajax');

const CHANGE_VERSION = 'CHANGE_VERSION';
const LOAD_VERSION_ERROR = 'LOAD_VERSION_ERROR';

/**
* updates the version identifier of the application
* @memberof actions.version
* @param {string} version new version to be set
*/
function changeVersion(version) {
return {
type: CHANGE_VERSION,
version
};
}

/**
* error in loading version file
* @memberof actions.version
* @param {object} e error description
*/
function loadVersionError(e) {
return {
type: LOAD_VERSION_ERROR,
error: e
};
}
/**
* loads a version identifier from the given url
* @memberof actions.version
* @param {string} config ['version.txt'] url of the (text) file to load the version identifier from
*/
function loadVersion(config = 'version.txt') {
return (dispatch) => {
return axios.get(config).then((response) => {
dispatch(changeVersion(response.data));
}).catch((e) => {
dispatch(loadVersionError(e));
});
};
}

/**
* Actions for version
* @name actions.version
*/
module.exports = {CHANGE_VERSION, LOAD_VERSION_ERROR,
loadVersion, loadVersionError, changeVersion};
4 changes: 2 additions & 2 deletions web/client/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"cfg": {
"tools": ["locate"]
}
}, "DrawerMenu", {
}, "Version", "DrawerMenu", {
"name": "Identify",
"showIn": ["Settings"],
"cfg": {
Expand Down Expand Up @@ -111,7 +111,7 @@
}, "Login",
"OmniBar", "BurgerMenu", "Expander", "GlobeViewSwitcher"
],
"desktop": ["Map", "HelpLink", "Share", "DrawerMenu", {
"desktop": ["Map", "HelpLink", "Share", "DrawerMenu", "Version", {
"name": "Identify",
"showIn": ["IdentifyBar", "Settings"],
"cfg": {
Expand Down
55 changes: 55 additions & 0 deletions web/client/plugins/Version.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 React = require('react');
const {connect} = require('react-redux');

const Message = require('../components/I18N/Message');

/**
* Version Plugin. Shows current MapStore2 version
* @class Version
* @memberof plugins
* @static
*
*/
const Version = connect((state) => ({
version: state.version && state.version.current
}))(React.createClass({
propTypes: {
version: React.PropTypes.string
},
getDefaultProps() {
return {
version: 'DEV'
};
},
render() {
return <span className="application-version"><span className="application-version-label"><Message msgId="version.label"/></span>: {this.props.version}</span>;
}
}));

const assign = require('object-assign');

const Empty = React.createClass({
render() {
return null;
}
});

module.exports = {
VersionPlugin: assign(Empty, {
Settings: {
tool: <Version/>,
position: 4
}
}),
reducers: {
version: require('../reducers/version')
}
};
4 changes: 3 additions & 1 deletion web/client/product/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const startApp = () => {
const ConfigUtils = require('../utils/ConfigUtils');

const {loadMaps} = require('../actions/maps');
const {loadVersion} = require('../actions/version');

const StandardApp = require('../components/app/StandardApp');

Expand All @@ -30,7 +31,8 @@ const startApp = () => {
}, {});

const initialActions = [
() => loadMaps(ConfigUtils.getDefaults().geoStoreUrl, ConfigUtils.getDefaults().initialMapFilter || "*")
() => loadMaps(ConfigUtils.getDefaults().geoStoreUrl, ConfigUtils.getDefaults().initialMapFilter || "*"),
loadVersion
];

const appConfig = {
Expand Down
3 changes: 2 additions & 1 deletion web/client/product/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ module.exports = {
ThemeSwitcherPlugin: require('../plugins/ThemeSwitcher'),
ScrollTopPlugin: require('../plugins/ScrollTop'),
GoFull: require('../plugins/GoFull'),
GlobeViewSwitcherPlugin: require('../plugins/GlobeViewSwitcher')
GlobeViewSwitcherPlugin: require('../plugins/GlobeViewSwitcher'),
VersionPlugin: require('../plugins/Version')
},
requires: {
ReactSwipe: require('react-swipeable-views').default,
Expand Down
18 changes: 18 additions & 0 deletions web/client/reducers/__tests__/version-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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');

var version = require('../version');


describe('Test the version reducer', () => {
it('changes the current version', () => {
var state = version({}, {type: 'CHANGE_VERSION', version: 'myVersion'});
expect(state.current).toBe('myVersion');
});
});
36 changes: 36 additions & 0 deletions web/client/reducers/version.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 { CHANGE_VERSION } = require('../actions/version');
const assign = require('object-assign');

/**
* Manages the state of the version identifier
* @prop {string} current version identifier
*
* @example
*{
* current: '2017.00.04'
*}
* @memberof reducers
*/
function version(state = null, action) {
switch (action.type) {
case CHANGE_VERSION: {
return assign({}, state,
{
current: action.version
}
);
}
default:
return state;
}
}

module.exports = version;
1 change: 1 addition & 0 deletions web/client/test-resources/testVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
myVersion
4 changes: 4 additions & 0 deletions web/client/themes/default/ms2-theme.less
Original file line number Diff line number Diff line change
Expand Up @@ -1024,3 +1024,7 @@ select.form-control option {
.tooltip {
z-index: 10000;
}

.application-version-label {
font-weight: bold;
}
3 changes: 3 additions & 0 deletions web/client/translations/data.de-DE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"enable": "Aktiviere",
"layers": "Ebenen",
"warning": "Warnung",
"version": {
"label": "Version"
},
"layerProperties": {
"windowTitle": "Ebenen Eigenschaften",
"title": "Titel",
Expand Down
3 changes: 3 additions & 0 deletions web/client/translations/data.en-US
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"enable": "Enable",
"layers": "Layers",
"warning": "Warning",
"version": {
"label": "Version"
},
"layerProperties": {
"windowTitle": "Layer Properties",
"title": "Title",
Expand Down
3 changes: 3 additions & 0 deletions web/client/translations/data.fr-FR
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"enable": "Activer",
"layers": "Couches",
"warning": "Attention",
"version": {
"label": "Version"
},
"layerProperties": {
"windowTitle": "Propriétés de la couche",
"title": "Titre",
Expand Down
Loading

0 comments on commit 7183c93

Please sign in to comment.