Skip to content

Commit

Permalink
GeoNode#1511 & GeoNode#1512: Implement links to remote documents and …
Browse files Browse the repository at this point in the history
…source in details panel
  • Loading branch information
dsuren1 committed Aug 4, 2023
1 parent 94016b6 commit 1d81fad
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Spinner from '@js/components/Spinner';
import Message from '@mapstore/framework/components/I18N/Message';
import tooltip from '@mapstore/framework/components/misc/enhancers/tooltip';
import moment from 'moment';
import { getResourceTypesInfo, getMetadataDetailUrl } from '@js/utils/ResourceUtils';
import { getResourceTypesInfo, getMetadataDetailUrl, isExternalDocumentSource } from '@js/utils/ResourceUtils';
import debounce from 'lodash/debounce';
import CopyToClipboardCmp from 'react-copy-to-clipboard';
import ResourceStatus from '@js/components/ResourceStatus';
Expand Down Expand Up @@ -75,6 +75,7 @@ const DetailsPanelTools = ({
enableFavorite,
favorite,
downloadUrl,
externalUrl,
onAction,
onFavorite,
detailUrl,
Expand Down Expand Up @@ -111,6 +112,8 @@ const DetailsPanelTools = ({
onFavorite(!fav);
};

const isExternalSourceType = isExternalDocumentSource(resource);

return (
<div className="gn-details-panel-tools">
<ResourceStatus resource={resource} />
Expand All @@ -120,11 +123,17 @@ const DetailsPanelTools = ({
onClick={debounce(() => handleFavorite(favorite), 500)}>
<FaIcon name={favorite ? 'star' : 'star-o'} />
</Button>}
{downloadUrl &&
{!isExternalSourceType && downloadUrl &&
<Button variant="default"
onClick={() => onAction(resource)} >
<FaIcon name="download" />
</Button>}
{isExternalSourceType && externalUrl &&
<Button variant="default"
href={externalUrl}
rel="noopener noreferrer" >
<FaIcon name="external-link"/>
</Button>}

<CopyToClipboard
tooltipPosition="top"
Expand Down Expand Up @@ -215,13 +224,15 @@ function DetailsPanel({
const downloadUrl = (resource?.href && resource?.href.includes('download')) ? resource?.href
: (resource?.download_url && canDownload) ? resource?.download_url : undefined;
const metadataDetailUrl = resource?.pk && getMetadataDetailUrl(resource);
const externalUrl = resource?.href;
const tools = (
<DetailsPanelTools
name={name}
resource={resource}
enableFavorite={enableFavorite}
favorite={favorite}
downloadUrl={downloadUrl}
externalUrl={externalUrl}
onAction={onAction}
onFavorite={onFavorite}
detailUrl={detailUrl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { createPlugin } from '@mapstore/framework/utils/PluginsUtils';
import { isExternalDocumentSource } from '@js/utils/ResourceUtils';
import Message from '@mapstore/framework/components/I18N/Message';
import Button from '@js/components/Button';
import Dropdown from '@js/components/Dropdown';
Expand All @@ -25,7 +26,7 @@ function DownloadDocumentButton({
size
}) {
return (
resource ? <Button
!isExternalDocumentSource(resource) ? <Button
download={`${resource?.title}.${resource?.extension}`}
href={resource?.href}
variant={variant}
Expand All @@ -50,7 +51,7 @@ function DownloadMenuItem({
onDownload
}) {

if (!(resource?.download_url && resource?.perms?.includes('download_resourcebase'))) {
if (!(resource?.download_url && resource?.perms?.includes('download_resourcebase')) || isExternalDocumentSource(resource)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
getMetadataUrl,
getMetadataDetailUrl,
resourceHasPermission,
canCopyResource
canCopyResource,
isExternalDocumentSource
} from '@js/utils/ResourceUtils';
import get from 'lodash/get';

Expand Down Expand Up @@ -42,5 +43,6 @@ export const getPluginsContext = () => ({
canCopyResource,
userHasPermission: (user, perm) => user?.perms?.includes(perm),
getUserResourceName,
getUserResourceNames
getUserResourceNames,
isExternalDocumentSource
});
4 changes: 4 additions & 0 deletions geonode_mapstore_client/client/js/utils/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,3 +703,7 @@ export const parseUploadFiles = (data) => {
export const getResourceImageSource = (image) => {
return image ? image : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADICAIAAABZHvsFAAAACXBIWXMAAC4jAAAuIwF4pT92AAABiklEQVR42u3SAQ0AAAjDMMC/5+MAAaSVsKyTFHwxEmBoMDQYGgyNocHQYGgwNBgaQ4OhwdBgaDA0hgZDg6HB0GBoDA2GBkODocHQGBoMDYYGQ4OhMTQYGgwNhgZDY2gwNBgaDI2hwdBgaDA0GBpDg6HB0GBoMDSGBkODocHQYGgMDYYGQ4OhwdAYGgwNhgZDg6ExNBgaDA2GBkNjaDA0GBoMDYbG0GBoMDQYGkODocHQYGgwNIYGQ4OhwdBgaAwNhgZDg6HB0BgaDA2GBkODoTE0GBoMDYYGQ2NoMDQYGgwNhsbQYGgwNBgaQ4OhwdBgaDA0hgZDg6HB0GBoDA2GBkODocHQGBoMDYYGQ4OhMTQYGgwNhgZDY2gwNBgaDA2GxtBgaDA0GBoMjaHB0GBoMDSGBkODocHQYGgMDYYGQ4OhwdAYGgwNhgZDg6ExNBgaDA2GBkNjaDA0GBoMDYbG0GBoMDQYGgyNocHQYGgwNIYGQ4OhwdBgaAwNhgZDg6HB0BgaDA2GBkPDbQH4OQSN0W8qegAAAABJRU5ErkJggg==';
};

export const isExternalDocumentSource = (resource) => {
return resource && resource.resource_type === ResourceTypes.DOCUMENT && resource.sourcetype === 'REMOTE';
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {
parseUploadFiles,
getResourceTypesInfo,
ResourceTypes,
FEATURE_INFO_FORMAT
FEATURE_INFO_FORMAT,
isExternalDocumentSource
} from '../ResourceUtils';

describe('Test Resource Utils', () => {
Expand Down Expand Up @@ -970,4 +971,16 @@ describe('Test Resource Utils', () => {
expect(formatMetadataUrl(resource)).toBe('/apps/100/metadata');
});
});
it('isExternalDocumentSource', () => {
let resource = { resource_type: "document", sourcetype: "REMOTE" };
expect(isExternalDocumentSource(resource)).toBeTruthy();

// LOCAL
resource = {...resource, sourcetype: "LOCAL"};
expect(isExternalDocumentSource(resource)).toBeFalsy();

// NOT DOCUMENT
resource = {...resource, resource_type: "dataset"};
expect(isExternalDocumentSource(resource)).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@
padding-left: 1rem;
max-width: calc(100% - 250px);
display: flex;
flex-direction: column;
.gn-details-info-html {
&.collapsed {
display: flex;
Expand Down
38 changes: 37 additions & 1 deletion geonode_mapstore_client/static/mapstore/configs/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@
},
{
"labelId": "gnviewer.download",
"disablePluginIf": "{!state('selectedLayerPermissions').includes('download_resourcebase')}",
"disableIf": "{!state('selectedLayerPermissions').includes('download_resourcebase') || context.isExternalDocumentSource(state('gnResourceData'))}",
"type": "dropdown",
"items": [
{
Expand Down Expand Up @@ -709,6 +709,12 @@
"f": "{context.get(state('gnResourceData'), 'resource_type')}"
}
},
{
"type": "{context.isExternalDocumentSource(state('gnResourceData')) ? 'link' : 'text'}",
"labelId": "gnviewer.sourceType",
"value": "{context.get(state('gnResourceData'), 'sourcetype', '').toLowerCase()}",
"href": "{context.get(state('gnResourceData'), 'href')}"
},
{
"type": "query",
"labelId": "gnviewer.category",
Expand Down Expand Up @@ -1583,6 +1589,12 @@
"f": "{context.get(state('gnResourceData'), 'resource_type')}"
}
},
{
"type": "{context.isExternalDocumentSource(state('gnResourceData')) ? 'link' : 'text'}",
"labelId": "gnviewer.sourceType",
"value": "{context.get(state('gnResourceData'), 'sourcetype', '').toLowerCase()}",
"href": "{context.get(state('gnResourceData'), 'href')}"
},
{
"type": "query",
"labelId": "gnviewer.category",
Expand Down Expand Up @@ -2226,6 +2238,12 @@
"f": "{context.get(state('gnResourceData'), 'resource_type')}"
}
},
{
"type": "{context.isExternalDocumentSource(state('gnResourceData')) ? 'link' : 'text'}",
"labelId": "gnviewer.sourceType",
"value": "{context.get(state('gnResourceData'), 'sourcetype', '').toLowerCase()}",
"href": "{context.get(state('gnResourceData'), 'href')}"
},
{
"type": "query",
"labelId": "gnviewer.category",
Expand Down Expand Up @@ -2536,6 +2554,12 @@
"f": "{context.get(state('gnResourceData'), 'resource_type')}"
}
},
{
"type": "{context.isExternalDocumentSource(state('gnResourceData')) ? 'link' : 'text'}",
"labelId": "gnviewer.sourceType",
"value": "{context.get(state('gnResourceData'), 'sourcetype', '').toLowerCase()}",
"href": "{context.get(state('gnResourceData'), 'href')}"
},
{
"type": "query",
"labelId": "gnviewer.category",
Expand Down Expand Up @@ -2764,6 +2788,12 @@
"f": "{context.get(state('gnResourceData'), 'resource_type')}"
}
},
{
"type": "{context.isExternalDocumentSource(state('gnResourceData')) ? 'link' : 'text'}",
"labelId": "gnviewer.sourceType",
"value": "{context.get(state('gnResourceData'), 'sourcetype', '').toLowerCase()}",
"href": "{context.get(state('gnResourceData'), 'href')}"
},
{
"type": "query",
"labelId": "gnviewer.category",
Expand Down Expand Up @@ -3285,6 +3315,12 @@
"f": "{context.get(state('gnResourceData'), 'resource_type')}"
}
},
{
"type": "{context.isExternalDocumentSource(state('gnResourceData')) ? 'link' : 'text'}",
"labelId": "gnviewer.sourceType",
"value": "{context.get(state('gnResourceData'), 'sourcetype', '').toLowerCase()}",
"href": "{context.get(state('gnResourceData'), 'href')}"
},
{
"type": "query",
"labelId": "gnviewer.category",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@
"dateFilter": {
"from": "Datum von",
"to": "Datum bis"
}
},
"sourceType": "Quelle"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@
"dateFilter": {
"from": "Date from",
"to": "Date to"
}
},
"sourceType": "Source"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@
"dateFilter": {
"from": "Fecha desde",
"to": "Fecha hasta"
}
},
"sourceType": "Fuente"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@
"dateFilter": {
"from": "Date from",
"to": "Date to"
}
},
"sourceType": "Source"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@
"dateFilter": {
"from": "Date de",
"to": "Date à"
}
},
"sourceType": "Source"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@
"dateFilter": {
"from": "Date from",
"to": "Date to"
}
},
"sourceType": "Source"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@
"dateFilter": {
"from": "Data da",
"to": "Data a"
}
},
"sourceType": "Fonte"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@
"dateFilter": {
"from": "Date from",
"to": "Date to"
}
},
"sourceType": "Source"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@
"dateFilter": {
"from": "Date from",
"to": "Date to"
}
},
"sourceType": "Source"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@
"dateFilter": {
"from": "Date from",
"to": "Date to"
}
},
"sourceType": "Source"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@
"dateFilter": {
"from": "Date from",
"to": "Date to"
}
},
"sourceType": "Source"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@
"dateFilter": {
"from": "Date from",
"to": "Date to"
}
},
"sourceType": "Source"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@
"dateFilter": {
"from": "Date from",
"to": "Date to"
}
},
"sourceType": "Source"
}
}
}

0 comments on commit 1d81fad

Please sign in to comment.