• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geosolutions-it / MapStore2 / 13439711986

20 Feb 2025 04:13PM UTC coverage: 76.693% (-0.005%) from 76.698%
13439711986

push

github

web-flow
#10799: Cesium map dark when opened in the evening (#10803)

31248 of 48904 branches covered (63.9%)

28 of 35 new or added lines in 2 files covered. (80.0%)

6 existing lines in 2 files now uncovered.

38772 of 50555 relevant lines covered (76.69%)

34.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.33
/web/client/components/mapcatalog/MapCatalogPanel.jsx
1
/**
2
 * Copyright 2020, GeoSolutions Sas.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under the BSD-style license found in the
6
 * LICENSE file in the root directory of this source tree.
7
 */
8

9
import React from 'react';
10
import PropTypes from 'prop-types';
11
import Rx from 'rxjs';
12
import { isArray, zip, split, isNil, bind } from 'lodash';
13
import { compose, getContext } from 'recompose';
14
import { Glyphicon } from 'react-bootstrap';
15

16
import { getResource } from '../../api/persistence';
17
import Api from '../../api/GeoStoreDAO';
18

19
import withInfiniteScroll from '../misc/enhancers/infiniteScroll/withInfiniteScroll';
20
import withShareTool from '../resources/enhancers/withShareTool';
21
import withFilter from './enhancers/withFilter';
22
import withDelete from './enhancers/withDelete';
23
import withEdit from './enhancers/withEdit';
24
import {getMessageById} from '../../utils/LocaleUtils';
25
import Toolbar from '../misc/toolbar/Toolbar';
26
import Filter from '../misc/Filter';
27
import MapCatalog from '../maps/MapCatalog';
28

29
const getContextNames = ({results, ...other}) => {
1✔
30
    const maps = isArray(results) ? results : (results === "" ? [] : [results]);
×
31
    return maps.length === 0 ?
×
32
        Rx.Observable.of({results, ...other}) :
33
        Rx.Observable.forkJoin(
34
            maps.map(({context}) => context ?
×
35
                getResource(context, {includeAttributes: false, withData: false, withPermissions: false})
36
                    .switchMap(resource => Rx.Observable.of(resource.name))
×
37
                    .catch(() => Rx.Observable.of(null)) :
×
38
                Rx.Observable.of(null))
39
        ).map(contextNames => ({
×
40
            results: zip(maps, contextNames).map(
41
                ([curMap, contextName]) => ({...curMap, contextName})),
×
42
            ...other
43
        }));
44
};
45

46
const searchMaps = ({searchText, opts}) => Rx.Observable.defer(() => Api.getResourcesByCategory(
2✔
47
    'MAP',
48
    searchText || '*',
4✔
49
    opts
50
)).switchMap(response => getContextNames(response))
×
51
    .map(result => ({
×
52
        items: result.results,
53
        total: result.totalCount,
54
        loading: false
UNCOV
55
    })).catch(() => Rx.Observable.of({
×
56
        items: [],
57
        total: 0,
58
        loading: false
59
    }));
60

61
const loadPage = ({searchText = '', limit = 12} = {}, page = 0) => searchMaps({
2!
62
    searchText,
63
    opts: {
64
        params: {
65
            includeAttributes: true,
66
            start: page * limit,
67
            limit
68
        }
69
    }
70
});
71

72
const onClickHandler = (map, router, mapType, toggleCatalog, reloadFunction) => {
1✔
73
    toggleCatalog();
1✔
74
    // reload if the same context was selected from catalog
75
    const {location} = router.history;
1✔
76
    if (!isNil(location.pathname)
1!
77
    && (map.contextName === split(location.pathname, '/')[2])
78
    && (map.id === Number(split(location.pathname, '/')[3]))) {
79
        reloadFunction();
1✔
80
    } else {
81
        router.history.push(map.contextName ?
×
82
            "/context/" + map.contextName + "/" + map.id :
83
            "/viewer/" + map.id
84
        );
85
    }
86
};
87

88
const MapCatalogPanel = ({
1✔
89
    loading,
90
    mapType,
91
    items = [],
2✔
92
    filterText,
93
    onFilter = () => {},
×
94
    onDelete = () => {},
×
95
    onEdit = () => {},
×
96
    onShare = () => {},
×
97
    messages = {},
4✔
98
    router = {},
2✔
99
    toggleCatalog = () => {},
4✔
100
    reloadFunction = bind(window.location.reload, window.location)
2✔
101
}) => {
102
    const mapToItem = (map) => ({
4✔
103
        title: map.name,
104
        description: map.description,
105
        tools: <Toolbar
106
            btnDefaultProps={{
107
                className: 'square-button-md'
108
            }}
109
            buttons={[{
110
                glyph: 'trash',
111
                bsStyle: 'primary',
112
                tooltipId: 'mapCatalog.tooltips.delete',
113
                visible: map.canDelete,
114
                onClick: (e) => {
115
                    e.stopPropagation();
×
116
                    onDelete(map);
×
117
                }
118
            }, {
119
                glyph: 'wrench',
120
                bsStyle: 'primary',
121
                tooltipId: 'mapCatalog.tooltips.edit',
122
                visible: map.canEdit,
123
                onClick: (e) => {
124
                    e.stopPropagation();
×
125
                    onEdit(map);
×
126
                }
127
            }, {
128
                glyph: 'share-alt',
129
                bsStyle: 'primary',
130
                className: 'square-button-md',
131
                tooltipId: 'mapCatalog.tooltips.share',
132
                onClick: (e) => {
133
                    e.stopPropagation();
×
134
                    onShare(map);
×
135
                }
136
            }]}/>,
137
        preview:
138
            <div className="map-catalog-preview">
139
                {map.thumbnail && map.thumbnail !== 'NODATA' ?
10✔
140
                    <img src={decodeURIComponent(map.thumbnail)}/> :
141
                    <Glyphicon glyph="1-map"/>}
142
            </div>,
143
        onClick: () => onClickHandler(map, router, mapType, toggleCatalog, reloadFunction)
1✔
144
    });
145

146
    return (
4✔
147
        <div className="map-catalog-panel">
148
            <MapCatalog
149
                loading={loading}
150
                loaderProps={{
151
                    width: 480,
152
                    height: 480
153
                }}
154
                header={<Filter
155
                    filterText={filterText}
156
                    filterPlaceholder={getMessageById(messages, 'mapCatalog.filterPlaceholder')}
157
                    onFilter={onFilter}/>
158
                }
159
                items={items.map(mapToItem)}/>
160
        </div>
161
    );
162
};
163

164
export default compose(
165
    getContext({
166
        messages: PropTypes.object,
167
        router: PropTypes.object
168
    }),
169
    withInfiniteScroll({
170
        loadPage,
171
        loadMoreStreamOptions: {
172
            initialStreamDebounce: 300
173
        },
174
        scrollSpyOptions: {
175
            querySelector: '.map-catalog-panel > .map-catalog > .ms2-border-layout-body',
176
            pageSize: 12
177
        },
178
        hasMore: ({items = [], total = 0}) => items.length < total
1!
179
    }),
180
    withFilter,
181
    withDelete,
182
    withEdit,
183
    withShareTool
184
)(MapCatalogPanel);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc