From b8d25ec2dd8eef8e49f7a129df30fc7a569102b7 Mon Sep 17 00:00:00 2001 From: David Quartey <42542676+DavidQuartz@users.noreply.github.com> Date: Wed, 9 Nov 2022 11:40:57 +0000 Subject: [PATCH] [Fixes #1243] Show metadata page in Document view when preview is not available (#1250) (#1284) --- .../client/js/api/geonode/v2/index.js | 6 +++- .../js/components/MediaViewer/Media.jsx | 10 +++--- .../MetadataPreview/MetadataPreview.jsx | 32 +++++++++++++++++++ .../js/components/MetadataPreview/index.js | 1 + .../client/js/epics/gnsearch.js | 3 +- .../client/js/utils/ResourceUtils.js | 7 ++-- .../mapstore/translations/data.de-DE.json | 2 +- .../mapstore/translations/data.en-US.json | 2 +- .../mapstore/translations/data.es-ES.json | 2 +- .../mapstore/translations/data.fr-FR.json | 2 +- .../mapstore/translations/data.it-IT.json | 2 +- 11 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 geonode_mapstore_client/client/js/components/MetadataPreview/MetadataPreview.jsx create mode 100644 geonode_mapstore_client/client/js/components/MetadataPreview/index.js diff --git a/geonode_mapstore_client/client/js/api/geonode/v2/index.js b/geonode_mapstore_client/client/js/api/geonode/v2/index.js index 0868e2e1c3..811016b513 100644 --- a/geonode_mapstore_client/client/js/api/geonode/v2/index.js +++ b/geonode_mapstore_client/client/js/api/geonode/v2/index.js @@ -321,7 +321,11 @@ export const getDatasetByPk = (pk) => { }; export const getDocumentByPk = (pk) => { - return axios.get(parseDevHostname(`${endpoints[DOCUMENTS]}/${pk}`)) + return axios.get(parseDevHostname(`${endpoints[DOCUMENTS]}/${pk}`), { + params: { + include: ['executions'] + } + }) .then(({ data }) => data.document); }; diff --git a/geonode_mapstore_client/client/js/components/MediaViewer/Media.jsx b/geonode_mapstore_client/client/js/components/MediaViewer/Media.jsx index 5228ef3a7f..be51b82980 100644 --- a/geonode_mapstore_client/client/js/components/MediaViewer/Media.jsx +++ b/geonode_mapstore_client/client/js/components/MediaViewer/Media.jsx @@ -13,12 +13,13 @@ import { determineResourceType } from '@js/utils/FileUtils'; import Loader from '@mapstore/framework/components/misc/Loader'; import MainEventView from '@js/components/MainEventView'; import { getResourceTypesInfo, getResourceImageSource } from '@js/utils/ResourceUtils'; +import MetadataPreview from '@js/components/MetadataPreview'; const Scene3DViewer = lazy(() => import('@js/components/MediaViewer/Scene3DViewer')); -function UnsupportedViewer() { +function UnsupportedViewer({url = ''}) { return ( - + ); } @@ -52,9 +53,9 @@ const Media = ({ resource, ...props }) => { const mediaTypes = getResourceTypesInfo(); const { - canPreviewed + hasPermission, metadataPreviewUrl = () => {} } = resource && (mediaTypes[resource.subtype] || mediaTypes[resource.resource_type]) || {}; - const viewResource = resource?.pk && canPreviewed && canPreviewed(resource); + const viewResource = resource?.pk && hasPermission && hasPermission(resource); if (resource && viewResource) { const mediaType = determineResourceType(resource.extension); @@ -68,6 +69,7 @@ const Media = ({ resource, ...props }) => { id={resource.pk} thumbnail={() => getResourceImageSource(resource?.thumbnail_url)} src={resource.href} + url={resource ? metadataPreviewUrl(resource) : ''} /> ); } diff --git a/geonode_mapstore_client/client/js/components/MetadataPreview/MetadataPreview.jsx b/geonode_mapstore_client/client/js/components/MetadataPreview/MetadataPreview.jsx new file mode 100644 index 0000000000..04a6ce61d0 --- /dev/null +++ b/geonode_mapstore_client/client/js/components/MetadataPreview/MetadataPreview.jsx @@ -0,0 +1,32 @@ +/* +* Copyright 2022, 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'; + +function MetadataPreview({ + url +}) { + return ( +
+