Skip to content
Open
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
11 changes: 9 additions & 2 deletions geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
EXECUTION_REQUEST,
getEndpoints as cGetEndpoints,
getEndpointUrl,
getQueryParams
getQueryParams,
UPLOADS
} from './constants';


Expand Down Expand Up @@ -723,6 +724,11 @@ export const deleteAsset = (pk, assetId) => {
});
};

export const createDataset = (body) => {
return axios.post(getEndpointUrl(UPLOADS) + '/upload', body)
.then(({ data }) => data);
};

export default {
getEndpoints,
getResources,
Expand Down Expand Up @@ -759,5 +765,6 @@ export default {
downloadResource,
getDatasets,
deleteExecutionRequest,
getResourceByTypeAndByPk
getResourceByTypeAndByPk,
createDataset
};
3 changes: 1 addition & 2 deletions geonode_mapstore_client/client/js/apps/gn-catalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ const getViewer = (component) => {
const viewers = {
[appRouteComponentTypes.VIEWER]: ViewerRoute,
[appRouteComponentTypes.CATALOGUE]: useRedirect ? RedirectRoute : ComponentsRoute,
[appRouteComponentTypes.DATASET_UPLOAD]: ComponentsRoute,
[appRouteComponentTypes.DOCUMENT_UPLOAD]: ComponentsRoute,
[appRouteComponentTypes.COMPONENTS]: ComponentsRoute,
[appRouteComponentTypes.MAP_VIEWER]: MapViewerRoute
};
return viewers[component];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* Copyright 2025, 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.
*/
import React from 'react';
import PropTypes from 'prop-types';
import { FormGroup, FormControl, Checkbox, HelpBlock } from 'react-bootstrap';

import FlexBox from '@mapstore/framework/components/layout/FlexBox';
import Message from '@mapstore/framework/components/I18N/Message';
import { getMessageById } from '@mapstore/framework/utils/LocaleUtils';

import { AttributeTypes, getAttributeControlId, RestrictionsTypes } from '../utils/CreateDatasetUtils';
import RangeRestriction from './RangeRestriction';
import EnumRestriction from './EnumRestriction';

const CreateDatasetAttributeRow = ({
data,
geometryAttribute,
disabled,
tools,
onChange,
getErrorByPath = () => undefined,
index
}, context) => {

const errors = {
name: getErrorByPath(`/attributes/${index}/name`),
restrictionsType: getErrorByPath(`/attributes/${index}/restrictionsType`),
restrictionsRangeMin: getErrorByPath(`/attributes/${index}/restrictionsRangeMin`),
restrictionsRangeMax: getErrorByPath(`/attributes/${index}/restrictionsRangeMax`)
};

const typesOptions = geometryAttribute
? [
{ value: AttributeTypes.Point, labelId: 'gnviewer.points' },
{ value: AttributeTypes.LineString, labelId: 'gnviewer.lines' },
{ value: AttributeTypes.Polygon, labelId: 'gnviewer.polygons' }]
: [
{ value: AttributeTypes.String, labelId: 'gnviewer.string' },
{ value: AttributeTypes.Integer, labelId: 'gnviewer.integer' },
{ value: AttributeTypes.Float, labelId: 'gnviewer.float' },
{ value: AttributeTypes.Date, labelId: 'gnviewer.date' }
];

const restrictionsOptions = [
AttributeTypes.Integer,
AttributeTypes.Float,
AttributeTypes.String
].includes(data?.type)
? [
{ value: RestrictionsTypes.None, labelId: 'gnviewer.none' },
...(data?.type !== AttributeTypes.String
? [{ value: RestrictionsTypes.Range, labelId: 'gnviewer.range' }]
: []
),
{ value: RestrictionsTypes.Options, labelId: 'gnviewer.options' }
]
: [{ value: RestrictionsTypes.None, labelId: 'gnviewer.none' }];

function handleOnChange(properties) {
onChange({
...data,
...properties
});
}

function handleTypeChange(event) {
const newType = event.target.value;
const currentType = data?.type;

// If type is changing, clear restrictions and set to default
if (newType !== currentType) {
onChange({
...data,
type: newType,
restrictionsType: RestrictionsTypes.None,
restrictionsRangeMin: null,
restrictionsRangeMax: null,
restrictionsOptions: []
});
} else {
handleOnChange({ type: newType });
}
}

return (
<tr className="gn-dataset-attribute">
<td className="gn-attribute-name">
<FormGroup
controlId={getAttributeControlId(data, 'name')}
validationState={errors?.name ? 'error' : undefined}
>
<FormControl
type="text"
value={data?.name || ''}
disabled={!!geometryAttribute || disabled}
onChange={(event) => handleOnChange({ name: event.target.value })}
/>
{errors?.name ? <HelpBlock><Message msgId={errors.name} /></HelpBlock> : null}
</FormGroup>
</td>
<td className="gn-attribute-type">
<FormGroup controlId={getAttributeControlId(data, 'type')}>
<FormControl
value={data?.type || ''}
componentClass="select"
placeholder="select"
onChange={handleTypeChange}
disabled={disabled}
>
{typesOptions.map(({ labelId, value }) =>
<option key={value} value={value}>
{getMessageById(context.messages, labelId)}
</option>
)}
</FormControl>
</FormGroup>
</td>
<td className="gn-attribute-nillable">
<FormGroup controlId={getAttributeControlId(data, 'nillable')}>
<Checkbox
style={{ paddingTop: 6 }}
checked={!!data?.nillable}
disabled={!!geometryAttribute || disabled}
onChange={(event) =>
handleOnChange({ nillable: event.target.checked })
}
/>
</FormGroup>
</td>
<td>
<FlexBox column gap="sm">
<FormGroup
controlId={getAttributeControlId(data, 'restrictions')}
validationState={errors?.restrictionsType ? 'error' : undefined}>
<FormControl
value={data?.restrictionsType}
componentClass="select"
placeholder="select"
disabled={!!geometryAttribute || disabled}
onChange={(event) =>
handleOnChange({ restrictionsType: event.target.value })
}
>
{restrictionsOptions.map(({ labelId, value }) =>
<option key={value} value={value}>
{getMessageById(context.messages, labelId)}
</option>
)}
</FormControl>
{errors?.restrictionsType ? <HelpBlock>{errors.restrictionsType}</HelpBlock> : null}
</FormGroup>
{data?.restrictionsType === RestrictionsTypes.Range ?
<RangeRestriction
errors={errors}
data={data}
handleOnChange={handleOnChange}
disabled={disabled}
/> : null}
{data?.restrictionsType === RestrictionsTypes.Options
? <EnumRestriction
index={index}
data={data}
handleOnChange={handleOnChange}
getErrorByPath={getErrorByPath}
disabled={disabled}
/> : null}
</FlexBox>
</td>
<td className="gn-attribute-tools">
{tools}
</td>
</tr>
);
};

CreateDatasetAttributeRow.contextTypes = {
messages: PropTypes.object
};

export default CreateDatasetAttributeRow;
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2025, 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.
*/
import React from "react";
import { v4 as uuid } from 'uuid';
import { FormGroup, FormControl, HelpBlock, Glyphicon } from "react-bootstrap";

import FlexBox from "@mapstore/framework/components/layout/FlexBox";
import Message from "@mapstore/framework/components/I18N/Message";
import Button from "@mapstore/framework/components/layout/Button";
import Text from "@mapstore/framework/components/layout/Text";

import { AttributeTypes, getAttributeControlId, parseNumber } from "../utils/CreateDatasetUtils";

const EnumRestriction = ({
index,
data = {},
handleOnChange = () => {},
getErrorByPath = () => {},
disabled
}) => {
return (
<FlexBox column wrap gap="sm">
<FlexBox gap="sm" column component="ul">
{(data?.restrictionsOptions || []).map((option, idx) => {
const optionsError = {
value: getErrorByPath(`/attributes/${index}/restrictionsOptions/${idx}/value`)
};
return (
<FlexBox component="li" gap="sm" key={option.id}>
<Text style={{ paddingTop: 6 }}>●</Text>
<FlexBox.Fill
component={FormGroup}
key={option.id}
validationState={optionsError?.value ? 'error' : undefined}
controlId={getAttributeControlId(data, `option-${option.id}`)}
>
<FormControl
type={data?.type === AttributeTypes.String ? "text" : "number"}
value={option.value}
disabled={disabled}
onChange={(event) => handleOnChange({
restrictionsOptions: (data?.restrictionsOptions || [])
.map((opt) => {
return opt.id !== option.id
? opt : {
...option,
value: data?.type === AttributeTypes.String
? event.target.value
: parseNumber(event.target.value)
};
})
})}
/>
{optionsError?.value ? <HelpBlock>
<Message msgId={optionsError.value} />
</HelpBlock> : null}
</FlexBox.Fill>
<Button square
onClick={() => handleOnChange({
restrictionsOptions: (data?.restrictionsOptions || [])
.filter(opt => opt.id !== option.id)
})}
disabled={disabled}>
<Glyphicon glyph="trash" />
</Button>
</FlexBox>
);
})}
<div>
<Button size="sm" onClick={() => handleOnChange({
restrictionsOptions: [
...(data?.restrictionsOptions || []),
{
id: uuid(),
value: ''
}
]
})}
disabled={disabled}>
<Glyphicon glyph="plus" />
{' '}<Message msgId="gnviewer.addOption" />
</Button>
</div>
</FlexBox>
</FlexBox>
);
};

export default EnumRestriction;
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2025, 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.
*/
import React from "react";
import { FormGroup, FormControl, ControlLabel, HelpBlock } from "react-bootstrap";

import FlexBox from "@mapstore/framework/components/layout/FlexBox";
import Message from "@mapstore/framework/components/I18N/Message";

import { getAttributeControlId, parseNumber } from "../utils/CreateDatasetUtils";

const RangeRestriction = ({
errors = {},
data = {},
handleOnChange = () => {},
disabled
}) => {
return (
<FlexBox centerChildrenVertically wrap gap="sm">
<FlexBox.Fill
flexBox
component={FormGroup}
validationState={errors?.restrictionsRangeMin ? 'error' : undefined}
controlId={getAttributeControlId(data, 'restrictions-min')}
centerChildrenVertically
gap="sm"
>
<ControlLabel><Message msgId="gnviewer.min" /></ControlLabel>
<FormControl
type="number"
value={data?.restrictionsRangeMin}
disabled={disabled}
onChange={(event) => handleOnChange({
restrictionsRangeMin: parseNumber(event.target.value)
})}
/>
{errors?.restrictionsRangeMin ?
<HelpBlock>
<Message msgId={errors.restrictionsRangeMin} />
</HelpBlock> : null}
</FlexBox.Fill>
<FlexBox.Fill
flexBox
component={FormGroup}
validationState={errors?.restrictionsRangeMax ? 'error' : undefined}
controlId={getAttributeControlId(data, 'restrictions-max')}
gap="sm"
centerChildrenVertically
>
<ControlLabel><Message msgId="gnviewer.max" /></ControlLabel>
<FormControl
type="number"
value={data?.restrictionsRangeMax}
disabled={disabled}
onChange={(event) => handleOnChange({
restrictionsRangeMax: parseNumber(event.target.value)
})}
/>
{errors?.restrictionsRangeMax
? <HelpBlock>
<Message msgId={errors.restrictionsRangeMax} />
</HelpBlock> : null}
</FlexBox.Fill>
</FlexBox>
);
};

export default RangeRestriction;
Loading