Skip to content

Commit

Permalink
Fixes #2542 Custom template for GetFeatureInfo (#2591)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored and offtherailz committed Feb 21, 2018
1 parent b7aa476 commit 283d06f
Show file tree
Hide file tree
Showing 85 changed files with 4,347 additions and 493 deletions.
9 changes: 9 additions & 0 deletions docma-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
"web/client/components/mapcontrols/mouseposition/MousePosition.jsx",
"web/client/components/notifications/NotificationContainer.jsx",
"web/client/components/buttons/ToggleButton.jsx",
"web/client/components/data/identify/GeocodeViewer.jsx",
"web/client/components/data/identify/IdentifyContainer.jsx",
"web/client/components/data/query/AutocompleteField.jsx",
"web/client/components/map/leaflet/DrawSupport.jsx",
"web/client/components/plugins/PluginsContainer.jsx",
Expand All @@ -120,10 +122,17 @@
"web/client/components/mapcontrols/annotations/AnnotationsConfig.js",
"web/client/components/misc/enhancers/emptyState.jsx",
"web/client/components/misc/enhancers/tooltip.jsx",
"web/client/components/misc/panels/Accordion.jsx",
"web/client/components/misc/panels/DockablePanel.jsx",
"web/client/components/misc/panels/DockPanel.jsx",
"web/client/components/misc/panels/PanelHeader.jsx",
"web/client/components/misc/sidebar/Sidebar.jsx",
"web/client/components/misc/toolbar/Toolbar.jsx",
"web/client/components/misc/EmptyView.jsx",
"web/client/components/misc/ResizableModal.jsx",
"web/client/components/TOC/TOCItemsSettings.jsx",
"web/client/components/TOC/fragments/settings/FeatureInfo.jsx",
"web/client/components/TOC/fragments/settings/FeatureInfoEditor.jsx",

"web/client/actions/index.jsdoc",
"web/client/actions/controls.js",
Expand Down
2 changes: 1 addition & 1 deletion web/client/actions/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function getFeatureInfo(basePath, requestParams, lMetaData, options = {}) {
dispatch(loadFeatureInfo(reqId, response.data, requestParams, lMetaData));
}
}).catch((e) => {
dispatch(errorFeatureInfo(reqId, e, requestParams, lMetaData));
dispatch(errorFeatureInfo(reqId, e.data || e.statusText || e.status, requestParams, lMetaData));
});
};
}
Expand Down
144 changes: 144 additions & 0 deletions web/client/components/TOC/TOCItemsSettings.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright 2018, 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 {Row, Col, Nav, NavItem, Glyphicon} = require('react-bootstrap');
const DockablePanel = require('../misc/panels/DockablePanel');
const Toolbar = require('../misc/toolbar/Toolbar');
const tooltip = require('../misc/enhancers/tooltip');
const NavItemT = tooltip(NavItem);
const ResizableModal = require('../misc/ResizableModal');
const Portal = require('../misc/Portal');
const {head, isObject} = require('lodash');
const Message = require('../I18N/Message');

/**
* Component for rendering TOC Settings as tabs inside a Dockable contanier
* @memberof components.TOC
* @name TOCItemsSettings
* @class
* @prop {boolean} dock switch between Dockable Panel and Resizable Modal, default true (DockPanel)
* @prop {string} activeTab current active tab, should match the tab id
* @prop {function} getTabs must return an array of object representing the tabs, eg (props) => [{ id: 'general', Component: MyGeneralComponent}]
* @prop {string} className additional calss name
*/

module.exports = props => {
const {
className = '',
activeTab = 'general',
currentLocale = 'en-US',
width = 500,
groups = [],
element = {},
settings = {},
getTabs = () => [],
onSave = () => {},
onClose = () => {},
onHideSettings = () => {},
onSetTab = () => {},
onUpdateParams = () => {},
onRetrieveLayerData = () => {},
onShowAlertModal = () => {},
realtimeUpdate = true,
alertModal = false,
dockStyle = {},
dock = true,
showFullscreen,
draggable,
position = 'left'
} = props;

const tabs = getTabs(props);

return (
<div>
<DockablePanel
open={settings.expanded}
glyph="wrench"
title={element.title && isObject(element.title) && (element.title[currentLocale] || element.title.default) || element.title || ''}
className={className}
onClose={onClose ? () => { onClose(); } : onHideSettings}
size={width}
style={dockStyle}
showFullscreen={showFullscreen}
dock={dock}
draggable={draggable}
position={position}
header={[
<Row key="ms-toc-settings-toolbar" className="text-center">
<Col xs={12}>
<Toolbar
btnDefaultProps={{ bsStyle: 'primary', className: 'square-button-md' }}
buttons={[{
glyph: 'floppy-disk',
tooltipId: 'save',
visible: !!onSave,
onClick: onSave
},
...(head(tabs.filter(tab => tab.id === activeTab && tab.toolbar).map(tab => tab.toolbar)) || [])]}/>
</Col>
</Row>,
...(tabs.length > 1 ? [<Row key="ms-toc-settings-navbar" className="ms-row-tab">
<Col xs={12}>
<Nav bsStyle="tabs" activeKey={activeTab} justified>
{tabs.map(tab =>
<NavItemT
key={'ms-tab-settings-' + tab.id}
tooltip={<Message msgId={tab.tooltipId}/> }
eventKey={tab.id}
onClick={() => onSetTab(tab.id)}>
<Glyphicon glyph={tab.glyph}/>
</NavItemT>
)}
</Nav>
</Col>
</Row>] : [])
]}>
{tabs.filter(tab => tab.id && tab.id === activeTab).filter(tab => tab.Component).map(tab => (
<tab.Component
{...props}
key={'ms-tab-settings-body-' + tab.id}
containerWidth={width}
element={element}
groups={groups}
nodeType={settings.nodeType}
settings={settings}
retrieveLayerData={onRetrieveLayerData}
onChange={(key, value) => onUpdateParams({[key]: value}, realtimeUpdate)}/>
))}
</DockablePanel>
<Portal>
<ResizableModal
fade
show={alertModal}
title={<Message msgId="layerProperties.changedSettings"/>}
size="xs"
onClose={() => onShowAlertModal(false)}
buttons={[
{
bsStyle: 'primary',
text: <Message msgId="close"/>,
onClick: () => onClose(true)
},
{
bsStyle: 'primary',
text: <Message msgId="save"/>,
onClick: onSave
}
]}>
<div className="ms-alert">
<div className="ms-alert-center">
<Message msgId="layerProperties.changedSettingsAlert"/>
</div>
</div>
</ResizableModal>
</Portal>
</div>
);
};
34 changes: 0 additions & 34 deletions web/client/components/TOC/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const {ButtonGroup, Button, Glyphicon, Tooltip, OverlayTrigger} = require('react
const ReactCSSTransitionGroup = require('react-addons-css-transition-group');
const {head} = require('lodash');
const ConfirmModal = require('../maps/modals/ConfirmModal');
const SettingsModal = require('./fragments/SettingsModal');
const GroupSettingsModal = require('./fragments/GroupSettingsModal');
const LayerMetadataModal = require('./fragments/LayerMetadataModal');

class Toolbar extends React.Component {
Expand Down Expand Up @@ -136,39 +134,8 @@ class Toolbar extends React.Component {
return status;
}

getSettingsModal = (status) => {
return status === 'LAYER' ?
(<SettingsModal
key="toolsettingsmodal"
options={this.props.options.modalOptions}
{...this.props.options.settingsOptions}
settings={this.props.settings}
element={this.props.selectedLayers[0]}
generalInfoFormat={this.props.generalInfoFormat}
retrieveLayerData={this.props.onToolsActions.onRetrieveLayerData}
updateSettings={this.props.onToolsActions.onUpdateSettings}
hideSettings={this.props.onToolsActions.onHideSettings}
updateNode={this.props.onToolsActions.onUpdate}
removeNode={this.props.onToolsActions.onRemove}
includeDeleteButton={this.props.activateTool.includeDeleteButtonInSettings}
chartStyle={this.props.style.chartStyle}
titleText={this.props.text.settingsText}
opacityText={this.props.text.opacityText}
elevationText={this.props.text.elevationText}
saveText={this.props.text.saveText}
closeText={this.props.text.closeText}
groups={this.props.groups}/>)
: <GroupSettingsModal
element={this.props.selectedGroups[this.props.selectedGroups.length - 1]}
settings={this.props.settings}
updateNode={this.props.onToolsActions.onUpdate}
updateSettings={this.props.onToolsActions.onUpdateSettings}
hideSettings={this.props.onToolsActions.onHideSettings}/>;
}

render() {
const status = this.getStatus();
const settingModal = status === 'GROUP' || status === 'LAYER' ? this.getSettingsModal(status) : null;
const layerMetadataModal = (<LayerMetadataModal
key="toollayermetadatamodal"
layerMetadata={this.props.layerMetadata}
Expand Down Expand Up @@ -277,7 +244,6 @@ class Toolbar extends React.Component {
confirmText={this.props.text.confirmDeleteText}
cancelText={this.props.text.confirmDeleteCancelText}
body={this.props.text.confirmDeleteMessage} />
{settingModal}
{layerMetadataModal}
</ButtonGroup>) : null;
}
Expand Down
77 changes: 77 additions & 0 deletions web/client/components/TOC/__tests__/TOCItemsSettings-test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2018, 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 expect = require('expect');
const ReactDOM = require('react-dom');
const TOCItemsSettings = require('../TOCItemsSettings');


describe("test TOCItemsSettings", () => {
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 with tabs', () => {
ReactDOM.render(<TOCItemsSettings activeTab="general" getTabs={() => [
{
id: 'general',
titleId: 'layerProperties.general',
tooltipId: 'layerProperties.general',
glyph: 'wrench',
Component: () => <div id="test-general-body"></div>
},
{
id: 'display',
titleId: 'layerProperties.display',
tooltipId: 'layerProperties.display',
glyph: 'eye-open',
Component: () => <div id="test-display-body"></div>
}
]}/>, document.getElementById("container"));
const navBar = document.getElementsByClassName('nav-justified')[0];
expect(navBar.children.length).toBe(2);
const testGeneralBody = document.getElementById('test-general-body');
expect(testGeneralBody).toExist();
const testDisplayBody = document.getElementById('test-display-body');
expect(testDisplayBody).toNotExist();
});

it('test without tabs', () => {
ReactDOM.render(<TOCItemsSettings activeTab="general" getTabs={() => []}/>, document.getElementById("container"));
const navBar = document.getElementsByClassName('nav-justified')[0];
expect(navBar).toNotExist();
});

it('test with tabs length 1', () => {
ReactDOM.render(<TOCItemsSettings activeTab="general" getTabs={() => [{
id: 'general',
titleId: 'layerProperties.general',
tooltipId: 'layerProperties.general',
glyph: 'wrench',
Component: () => <div id="test-general-body"></div>
}]}/>, document.getElementById("container"));
const navBar = document.getElementsByClassName('nav-justified')[0];
expect(navBar).toNotExist();
const testGeneralBody = document.getElementById('test-general-body');
expect(testGeneralBody).toExist();
});

it('test alert modal', () => {
ReactDOM.render(<TOCItemsSettings alertModal/>, document.getElementById("container"));
const alertModal = document.getElementsByClassName('ms-resizable-modal');
expect(alertModal.length).toBe(1);
});

});
Loading

0 comments on commit 283d06f

Please sign in to comment.