-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
GoFull plugins autoshows when originalUrl is present in config (JsAPI use case) or when the url match with a regex (embedded iframe use case). In both cases it opens MapStore full in a new tab (using originalUrl or parsing the current href to create the url to open. * Externalized component and add tests * made also search epic test more rubust
- Loading branch information
1 parent
ab81b0e
commit f7437a4
Showing
16 changed files
with
187 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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 {Button, Glyphicon, Tooltip} = require('react-bootstrap'); | ||
const OverlayTrigger = require('../misc/OverlayTrigger'); | ||
const Message = require('../I18N/Message'); | ||
|
||
const ConfigUtils = require('../../utils/ConfigUtils'); | ||
/** | ||
* Button for Go to Full MapStore2. | ||
* @prop {string} cfg.glyph the glyph icon for the button | ||
* @prop {string} cfg.tooltip messageId of the tooltip to use | ||
* @prop {string} cfg.urlRegex. A regex to parse the current location.href. This regex must match if the originalUrl is not defined. | ||
* @prop {string} cfg.urlReplaceString. The template to create the url link. Uses the `urlRegex` groups to create the final URL | ||
* @memberof components.buttons | ||
* @class | ||
*/ | ||
const GoFullButton = React.createClass({ | ||
propTypes: { | ||
glyph: React.PropTypes.string, | ||
tooltip: React.PropTypes.string, | ||
urlRegex: React.PropTypes.string, | ||
urlReplaceString: React.PropTypes.string, | ||
originalUrl: React.PropTypes.string | ||
}, | ||
getDefaultProps() { | ||
return { | ||
glyph: "share", | ||
tooltip: "fullscreen.viewLargerMap", | ||
urlRegex: "^(.*?)embedded.html.*?#\\/(\\d?)", | ||
urlReplaceString: "$1#/viewer/leaflet/$2" | ||
}; | ||
}, | ||
|
||
render() { | ||
if (!this.display()) return null; | ||
return (<OverlayTrigger placement="left" overlay={<Tooltip id="gofull-tooltip"><Message msgId={this.props.tooltip}/></Tooltip>}> | ||
<Button className="square-button" bsStyle="primary" onClick={() => this.openFull(this.generateUrl())}> | ||
<Glyphicon glyph={this.props.glyph}/> | ||
</Button> | ||
</OverlayTrigger>); | ||
}, | ||
display() { | ||
let regex = this.generateRegex(); | ||
return this.props.originalUrl || ConfigUtils.getConfigProp("originalUrl") || location.href.match(regex); | ||
}, | ||
openFull(url) { | ||
if (url) { | ||
window.open(url, '_blank'); | ||
} | ||
}, | ||
generateRegex() { | ||
return new RegExp(this.props.urlRegex); | ||
}, | ||
|
||
generateUrl() { | ||
let orig = this.props.originalUrl || ConfigUtils.getConfigProp("originalUrl"); | ||
if (orig) { | ||
return orig; | ||
} | ||
let regex = this.generateRegex(); | ||
if (location.href.match(regex)) { | ||
let next = location.href; | ||
return next.replace(regex, this.props.urlReplaceString); | ||
} | ||
} | ||
}); | ||
|
||
module.exports = GoFullButton; |
46 changes: 46 additions & 0 deletions
46
web/client/components/buttons/__tests__/GoFullButton-test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* 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 React = require('react'); | ||
var ReactDOM = require('react-dom'); | ||
var GoFullButton = require('../GoFullButton'); | ||
|
||
describe("test the GoFullButton", () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
|
||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
|
||
it('test not showing', () => { | ||
const tb = ReactDOM.render(<GoFullButton/>, document.getElementById("container")); | ||
expect(tb).toExist(); | ||
const tbNode = ReactDOM.findDOMNode(tb); | ||
expect(tbNode).toNotExist(); | ||
}); | ||
it('test showing on originalUrl property set', () => { | ||
const tb = ReactDOM.render(<GoFullButton originalUrl={"TEST"}/>, document.getElementById("container")); | ||
expect(tb).toExist(); | ||
const tbNode = ReactDOM.findDOMNode(tb); | ||
expect(tbNode).toExist(); | ||
}); | ||
it('test showing on regex match', () => { | ||
const href = location.href; | ||
const tb = ReactDOM.render(<GoFullButton urlRegex={"(.*)"} urlReplaceString={"$1"}/>, document.getElementById("container")); | ||
expect(tb).toExist(); | ||
expect(tb.generateUrl()).toBe(href); | ||
const tbNode = ReactDOM.findDOMNode(tb); | ||
expect(tbNode).toExist(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,6 @@ describe('search Epics', () => { | |
|
||
done(); | ||
// setting 0 as delay arises script error | ||
}, 100); | ||
}, 300); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 {connect} = require('react-redux'); | ||
|
||
/** | ||
* GoFull plugin. Shows a button that opens full MapStore2 in a new tab. Try to find the `originalUrl` in configuration or tries to guess the mapId and creates the proper URL. | ||
* This plugins hides automatically if the originalUrl is not present in configuration and if the urlRegex do not match. | ||
* @prop {string} cfg.glyph the glyph icon for the button | ||
* @prop {string} cfg.tooltip messageId of the tooltip to use | ||
* @prop {string} cfg.urlRegex. A regex to parse the current location.href. This regex must match if the originalUrl is not defined. | ||
* @prop {string} cfg.urlReplaceString. The template to create the url link. Uses the `urlRegex` groups to create the final URL | ||
* @memberof plugins | ||
* @class GoFull | ||
*/ | ||
const GoFullPlugin = connect(() => ({}))(require('../components/buttons/GoFullButton')); | ||
|
||
const assign = require('object-assign'); | ||
|
||
|
||
module.exports = { | ||
GoFullPlugin: assign(GoFullPlugin, { | ||
Toolbar: { | ||
name: 'gofull', | ||
position: 1, | ||
toolStyle: "primary", | ||
tooltip: "fullscreen.viewLargerMap", | ||
tool: true, | ||
priority: 1 | ||
} | ||
}), | ||
reducers: {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters