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 (
+
+
+
+ );
+}
+
+MetadataPreview.defaultProps = {
+ url: ''
+};
+
+export default MetadataPreview;
diff --git a/geonode_mapstore_client/client/js/components/MetadataPreview/index.js b/geonode_mapstore_client/client/js/components/MetadataPreview/index.js
new file mode 100644
index 0000000000..3df012f8bd
--- /dev/null
+++ b/geonode_mapstore_client/client/js/components/MetadataPreview/index.js
@@ -0,0 +1 @@
+export { default } from './MetadataPreview';
diff --git a/geonode_mapstore_client/client/js/epics/gnsearch.js b/geonode_mapstore_client/client/js/epics/gnsearch.js
index c6d792c194..1bb36606d7 100644
--- a/geonode_mapstore_client/client/js/epics/gnsearch.js
+++ b/geonode_mapstore_client/client/js/epics/gnsearch.js
@@ -13,6 +13,7 @@ import isNil from 'lodash/isNil';
import {
getResources,
getResourceByPk,
+ getDocumentByPk,
getFeaturedResources,
getResourceByUuid
} from '@js/api/geonode/v2';
@@ -228,7 +229,7 @@ export const gnsSelectResourceEpic = (action$, store) =>
const resources = state.gnsearch?.resources || [];
const selectedResource = resources.find(({ pk, resource_type: resourceType}) =>
pk === action.pk && action.ctype === resourceType);
- return Observable.defer(() => getResourceByPk(action.pk))
+ return Observable.defer(() => action.ctype !== 'document' ? getResourceByPk(action.pk) : getDocumentByPk(action.pk))
.switchMap((resource) => {
return Observable.of(setResource({
...resource,
diff --git a/geonode_mapstore_client/client/js/utils/ResourceUtils.js b/geonode_mapstore_client/client/js/utils/ResourceUtils.js
index b86e2f61f3..8a8d0069af 100644
--- a/geonode_mapstore_client/client/js/utils/ResourceUtils.js
+++ b/geonode_mapstore_client/client/js/utils/ResourceUtils.js
@@ -15,6 +15,7 @@ import { ProcessTypes, ProcessStatus } from '@js/utils/ResourceServiceUtils';
import { bboxToPolygon } from '@js/utils/CoordinatesUtils';
import { uniqBy, orderBy, isString, isObject, pick, difference } from 'lodash';
import { excludeGoogleBackground, extractTileMatrixFromSources } from '@mapstore/framework/utils/LayersUtils';
+import { determineResourceType } from '@js/utils/FileUtils';
/**
* @module utils/ResourceUtils
@@ -280,10 +281,12 @@ export const getResourceTypesInfo = () => ({
[ResourceTypes.DOCUMENT]: {
icon: 'file',
name: 'Document',
- canPreviewed: (resource) => resourceHasPermission(resource, 'download_resourcebase'),
+ canPreviewed: (resource) => resourceHasPermission(resource, 'download_resourcebase') && !!(determineResourceType(resource.extension) !== 'unsupported'),
+ hasPermission: (resource) => resourceHasPermission(resource, 'download_resourcebase'),
formatEmbedUrl: (resource) => resource?.embed_url && parseDevHostname(resource.embed_url),
formatDetailUrl: (resource) => resource?.detail_url && parseDevHostname(resource.detail_url),
- formatMetadataUrl: (resource) => (`/documents/${resource.pk}/metadata`)
+ formatMetadataUrl: (resource) => (`/documents/${resource.pk}/metadata`),
+ metadataPreviewUrl: (resource) => (`/documents/${resource.pk}/metadata_detail?preview`)
},
[ResourceTypes.GEOSTORY]: {
icon: 'book',
diff --git a/geonode_mapstore_client/client/static/mapstore/translations/data.de-DE.json b/geonode_mapstore_client/client/static/mapstore/translations/data.de-DE.json
index 9946798a76..0ea63152e3 100644
--- a/geonode_mapstore_client/client/static/mapstore/translations/data.de-DE.json
+++ b/geonode_mapstore_client/client/static/mapstore/translations/data.de-DE.json
@@ -50,7 +50,7 @@
"viewImage": "Bild ansehen",
"viewVideo": "Video ansehen",
"viewDashboard": "Dashboard ansehen",
- "viewMetadata": "Metadaten ansehen",
+ "viewMetadata": "Details anzeigen",
"author": "Autor",
"publication": "Veröffentlichung",
"creation": "Erstellungsdatum",
diff --git a/geonode_mapstore_client/client/static/mapstore/translations/data.en-US.json b/geonode_mapstore_client/client/static/mapstore/translations/data.en-US.json
index 13fad3d212..0d064e8ac5 100644
--- a/geonode_mapstore_client/client/static/mapstore/translations/data.en-US.json
+++ b/geonode_mapstore_client/client/static/mapstore/translations/data.en-US.json
@@ -50,7 +50,7 @@
"viewImage": "View image",
"viewVideo": "View video",
"viewDashboard": "View dashboard",
- "viewMetadata": "View metadata",
+ "viewMetadata": "View details",
"author": "Author",
"publication": "Publication",
"creation": "Creation",
diff --git a/geonode_mapstore_client/client/static/mapstore/translations/data.es-ES.json b/geonode_mapstore_client/client/static/mapstore/translations/data.es-ES.json
index b5b286cc5b..f7e1c47a50 100644
--- a/geonode_mapstore_client/client/static/mapstore/translations/data.es-ES.json
+++ b/geonode_mapstore_client/client/static/mapstore/translations/data.es-ES.json
@@ -50,7 +50,7 @@
"viewImage": "Ver imágenes",
"viewVideo": "Ver video",
"viewDashboard": "Ver dashboard",
- "viewMetadata": "Voir metadatos",
+ "viewMetadata": "Ver detalles",
"author": "Autor",
"publication": "Publicación",
"creation": "Creación",
diff --git a/geonode_mapstore_client/client/static/mapstore/translations/data.fr-FR.json b/geonode_mapstore_client/client/static/mapstore/translations/data.fr-FR.json
index 6c618846ba..e7ece4fb77 100644
--- a/geonode_mapstore_client/client/static/mapstore/translations/data.fr-FR.json
+++ b/geonode_mapstore_client/client/static/mapstore/translations/data.fr-FR.json
@@ -50,7 +50,7 @@
"viewImage": "Voir images",
"viewVideo": "Voir video",
"viewDashboard": "Voir dashboard",
- "viewMetadata": "Voir métadonnées",
+ "viewMetadata": "Voir les détails",
"author": "Auteur",
"publication": "Publication",
"creation": "Création",
diff --git a/geonode_mapstore_client/client/static/mapstore/translations/data.it-IT.json b/geonode_mapstore_client/client/static/mapstore/translations/data.it-IT.json
index bc823da21a..7ab1a2a0ef 100644
--- a/geonode_mapstore_client/client/static/mapstore/translations/data.it-IT.json
+++ b/geonode_mapstore_client/client/static/mapstore/translations/data.it-IT.json
@@ -50,7 +50,7 @@
"viewImage": "Visualizza immagine",
"viewVideo": "Visualizza video",
"viewDashboard": "Visualizza dashboard",
- "viewMetadata": "Visualizza metadati",
+ "viewMetadata": "Visualizza dettagli",
"author": "Autore",
"publication": "Pubblicazione",
"creation": "Creazione",