diff --git a/docma-config.json b/docma-config.json index 98a1cf617b..855584b94b 100644 --- a/docma-config.json +++ b/docma-config.json @@ -108,6 +108,7 @@ "framework" : [ "web/client/components/index.jsdoc", "web/client/components/buttons/FullScreenButton.jsx", + "web/client/components/buttons/GoFullButton.jsx", "web/client/components/mapcontrols/search/SearchBar.jsx", "web/client/components/buttons/ToggleButton.jsx", @@ -131,6 +132,7 @@ "plugins": [ "web/client/plugins/index.jsdoc", "web/client/plugins/BackgroundSwitcher.jsx", + "web/client/plugins/GoFull.jsx", "web/client/plugins/Map.jsx", "web/client/plugins/FullScreen.jsx", "web/client/plugins/Identify.jsx", diff --git a/web/client/api.html b/web/client/api.html index e9111e6082..e1b6199667 100644 --- a/web/client/api.html +++ b/web/client/api.html @@ -32,7 +32,9 @@ diff --git a/web/client/components/buttons/GoFullButton.jsx b/web/client/components/buttons/GoFullButton.jsx new file mode 100644 index 0000000000..baa076cadd --- /dev/null +++ b/web/client/components/buttons/GoFullButton.jsx @@ -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 (}> + + ); + }, + 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; diff --git a/web/client/components/buttons/__tests__/GoFullButton-test.jsx b/web/client/components/buttons/__tests__/GoFullButton-test.jsx new file mode 100644 index 0000000000..4bf41ecafc --- /dev/null +++ b/web/client/components/buttons/__tests__/GoFullButton-test.jsx @@ -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 = '
'; + setTimeout(done); + }); + + afterEach((done) => { + ReactDOM.unmountComponentAtNode(document.getElementById("container")); + document.body.innerHTML = ''; + setTimeout(done); + }); + + it('test not showing', () => { + const tb = ReactDOM.render(, 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(, 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(, document.getElementById("container")); + expect(tb).toExist(); + expect(tb.generateUrl()).toBe(href); + const tbNode = ReactDOM.findDOMNode(tb); + expect(tbNode).toExist(); + }); +}); diff --git a/web/client/components/share/ShareApi.jsx b/web/client/components/share/ShareApi.jsx index aa03d3778b..f453d72830 100644 --- a/web/client/components/share/ShareApi.jsx +++ b/web/client/components/share/ShareApi.jsx @@ -35,7 +35,8 @@ const ShareApi = React.createClass({ render() { const parsedCode = codeApi .replace('__BASE__URL__', this.props.shareUrl) - .replace('__CONFIG__URL__', this.props.shareConfigUrl); + .replace('__CONFIG__URL__', this.props.shareConfigUrl) + .replace('__ORIGINAL_URL__', location.href); const tooltip = ( {this.state.copied ? : } ); diff --git a/web/client/components/share/api-template.raw b/web/client/components/share/api-template.raw index 20705bc328..a82cd0990c 100644 --- a/web/client/components/share/api-template.raw +++ b/web/client/components/share/api-template.raw @@ -33,7 +33,8 @@ diff --git a/web/client/epics/__tests__/search-test.js b/web/client/epics/__tests__/search-test.js index 92682eeb42..8c05136fa2 100644 --- a/web/client/epics/__tests__/search-test.js +++ b/web/client/epics/__tests__/search-test.js @@ -192,6 +192,6 @@ describe('search Epics', () => { done(); // setting 0 as delay arises script error - }, 100); + }, 300); }); }); diff --git a/web/client/jsapi/MapStore2.js b/web/client/jsapi/MapStore2.js index 96763624fe..ea7cd6f3c1 100644 --- a/web/client/jsapi/MapStore2.js +++ b/web/client/jsapi/MapStore2.js @@ -138,7 +138,8 @@ const defaultPlugins = { "Expander", "Undo", "Redo", - "FullScreen" + "FullScreen", + "GoFull" ] }; @@ -228,6 +229,7 @@ const MapStore2 = { * look at [Plugins documentation](./plugins-documentation) for further details * * **config**: map configuration object for the application (look at [Map Configuration](./maps-configuration) for details) * * **configUrl**: map configuration url for the application (look at [Map Configuration](./maps-configuration) for details) + * * **originalUrl**: url of the original instance of MapStore. If present it will be linked inside the map using the "GoFull" plugin, present by default. * * **initialState**: allows setting the initial application state (look at [State Configuration](./app-state-configuration) for details) * * Styling can be configured either using a **theme**, or a complete custom **less stylesheet**, using the @@ -328,6 +330,9 @@ const MapStore2 = { if (options.translations) { ConfigUtils.setConfigProp('translationsPath', options.translations); } + if (options.originalUrl) { + ConfigUtils.setConfigProp('originalUrl', options.originalUrl); + } ReactDOM.render(, document.getElementById(container)); }, buildPluginsCfg, diff --git a/web/client/plugins/GoFull.jsx b/web/client/plugins/GoFull.jsx new file mode 100644 index 0000000000..b2600032b5 --- /dev/null +++ b/web/client/plugins/GoFull.jsx @@ -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: {} +}; diff --git a/web/client/product/apiPlugins.js b/web/client/product/apiPlugins.js index e6c6f2268e..ccdd935ba0 100644 --- a/web/client/product/apiPlugins.js +++ b/web/client/product/apiPlugins.js @@ -18,6 +18,7 @@ module.exports = { LocatePlugin: require('../plugins/Locate'), ZoomAllPlugin: require('../plugins/ZoomAll'), MapLoadingPlugin: require('../plugins/MapLoading'), + GoFullPlugin: require('../plugins/GoFull'), OmniBarPlugin: require('../plugins/OmniBar') }, requires: { diff --git a/web/client/product/plugins.js b/web/client/product/plugins.js index 896e8dc01d..e134cd01c7 100644 --- a/web/client/product/plugins.js +++ b/web/client/product/plugins.js @@ -64,7 +64,8 @@ module.exports = { FeatureGridPlugin: require('../plugins/FeatureGrid'), TutorialPlugin: require('../plugins/Tutorial'), ThemeSwitcherPlugin: require('../plugins/ThemeSwitcher'), - ScrollTopPlugin: require('../plugins/ScrollTop') + ScrollTopPlugin: require('../plugins/ScrollTop'), + GoFull: require('../plugins/GoFull') }, requires: { ReactSwipe: require('react-swipeable-views').default, diff --git a/web/client/product/pluginsEmbedded.js b/web/client/product/pluginsEmbedded.js index 37f5170b82..940d10afc3 100644 --- a/web/client/product/pluginsEmbedded.js +++ b/web/client/product/pluginsEmbedded.js @@ -18,6 +18,7 @@ module.exports = { LocatePlugin: require('../plugins/Locate'), ZoomAllPlugin: require('../plugins/ZoomAll'), MapLoadingPlugin: require('../plugins/MapLoading'), + GoFullPlugin: require('../plugins/GoFull'), OmniBarPlugin: require('../plugins/OmniBar') }, requires: { diff --git a/web/client/translations/data.de-DE b/web/client/translations/data.de-DE index 6b98578ee0..37f0f6b423 100644 --- a/web/client/translations/data.de-DE +++ b/web/client/translations/data.de-DE @@ -355,7 +355,8 @@ }, "fullscreen": { "tooltipActivate": "Umschalten auf Vollbild", - "tooltipDeactivate": "Vollbild verlassen" + "tooltipDeactivate": "Vollbild verlassen", + "viewLargerMap": "Größere Karte ansehen" }, "helptexts": { "scaleBox": "Das ist die Hilfe für die ScaleBox", diff --git a/web/client/translations/data.en-US b/web/client/translations/data.en-US index 5c7588f28a..2a857a540f 100644 --- a/web/client/translations/data.en-US +++ b/web/client/translations/data.en-US @@ -355,7 +355,8 @@ }, "fullscreen": { "tooltipActivate": "Switch to Full Screen", - "tooltipDeactivate": "Exit full screen" + "tooltipDeactivate": "Exit full screen", + "viewLargerMap": "View Larger Map" }, "helptexts": { "scaleBox": "This is the helptext for the ScaleBox", diff --git a/web/client/translations/data.fr-FR b/web/client/translations/data.fr-FR index 743ebdc9b7..5b5537f053 100644 --- a/web/client/translations/data.fr-FR +++ b/web/client/translations/data.fr-FR @@ -357,7 +357,8 @@ }, "fullscreen": { "tooltipActivate": "Basculer en plein écran", - "tooltipDeactivate": "Quitter plein écran" + "tooltipDeactivate": "Quitter plein écran", + "viewLargerMap": "Agrandir le plan" }, "helptexts": { "scaleBox": "This is the helptext for the ScaleBox", diff --git a/web/client/translations/data.it-IT b/web/client/translations/data.it-IT index b76171d5f7..a4ed55acd4 100644 --- a/web/client/translations/data.it-IT +++ b/web/client/translations/data.it-IT @@ -355,7 +355,8 @@ }, "fullscreen": { "tooltipActivate": "Passa a schermo intero", - "tooltipDeactivate": "Esci da schermo intero" + "tooltipDeactivate": "Esci da schermo intero", + "viewLargerMap": "Visualizza mappa più grande" }, "helptexts": { "scaleBox": "Questo è il testo di aiuto per ScaleBox",