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

geosolutions-it / MapStore2 / 14797665772

02 May 2025 02:55PM UTC coverage: 76.933% (-0.06%) from 76.991%
14797665772

Pull #11067

github

web-flow
Merge 99dcd7f92 into d28bf7035
Pull Request #11067: Fix #10966 basic auth for services

30858 of 48053 branches covered (64.22%)

104 of 172 new or added lines in 24 files covered. (60.47%)

3 existing lines in 3 files now uncovered.

38384 of 49893 relevant lines covered (76.93%)

35.93 hits per line

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

29.09
/web/client/components/catalog/editor/MainForm.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
import React, { useState } from 'react';
9
import {get, find} from 'lodash';
10
import { Button, InputGroup, FormControl as FC, Form, Col, FormGroup, ControlLabel, Alert } from "react-bootstrap";
11

12
import Message from '../../I18N/Message';
13
import HTML from '../../I18N/HTML';
14
import {getConfigProp} from '../../../utils/ConfigUtils';
15
import InfoPopover from '../../widgets/widget/InfoPopover';
16
import localizedProps from '../../misc/enhancers/localizedProps';
17
import {checkUrl} from "./MainFormUtils";
18
import IconRB from '../../../plugins/ResourcesCatalog/components/Icon';
19
// selector for tile provider
20
import CONFIG_PROVIDER from '../../../utils/ConfigProvider';
21
import tooltip from '../../misc/enhancers/tooltip';
22

23
const FormControl = localizedProps('placeholder')(FC);
1✔
24
const CUSTOM = "custom";
1✔
25
const TMS = "tms";
1✔
26
const Icon = tooltip(IconRB);
1✔
27

28
const UrlAddon = ({
1✔
29
    onClick,
30
    glyph,
31
    service,
32
    tooltipId,
33
    btnClassName
NEW
34
}) => <InputGroup.Addon
×
35
    onClick={() => {
NEW
36
        onClick(service);
×
37
    }}
38
>
39
    <Button className={btnClassName || ""}>
×
40
        <Icon
41
            glyph={glyph}
42
            type="glyphicon"
43
            tooltipId={tooltipId}
44
        />
45
    </Button>
46
</InputGroup.Addon>;
47

48
const DefaultURLEditor = ({
1✔
49
    service = {},
×
50
    addonsItems = [],
14✔
51
    onChangeUrl = () => { }
×
52
} ) => {
53

54
    const UrlForm = (<FormControl
14✔
55
        type="text"
56
        style={{
57
            textOverflow: "ellipsis"
58
        }}
59
        placeholder={'catalog.urlPlaceHolders.' + service.type}
60
        value={service && service.url}
28✔
NEW
61
        onChange={(e) => onChangeUrl(e.target.value)}/>);
×
62

63
    return (<FormGroup controlId="URL" bsSize="medium">
14✔
64
        <Col xs={12}>
65
            <ControlLabel><Message msgId="catalog.url"/></ControlLabel>
66
            <InputGroup style={{width: "100%"}}>
67
                {UrlForm}
NEW
68
                {addonsItems.map((item) => <item.Component key={item.name} itemComponent={(props) => <UrlAddon {...props} service={service}/> } service={service} />)}
×
69
            </InputGroup>
70
        </Col>
71
    </FormGroup>
72
    );
73
};
74

75
const getProviderLabel = k=> k === TMS ? "TMS 1.0.0" : k;
1!
76
const TmsURLEditor = ({ serviceTypes = [], onChangeServiceProperty, service = {}, onChangeUrl = () => { }, onChangeTitle = () => { } }) => {
1!
77
    const allowedProviders =
78
        getConfigProp('allowedProviders') // this allows overriding of the allowed providers list to remove some service that has been deactivated from the list
×
79
        || get(find(serviceTypes || [], {name: "tms"}), 'allowedProviders') // can be configured at plugin level or via props
×
80
        || [];
81
    const providers = Object.keys(CONFIG_PROVIDER)
×
82
        .filter(k =>
83
            allowedProviders === "ALL" // if set to "ALL" doesn't filter anything
×
84
            || allowedProviders.indexOf(k) >= 0);
85
    const selectedProvider = service === TMS ? service : service?.provider?.split?.(".")?.[0];
×
86
    const isCustom = !selectedProvider || selectedProvider === CUSTOM;
×
87
    const isTMS = selectedProvider === TMS;
×
88
    const needURL = isTMS || isCustom;
×
89
    return (<FormGroup>
×
90
        <Col xs={12} sm={isCustom ? 3 : 12} md={needURL ? 3 : 12}>
×
91
            <ControlLabel><Message msgId="catalog.tms.provider" /></ControlLabel>
92
            <FormControl
93
                onChange={(e) => {
94
                    const provider = e.target.value;
×
95
                    onChangeServiceProperty("provider", `${provider}`);
×
96
                    // auto-set title for pre-configured tile provider
97
                    if (provider !== CUSTOM && provider !== TMS) {
×
98
                        onChangeTitle(provider);
×
99
                    // auto reset if Title was set automatically
100
                    } else if (!isCustom && !isTMS) {
×
101
                        onChangeTitle("");
×
102
                    }
103
                }}
104
                value={selectedProvider}
105
                componentClass="select">
106
                {[CUSTOM, TMS, ...providers].map(k => ({ name: k, label: getProviderLabel(k) })).map((format) => <option value={format.name} key={format.name}>{format.label}</option>)}
×
107
            </FormControl>
108
        </Col>
109
        <Col xs={12} sm={9} md={9}>
110
            {isCustom
×
111
                ? <React.Fragment>
112
                    <ControlLabel><Message msgId="catalog.tms.urlTemplate" />&nbsp;&nbsp;<InfoPopover text={<HTML msgId="catalog.tms.urlTemplateHint" />} /></ControlLabel>
113
                    <FormControl
114
                        type="text"
115
                        style={{
116
                            textOverflow: "ellipsis"
117
                        }}
118
                        placeholder="catalog.urlPlaceHolders.custom"
119
                        value={service && service.url}
×
120
                        onChange={(e) => onChangeUrl(e.target.value)} />
×
121
                </React.Fragment>
122
                : isTMS
×
123
                    ? <React.Fragment>
124
                        <ControlLabel><Message msgId="catalog.url" /></ControlLabel>
125
                        <FormControl
126
                            type="text"
127
                            style={{
128
                                textOverflow: "ellipsis"
129
                            }}
130
                            placeholder="catalog.urlPlaceHolders.tms"
131
                            value={service && service.url}
×
132
                            onChange={(e) => onChangeUrl(e.target.value)} />
×
133
                    </React.Fragment>
134
                    : null
135
            }
136
        </Col>
137
    </FormGroup>);
138
};
139

140
const COGEditor = ({ service = {}, onChangeServiceProperty = () => { } }) => {
1!
141
    return (
×
142
        <FormGroup controlId="URL">
143
            <Col xs={12}>
144
                <ControlLabel><Message msgId="catalog.urls"/>&nbsp;&nbsp;<InfoPopover text={<HTML msgId="catalog.cog.urlTemplateHint" />} /></ControlLabel>
145
                <FormControl
146
                    type="text"
147
                    style={{
148
                        textOverflow: "ellipsis"
149
                    }}
150
                    placeholder="catalog.urlPlaceHolders.cog"
151
                    value={service && service.records && service.records.map(record => record?.url)?.join(',')}
×
152
                    onChange={(e) => {
153
                        let urls = e.target.value || "";
×
154
                        urls = urls?.split(',')
×
155
                            ?.map(url => url?.trim())
×
156
                            ?.map((url, i) => ({
×
157
                                url,
158
                                title: url?.split('/')?.pop()?.replace('.tif', '') || `COG_${i}`
×
159
                            }));
160
                        onChangeServiceProperty("records", urls);
×
161
                    }}/>
162
            </Col>
163
        </FormGroup>
164

165
    );
166
};
167

168

169
/**
170
 * Main Form for editing a catalog entry
171
 *
172
 */
173
export default ({
174
    service = {},
×
175
    serviceTypes, // TODO: this should be renamed most properly with something like serviceTypes
176
    onChangeTitle,
177
    onChangeUrl,
178
    onChangeServiceProperty,
179
    addonsItems,
180
    onChangeType,
181
    setValid = () => {}
×
182
}) => {
183
    const [error, setError] = useState(null);
14✔
184
    const [warning, setWarning] = useState(null);
14✔
185
    function handleProtocolValidity(url) {
186
        onChangeUrl(url);
×
187
        if (url) {
×
188
            const {valid, errorMsgId} = checkUrl(url, null, service?.allowUnsecureLayers);
×
189
            if (errorMsgId === "catalog.invalidUrlHttpProtocol") {
×
190
                setError(null);
×
191
                setWarning(errorMsgId);
×
192
            } else {
193
                setWarning(null);
×
194
                setError(valid ? null : errorMsgId);
×
195
                setValid(valid);
×
196
            }
197
        }
198
    }
199
    const URLEditor = service.type === "tms" ? TmsURLEditor : service.type === "cog" ? COGEditor : DefaultURLEditor;
14!
200
    return (
14✔
201
        <Form horizontal >
202
            <FormGroup controlId="title" key="type-title-row">
203
                <Col key="type" xs={12} sm={3} md={3}>
204
                    <ControlLabel><Message msgId="catalog.type" /></ControlLabel>
205
                    <FormControl
206
                        onChange={(e) => onChangeType(e.target.value)}
×
207
                        value={service && service.type}
28✔
208
                        componentClass="select">
209
                        {serviceTypes.map((type) => <option value={type.name} key={type.name}>{type.label}</option>)}
14✔
210
                    </FormControl>
211
                </Col>
212
                <Col key="title" xs={12} sm={9} md={9}>
213
                    <ControlLabel><Message msgId="catalog.serviceTitle" /></ControlLabel>
214
                    <FormControl
215
                        type="text"
216
                        style={{
217
                            textOverflow: "ellipsis"
218
                        }}
219
                        placeholder={"catalog.serviceTitlePlaceholder"}
220
                        value={service && service.title}
28✔
221
                        onChange={(e) => onChangeTitle(e.target.value)} />
×
222
                </Col>
223
            </FormGroup>
224
            <URLEditor
225
                addonsItems={addonsItems}
226
                key="url-row" serviceTypes={serviceTypes} service={service} onChangeUrl={handleProtocolValidity} onChangeTitle={onChangeTitle} onChangeServiceProperty={onChangeServiceProperty} />
227

228
            {error ? <Alert bsStyle="danger">
14!
229
                <Message msgId={error} />
230
            </Alert> : null}
231
            {warning ? <Alert bsStyle="warning">
14!
232
                <Message msgId={warning} />
233
            </Alert> : null}
234

235
        </Form>);
236
};
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

© 2025 Coveralls, Inc