Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit df8845d

Browse files
authored
118 show current map url (#123)
* Add component to show the current map url; show the url for the saved map when it has an id * Use MapTitle as link title, use Paper from material-ui
1 parent 4a6f461 commit df8845d

File tree

11 files changed

+121
-4
lines changed

11 files changed

+121
-4
lines changed

src/components/geonode.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import enMessages from 'boundless-sdk/locale/en.js';
2323
global.enMessages = enMessages;
2424

2525
import Save from './save';
26+
import MapUrlLink from '../containers/MapUrlLink';
2627

2728
import '../css/app.css'
2829
import 'boundless-sdk/dist/css/components.css';
@@ -109,14 +110,15 @@ class GeoNodeViewer extends React.Component {
109110
onRequestClose={this._handleRequestClose.bind(this)}
110111
/>);
111112
}
112-
let layerList, save = undefined;
113+
let layerList, save, mapUrl;
113114
if(this.edit) {
114115
layerList = {
115116
sources: this.props.addLayerSources,
116117
allowUserInput: true
117118
};
118119
if(this.props.server) {
119120
save = (<div id='save-button' className='geonode-save'><Save map={map} /></div>);
121+
mapUrl = (<MapUrlLink />);
120122
}
121123
}
122124
return (
@@ -131,6 +133,7 @@ class GeoNodeViewer extends React.Component {
131133
<div id='rotate-button'><Rotate autoHide={true} tooltipPosition='right' map={map} /></div>
132134
<div id='popup' className='ol-popup'><InfoPopup toggleGroup='navigation' toolId='nav' infoFormat='application/vnd.ogc.gml' map={map} /></div>
133135
{save}
136+
{mapUrl}
134137
</div>
135138
);
136139
}

src/components/mapUrl.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import Paper from 'material-ui/Paper'
3+
import muiThemeable from 'material-ui/styles/muiThemeable';
4+
5+
export class MapUrl extends React.Component {
6+
render() {
7+
const showHideClass = this.props.show ? '' : 'hide';
8+
const content=[(<a key="link" href={this.props.url} className='map-url'>{this.props.text}</a>)];
9+
const style = {
10+
background: this.props.muiTheme.palette.primary1Color,
11+
color: this.props.muiTheme.palette.alternateTextColor,
12+
padding: '5px'
13+
}
14+
return (
15+
<Paper className={'map-url-wrapper ' + showHideClass} children={content} style={style}/>
16+
)
17+
}
18+
}
19+
MapUrl.propTypes = {
20+
url: React.PropTypes.string.isRequired,
21+
text: React.PropTypes.string.isRequired,
22+
show: React.PropTypes.bool
23+
}
24+
MapUrl.contextTypes = {
25+
muiTheme: React.PropTypes.object
26+
};
27+
export default muiThemeable()(MapUrl);

src/constants/server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const NEW_MAP_ENDPOINT = '/maps/new/data';
2+
export const VIEW_MAP_ENDPOINT = '/maps/';
3+
4+
export const edit_map_endpoint = (id) => {
5+
return `/maps/${id}/data`;
6+
};

src/containers/MapUrlLink.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {connect} from 'react-redux';
2+
import MapUrl from '../components/mapUrl';
3+
import {getMapId, getMapViewUrl} from '../state/map/selectors';
4+
import {getMapTitle} from '../state/mapConfig/selectors';
5+
6+
const mapStateToProps = (state) => {
7+
return {
8+
url: getMapViewUrl(state),
9+
show: getMapId(state) ? true : false,
10+
text: getMapTitle(state) || ''
11+
};
12+
};
13+
14+
const MapUrlLink = connect(
15+
mapStateToProps
16+
)(MapUrl);
17+
18+
export default MapUrlLink;

src/css/app.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ html, body {
7272
.layer-tree-panel {
7373
max-height: 94vh !important;
7474
}
75+
.map-url-wrapper {
76+
position: absolute;
77+
top: 0;
78+
width: 50%;
79+
left: 25%;
80+
height: 25px;
81+
text-align: center;
82+
}
83+
.map-url-wrapper.hide {
84+
display: none;
85+
}
86+
.map-url-wrapper a {
87+
padding: 10px;
88+
color: #fff;
89+
font-size: 0.8em;
90+
}
7591
#debug {
7692
position: absolute;
7793
top: 0;

src/services/geonode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import MapConfigTransformService from 'boundless-sdk/services/MapConfigTransformService';
22
import MapConfigService from 'boundless-sdk/services/MapConfigService';
33
import {getCRSFToken, removeTrailingSlash} from '../helper';
4-
const NEW_MAP_ENDPOINT = '/maps/new/data';
4+
import {edit_map_endpoint, NEW_MAP_ENDPOINT} from '../constants/server'
55

66
import 'whatwg-fetch';
77

@@ -17,7 +17,7 @@ const createRequestObject = function(method, body) {
1717
};
1818
};
1919
const saveEndPoint = (id = undefined) => {
20-
return id ? `/maps/${id}/data` : NEW_MAP_ENDPOINT;
20+
return id ? edit_map_endpoint(id) : NEW_MAP_ENDPOINT;
2121
};
2222
const saveMethod = (id = undefined) => {
2323
return id ? 'PUT' : 'POST';

src/state/map/selectors.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import {getServerUrl} from '../server/selectors'
2+
import {removeTrailingSlash} from '../../helper';
3+
import {VIEW_MAP_ENDPOINT} from '../../constants/server';
14

25
function isError(state) {
36
return (state.map.save.error && !state.map.save.success) ? true : false;
@@ -17,3 +20,6 @@ export function errorMessage(state) {
1720
export function getMapId(state) {
1821
return state.map.id;
1922
}
23+
export function getMapViewUrl(state) {
24+
return `${removeTrailingSlash(getServerUrl(state))}${VIEW_MAP_ENDPOINT}${getMapId(state)}`;
25+
}

src/state/server/selectors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function getServerUrl(state) {
2+
return state.server.url;
3+
}

tests/components/mapUrl.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {MapUrl} from '../../src/components/mapUrl';
2+
import {shallowRender, shallowRenderOutput } from '../testhelper';
3+
import ReactTestUtils from 'react-addons-test-utils';
4+
5+
describe('mapUrl', () => {
6+
let mapUrlComponent, url, muiTheme;
7+
beforeEach(function() {
8+
url = 'http://geonode.org';
9+
muiTheme = { palette: { primary1Color: '', alternateTextColor: ''}};
10+
mapUrlComponent = shallowRenderOutput( <MapUrl text='Test' url={url} muiTheme={muiTheme}/> );
11+
});
12+
it('exists', () => {
13+
mapUrlComponent = shallowRender( <MapUrl muiTheme={muiTheme} url='' text=''/> );
14+
assert.isDefined(ReactTestUtils.isCompositeComponent(mapUrlComponent));
15+
});
16+
it('has a link with class map-url', () => {
17+
const urlWrapper = mapUrlComponent.props.children[0];
18+
assert.equal(urlWrapper.props.className, 'map-url');
19+
});
20+
it('has the correct link', () => {
21+
const urlWrapper = mapUrlComponent.props.children[0];
22+
assert.equal(urlWrapper.props.href, url);
23+
});
24+
});

tests/state/map/selectors.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isSaving, success, error, errorMessage} from '../../../src/state/map/selectors';
1+
import {isSaving, success, error, errorMessage, getMapId, getMapViewUrl} from '../../../src/state/map/selectors';
22

33
describe('mapSelectors', () => {
44
describe('#isSaving', () => {
@@ -74,4 +74,9 @@ describe('mapSelectors', () => {
7474
});
7575
});
7676
});
77+
describe('#getMapViewUrl', () => {
78+
it('returns the url', () => {
79+
assert.equal(getMapViewUrl({map: {id: 1},server: {url: 'http://geonode.org'}}), 'http://geonode.org/maps/1');
80+
});
81+
});
7782
});

0 commit comments

Comments
 (0)