forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c962040
commit b1bfe81
Showing
59 changed files
with
2,553 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
geonode_mapstore_client/client/js/api/geonode/v2/metadata.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2024, 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 axios from '@mapstore/framework/libs/ajax'; | ||
import { | ||
METADATA, | ||
RESOURCES, | ||
getEndpointUrl | ||
} from './constants'; | ||
import { isObject, isArray, castArray } from 'lodash'; | ||
|
||
const parseUiSchema = (properties) => { | ||
return Object.keys(properties).reduce((acc, key) => { | ||
const entry = properties[key]; | ||
const uiKeys = Object.keys(entry).filter(propertyKey => propertyKey.indexOf('ui:') === 0); | ||
if (uiKeys.length) { | ||
acc[key] = Object.fromEntries(uiKeys.map(uiKey => [uiKey, entry[uiKey]])); | ||
} | ||
if (entry.type === 'object') { | ||
const nestedProperties = parseUiSchema(entry?.properties); | ||
acc[key] = { ...acc[key], ...nestedProperties }; | ||
} | ||
return acc; | ||
}, {}); | ||
}; | ||
|
||
let metadataSchemas; | ||
export const getMetadataSchema = () => { | ||
if (metadataSchemas) { | ||
return Promise.resolve(metadataSchemas); | ||
} | ||
return axios.get(getEndpointUrl(METADATA, '/schema/')) | ||
.then(({ data }) => { | ||
const schema = data; | ||
metadataSchemas = { | ||
schema: schema, | ||
uiSchema: parseUiSchema(schema?.properties || {}) | ||
}; | ||
return metadataSchemas; | ||
}); | ||
}; | ||
|
||
const removeNullValueRecursive = (metadata = {}, schema = {}) => { | ||
return Object.keys(metadata).reduce((acc, key) => { | ||
const schemaTypes = castArray(schema?.[key]?.type || []); | ||
if (metadata[key] === null && !schemaTypes.includes('null')) { | ||
return { | ||
...acc, | ||
[key]: undefined | ||
}; | ||
} | ||
return { | ||
...acc, | ||
[key]: !isArray(metadata[key]) && isObject(metadata[key]) | ||
? removeNullValueRecursive(metadata[key], schema[key]) | ||
: metadata[key] | ||
}; | ||
}, {}); | ||
}; | ||
|
||
export const getMetadataByPk = (pk) => { | ||
return getMetadataSchema() | ||
.then(({ schema, uiSchema }) => { | ||
const resourceProperties = ['pk', 'title', 'detail_url', 'perms']; | ||
return Promise.all([ | ||
axios.get(getEndpointUrl(METADATA, `/instance/${pk}/`)), | ||
axios.get(getEndpointUrl(RESOURCES, `/${pk}/?exclude[]=*&${resourceProperties.map(value => `include[]=${value}`).join('&')}`)) | ||
]) | ||
.then((response) => { | ||
const metadataResponse = response?.[0]?.data || {}; | ||
const resource = response?.[1]?.data?.resource || {}; | ||
const { extraErrors, ...metadata } = metadataResponse; | ||
return { | ||
schema, | ||
uiSchema, | ||
metadata: removeNullValueRecursive(metadata, schema?.properties), | ||
resource, | ||
extraErrors | ||
}; | ||
}); | ||
}); | ||
}; | ||
|
||
export const updateMetadata = (pk, body) => { | ||
return axios.put(getEndpointUrl(METADATA, `/instance/${pk}/`), body) | ||
.then(({ data }) => data); | ||
}; |
19 changes: 19 additions & 0 deletions
19
...apstore_client/client/js/components/InputControlWithDebounce/InputControlWithDebounce.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2024, 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 { FormControl as FormControlRB } from 'react-bootstrap'; | ||
import withDebounceOnCallback from '@mapstore/framework/components/misc/enhancers/withDebounceOnCallback'; | ||
import localizedProps from '@mapstore/framework/components/misc/enhancers/localizedProps'; | ||
const FormControl = localizedProps('placeholder')(FormControlRB); | ||
function InputControl({ onChange, value, debounceTime, ...props }) { | ||
return <FormControl {...props} value={value} onChange={event => onChange(event.target.value)}/>; | ||
} | ||
const InputControlWithDebounce = withDebounceOnCallback('onChange', 'value')(InputControl); | ||
|
||
export default InputControlWithDebounce; |
1 change: 1 addition & 0 deletions
1
geonode_mapstore_client/client/js/components/InputControlWithDebounce/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './InputControlWithDebounce'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
geonode_mapstore_client/client/js/plugins/MetadataEditor/MetadataViewer.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright 2024, 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 { createPlugin } from '@mapstore/framework/utils/PluginsUtils'; | ||
import { connect } from 'react-redux'; | ||
import { createSelector } from 'reselect'; | ||
import { withRouter } from 'react-router'; | ||
import isEqual from 'lodash/isEqual'; | ||
import Message from '@mapstore/framework/components/I18N/Message'; | ||
import ResizableModal from '@mapstore/framework/components/misc/ResizableModal'; | ||
import Portal from '@mapstore/framework/components/misc/Portal'; | ||
import Button from '@js/components/Button'; | ||
|
||
import { | ||
setMetadataPreview | ||
} from './actions/metadata'; | ||
|
||
import metadataReducer from './reducers/metadata'; | ||
|
||
const connectMetadataViewer = connect( | ||
createSelector([ | ||
state => state?.metadata?.metadata, | ||
state => state?.metadata?.initialMetadata, | ||
state => state?.metadata?.preview | ||
], (metadata, initialMetadata, preview) => ({ | ||
preview, | ||
pendingChanges: !isEqual(initialMetadata, metadata) | ||
})), | ||
{ | ||
setPreview: setMetadataPreview | ||
} | ||
); | ||
|
||
const MetadataViewer = ({ | ||
match, | ||
preview, | ||
setPreview, | ||
labelId = 'gnviewer.viewMetadata' | ||
}) => { | ||
const { params } = match || {}; | ||
const pk = params?.pk; | ||
return ( | ||
<Portal> | ||
<ResizableModal | ||
title={<Message msgId={labelId} />} | ||
show={preview} | ||
size="lg" | ||
clickOutEnabled={false} | ||
modalClassName="gn-simple-dialog" | ||
onClose={() => setPreview(false)} | ||
> | ||
<iframe style={{ border: 'none', position: 'absolute', width: '100%', height: '100%' }} src={`/metadata/${pk}/embed`} /> | ||
</ResizableModal> | ||
</Portal> | ||
); | ||
}; | ||
|
||
const MetadataViewerPlugin = connectMetadataViewer(withRouter(MetadataViewer)); | ||
|
||
const PreviewButton = ({ | ||
size, | ||
variant, | ||
pendingChanges, | ||
setPreview = () => {}, | ||
labelId = 'gnviewer.viewMetadata' | ||
}) => { | ||
return ( | ||
<Button | ||
size={size} | ||
variant={variant} | ||
disabled={pendingChanges} | ||
onClick={() => setPreview(true)} | ||
> | ||
<Message msgId={labelId} /> | ||
</Button> | ||
); | ||
}; | ||
|
||
const PreviewButtonPlugin = connectMetadataViewer(PreviewButton); | ||
|
||
export default createPlugin('MetadataViewer', { | ||
component: MetadataViewerPlugin, | ||
containers: { | ||
ActionNavbar: { | ||
name: 'MetadataViewer', | ||
Component: PreviewButtonPlugin | ||
} | ||
}, | ||
epics: {}, | ||
reducers: { | ||
metadata: metadataReducer | ||
} | ||
}); |
Oops, something went wrong.