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

Fix #3608 Toc tooltips options saved in map configuration #3663

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions web/client/components/TOC/fragments/GroupTitle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const PropTypes = require('prop-types');
const StatusIcon = require('./StatusIcon');
const {Tooltip} = require('react-bootstrap');
const OverlayTrigger = require('../../misc/OverlayTrigger');
const {getTitleAndtooltip} = require('../../../utils/TOCUtils');
const {getTitleAndTooltip} = require('../../../utils/TOCUtils');

class GroupTitle extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -40,7 +40,7 @@ class GroupTitle extends React.Component {

render() {
let expanded = this.props.node.expanded !== undefined ? this.props.node.expanded : true;
const {title: groupTitle, tooltipText} = getTitleAndtooltip(this.props);
const {title: groupTitle, tooltipText} = getTitleAndTooltip(this.props);

return this.props.tooltip && tooltipText ? (
<OverlayTrigger placement={this.props.node.tooltipPlacement || "top"} overlay={(<Tooltip id={"tooltip-layer-group"}>{tooltipText}</Tooltip>)}>
Expand Down
5 changes: 3 additions & 2 deletions web/client/components/TOC/fragments/Title.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const PropTypes = require('prop-types');
const React = require('react');
const {Tooltip} = require('react-bootstrap');
const OverlayTrigger = require('../../misc/OverlayTrigger');
const {getTitleAndtooltip} = require('../../../utils/TOCUtils');
const {getTitleAndTooltip} = require('../../../utils/TOCUtils');

require("./css/toctitle.css");

class Title extends React.Component {
Expand Down Expand Up @@ -48,7 +49,7 @@ class Title extends React.Component {
}

render() {
const {title, tooltipText} = getTitleAndtooltip(this.props);
const {title, tooltipText} = getTitleAndTooltip(this.props);
return this.props.tooltip && tooltipText ? (
<OverlayTrigger placement={this.props.node.tooltipPlacement || "top"} overlay={(<Tooltip id={"tooltip-layer-title"}>{tooltipText}</Tooltip>)}>
<div className="toc-title" onClick={this.props.onClick ? (e) => this.props.onClick(this.props.node.id, 'layer', e.ctrlKey) : () => {}} onContextMenu={(e) => {e.preventDefault(); this.props.onContextMenu(this.props.node); }}>
Expand Down
4 changes: 3 additions & 1 deletion web/client/utils/LayersUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ const LayersUtils = {
useForElevation: layer.useForElevation || false,
hidden: layer.hidden || false,
origin: layer.origin,
thematic: layer.thematic
thematic: layer.thematic,
tooltipOptions: layer.tooltipOptions,
tooltipPlacement: layer.tooltipPlacement
},
layer.params ? { params: layer.params } : {},
layer.credits ? { credits: layer.credits } : {});
Expand Down
5 changes: 3 additions & 2 deletions web/client/utils/TOCUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ const TOCUtils = {
* @return {string} separator
* @return {number} maxLength
*/
getTitleAndtooltip: ({node, currentLocale, tooltipOptions = {separator: " - ", maxLength: 807}}) => {
let tooltipText = TOCUtils.getTooltip(node, currentLocale, tooltipOptions.separator).substring(0, tooltipOptions.maxLength);
getTitleAndTooltip: ({node, currentLocale, tooltipOptions = {separator: " - ", maxLength: 807}}) => {
let tooltipText = TOCUtils.getTooltip(node, currentLocale, tooltipOptions.separator) || "";
tooltipText = tooltipText && tooltipText.substring(0, tooltipOptions.maxLength);
if (tooltipText.length === tooltipOptions.maxLength) {
tooltipText += "...";
}
Expand Down
11 changes: 11 additions & 0 deletions web/client/utils/__tests__/LayersUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,17 @@ describe('LayersUtils', () => {
l => {
expect(l.credits).toExist();
}
],
// save tooltipOptions and tooltipPlacement if present
[
{
tooltipOptions: "both",
tooltipPlacement: "right"
},
l => {
expect(l.tooltipOptions).toExist();
expect(l.tooltipPlacement).toExist();
}
]
];
layers.map(([layer, test]) => test(LayersUtils.saveLayer(layer)) );
Expand Down
183 changes: 172 additions & 11 deletions web/client/utils/__tests__/MapUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
},
{
allowedSRS: {},
Expand Down Expand Up @@ -328,7 +330,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
},
{
allowedSRS: {},
Expand Down Expand Up @@ -372,7 +376,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
},
{
allowedSRS: {},
Expand Down Expand Up @@ -416,7 +422,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: [100000, 100000],
thematic: undefined
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
}],
mapOptions: {},
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
Expand Down Expand Up @@ -478,7 +486,9 @@ describe('Test the MapUtils', () => {
type: "wms",
url: "",
visibility: true,
catalogURL: "url"
catalogURL: "url",
tooltipOptions: "both",
tooltipPlacement: "right"
}
];

Expand Down Expand Up @@ -582,7 +592,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
},
{
allowedSRS: {},
Expand Down Expand Up @@ -626,7 +638,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
},
{
allowedSRS: {},
Expand Down Expand Up @@ -670,7 +684,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined
thematic: undefined,
tooltipOptions: "both",
tooltipPlacement: "right"
}],
mapOptions: {
view: {
Expand Down Expand Up @@ -854,7 +870,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
},
{
allowedSRS: {},
Expand Down Expand Up @@ -898,7 +916,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
},
{
allowedSRS: {},
Expand Down Expand Up @@ -942,7 +962,9 @@ describe('Test the MapUtils', () => {
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
}],
mapOptions: {},
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
Expand All @@ -969,6 +991,145 @@ describe('Test the MapUtils', () => {
});


it('save map configuration with tile matrix and map info configuration', () => {
const flat = [
{
allowedSRS: {},
bbox: {},
description: undefined,
dimensions: [],
id: "layer001",
loading: true,
name: "layer001",
params: {},
search: {},
singleTile: false,
title: "layer001",
type: "wms",
url: "http:url001",
visibility: true,
catalogURL: "url",
matrixIds: {
'EPSG:4326': [{
identifier: 'EPSG:4326:0'
}]
},
tileMatrixSet: [{
TileMatrix: [{
'ows:Identifier': 'EPSG:4326:0'
}],
'ows:Identifier': "EPSG:4326",
'ows:SupportedCRS': "urn:ogc:def:crs:EPSG::4326"
}, {
TileMatrix: [{
'ows:Identifier': 'custom:0'
}],
'ows:Identifier': "custom",
'ows:SupportedCRS': "urn:ogc:def:crs:EPSG::900913"
}]
}
];
const groups = [
{expanded: true, id: 'Default', name: 'Default', title: 'Default', nodes: ['layer001', 'layer002']},
{expanded: false, id: 'custom', name: 'custom', title: 'custom',
nodes: [{expanded: true, id: 'custom.nested001', name: 'nested001', title: 'nested001', nodes: ['layer003']}
]}
];
const mapConfig = {
center: {x: 0, y: 0, crs: 'EPSG:4326'},
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
projection: 'EPSG:900913',
units: 'm',
zoom: 10
};
const saved = saveMapConfiguration(mapConfig, flat, groups, '', { mapInfoConfiguration: {infoFormat: "text/html", showEmptyMessageGFI: false}});
expect(saved).toEqual({
map: {
center: {crs: 'EPSG:4326', x: 0, y: 0},
groups: [{
id: 'Default',
expanded: true
}, {
id: 'custom',
expanded: false
}, {
id: 'custom.nested001',
expanded: true
}],
layers: [{
allowedSRS: {},
thumbURL: undefined,
availableStyles: undefined,
bbox: {},
requestEncoding: undefined,
capabilitiesURL: undefined,
description: undefined,
dimensions: [],
nativeCrs: undefined,
features: undefined,
queryable: undefined,
featureInfo: undefined,
format: undefined,
group: undefined,
hideLoading: false,
handleClickOnLayer: false,
id: "layer001",
matrixIds: ['EPSG:4326'],
maxZoom: undefined,
maxNativeZoom: undefined,
name: "layer001",
opacity: undefined,
params: {},
provider: undefined,
search: {},
singleTile: false,
source: undefined,
style: undefined,
styleName: undefined,
styles: undefined,
tileMatrixSet: true,
tiled: undefined,
title: "layer001",
transparent: undefined,
type: "wms",
url: "http:url001",
visibility: true,
catalogURL: "url",
hidden: false,
useForElevation: false,
origin: undefined,
thematic: undefined,
tooltipOptions: undefined,
tooltipPlacement: undefined
}],
mapOptions: {},
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
projection: 'EPSG:900913',
text_serch_config: '',
units: 'm',
zoom: 10,
sources: {
'http:url001': {
tileMatrixSet: {
'EPSG:4326': {
TileMatrix: [{
'ows:Identifier': 'EPSG:4326:0'
}],
'ows:Identifier': "EPSG:4326",
'ows:SupportedCRS': "urn:ogc:def:crs:EPSG::4326"
}
}
}
}
},
mapInfoConfiguration: {
infoFormat: "text/html",
showEmptyMessageGFI: false
},
version: 2
});
});

it('test getIdFromUri ', () => {
// /mapstore2/rest/geostore/data/578/raw?decode=datauri
expect(getIdFromUri('%2Fmapstore2%2Frest%2Fgeostore%2Fdata%2F578%2Fraw%3Fdecode%3Ddatauri')).toBe('578');
Expand Down
26 changes: 19 additions & 7 deletions web/client/utils/__tests__/TOCUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
getTooltip,
getTooltipFragment,
flattenGroups,
getTitleAndtooltip
getTitleAndTooltip
} = require('../TOCUtils');
let options = [{label: "lab1", value: "val1"}];
const groups = [{
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('TOCUtils', () => {
expect(allGroups[2].value).toBe("first.second.third");
expect(allGroups[2].label).toBe("first/second/third");
});
it('test getTitleAndtooltip', () => {
it('test getTitleAndTooltip both', () => {
const node = {
name: 'layer00',
title: {
Expand All @@ -166,16 +166,28 @@ describe('TOCUtils', () => {
},
id: "layer00",
description: "desc",
visibility: true,
storeIndex: 9,
type: 'wms',
url: 'fakeurl',
tooltipOptions: "both"
};
const currentLocale = "it-IT";
const {title, tooltipText} = getTitleAndtooltip({node, currentLocale});
const {title, tooltipText} = getTitleAndTooltip({node, currentLocale});
expect(title).toBe("Livello");
expect(tooltipText).toBe("Livello - desc");

});
it('test getTitleAndTooltip NoTooltip', () => {
const node = {
name: 'layer00',
title: {
'default': 'Layer',
'it-IT': 'Livello'
},
id: "layer00",
description: "desc",
tooltipOptions: "none"
};
const currentLocale = "it-IT";
const {title, tooltipText} = getTitleAndTooltip({node, currentLocale});
expect(title).toBe("Livello");
expect(tooltipText).toBe("");
});
});