Skip to content

Commit

Permalink
Client - Download link for documents page (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
luorlandini authored Aug 24, 2021
1 parent 34acab1 commit 652f8fc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
57 changes: 57 additions & 0 deletions geonode_mapstore_client/client/js/plugins/DownloadResource.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2021, 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 { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { createPlugin } from '@mapstore/framework/utils/PluginsUtils';
import Message from '@mapstore/framework/components/I18N/Message';
import Button from '@js/components/Button';
import {
getResourceData
} from '@js/selectors/resource';


function DownloadDocumentButton({
resource,
variant,
size
}) {
return (
resource ? <Button
download={`${resource?.title}.${resource?.extension}`}
href={resource?.href}
variant={variant}
size={size}
>
<Message msgId="gnviewer.download" />
</Button> : null);
}

const ConnectedDownloadResource = connect(
createSelector([
getResourceData
], (resource) => ({
resource
})),
{
}
)(DownloadDocumentButton);


export default createPlugin('DownloadResource', {
component: ConnectedDownloadResource,
containers: {
ActionNavbar: {
name: 'DownloadResource',
Component: ConnectedDownloadResource
}
},
epics: {},
reducers: {}
});
5 changes: 5 additions & 0 deletions geonode_mapstore_client/client/js/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,12 @@ export const plugins = {
DeleteResourcePlugin: toLazyPlugin(
'DeleteResource',
import(/* webpackChunkName: 'plugins/delete-resource-plugin' */ '@js/plugins/DeleteResource')
),
DownloadResourcePlugin: toLazyPlugin(
'DownloadResource',
import(/* webpackChunkName: 'plugins/download-resource-plugin' */ '@js/plugins/DownloadResource')
)

};

const pluginsDefinition = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,16 @@
"type": "plugin",
"name": "Share"
},
{
"type": "plugin",
"name": "DownloadResource",
"perms": [
{
"type": "resource",
"value": "download_resourcebase"
}
]
},
{
"type": "plugin",
"name": "DeleteResource",
Expand All @@ -2079,6 +2089,10 @@
"type": "plugin",
"name": "FullScreen"
},
{
"type": "plugin",
"name": "DownloadResource"
},
{
"name": "DetailViewer"
},
Expand Down

0 comments on commit 652f8fc

Please sign in to comment.