Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2542 Custom Format on Get Feature Info #2591

Merged
merged 8 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe what is this component usable for

/**
* Component for rendering TOC Settings as tabs inside a Dockable contanier
* @memberof components.TOC
* @name TOCItemsSettings
* @class
* @prop {dock} dock switch between Dockable Panel and Resizable Modal, default true (DockPanel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably {boolean}

* @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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not generic, too many properties are dependent on specific item info (e.g. chartStyle, getDimension, generalInfoFormat). If it has to be a generic item setting container component, it should only have reference to generic things (e.g. the item node)

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 (
<span>
<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>
</span>
);
};
13 changes: 7 additions & 6 deletions web/client/components/TOC/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ 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');
// removed from toolbar to avoid conflict with TOCItemsSettings
// const SettingsModal = require('./fragments/SettingsModal');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code from this file

// const GroupSettingsModal = require('./fragments/GroupSettingsModal');
const LayerMetadataModal = require('./fragments/LayerMetadataModal');

class Toolbar extends React.Component {
Expand Down Expand Up @@ -135,7 +136,7 @@ class Toolbar extends React.Component {
status = this.props.selectedLayers.length > 0 && this.props.selectedLayers.filter(l => l.loadingError === 'Error').length === this.props.selectedLayers.length ? 'LAYERS_LOAD_ERROR' : status;
return status;
}

/*
getSettingsModal = (status) => {
return status === 'LAYER' ?
(<SettingsModal
Expand Down Expand Up @@ -164,11 +165,11 @@ class Toolbar extends React.Component {
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 settingModal = status === 'GROUP' || status === 'LAYER' ? this.getSettingsModal(status) : null;
const layerMetadataModal = (<LayerMetadataModal
key="toollayermetadatamodal"
layerMetadata={this.props.layerMetadata}
Expand Down Expand Up @@ -277,7 +278,7 @@ class Toolbar extends React.Component {
confirmText={this.props.text.confirmDeleteText}
cancelText={this.props.text.confirmDeleteCancelText}
body={this.props.text.confirmDeleteMessage} />
{settingModal}
{/*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