Skip to content

Commit

Permalink
[Fixes #1243] Show metadata page in Document view when preview is not…
Browse files Browse the repository at this point in the history
… available (#1250) (#1284)
  • Loading branch information
DavidQuartz committed Nov 9, 2022
1 parent 3700b1f commit b8d25ec
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 13 deletions.
6 changes: 5 additions & 1 deletion geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<MainEventView msgId={'gnhome.noPreview'} icon="file" />
<MetadataPreview url={url} />
);
}

Expand Down Expand Up @@ -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);
Expand All @@ -68,6 +69,7 @@ const Media = ({ resource, ...props }) => {
id={resource.pk}
thumbnail={() => getResourceImageSource(resource?.thumbnail_url)}
src={resource.href}
url={resource ? metadataPreviewUrl(resource) : ''}
/>
</Suspense>);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<div className="gn-main-event-container">
<iframe
frameBorder="0"
key={url}
src={url}
style={{
width: '100%',
height: '100%'
}} />
</div>
);
}

MetadataPreview.defaultProps = {
url: ''
};

export default MetadataPreview;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './MetadataPreview';
3 changes: 2 additions & 1 deletion geonode_mapstore_client/client/js/epics/gnsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import isNil from 'lodash/isNil';
import {
getResources,
getResourceByPk,
getDocumentByPk,
getFeaturedResources,
getResourceByUuid
} from '@js/api/geonode/v2';
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions geonode_mapstore_client/client/js/utils/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b8d25ec

Please sign in to comment.