Commit 0a9a9e8b authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Add Download MCPD button for subsets and datasets

parent 0647be0f
......@@ -825,6 +825,7 @@
"locations": "Locations",
"traitsObserved": "Traits observed",
"useAndLicensing": "Dataset use and licensing",
"datasetMcpdPasportData": "MCPD passport data",
"confirmDescription": {
"approve": "After approving the dataset no changes are permitted, a new version must be created.",
"onPublish": "The dataset will be reviewing by administrator before publishing."
......@@ -1691,7 +1692,8 @@
"subTitle": "Explore curated sets of subsets"
},
"display": {
"title": "Subset {{subsetTitle: string}}"
"title": "Subset {{subsetTitle: string}}",
"MCPD": "MCPD"
}
}
},
......
......@@ -160,6 +160,7 @@
"locations": "Locations",
"traitsObserved": "Traits observed",
"useAndLicensing": "Dataset use and licensing",
"datasetMcpdPasportData": "MCPD passport data",
"confirmDescription": {
"approve": "After approving the dataset no changes are permitted, a new version must be created.",
"onPublish": "The dataset will be reviewing by administrator before publishing."
......
......@@ -38,6 +38,7 @@ import McpdDate from 'ui/common/time/McpdDate';
import PagedLoader from 'ui/common/PagedLoader';
import AccessionRefCard from 'accessions/ui/c/AccessionRefCard';
import Number from 'ui/common/Number';
import DownloadDialog from 'ui/common/download-dialog';
const styles = (theme) => ({
root: {
......@@ -386,6 +387,22 @@ class DetailInfo extends React.Component<IDetailInfoProps, any> {
</PropertiesItem>
))
}
<Authorize role="ROLE_USER">
<PropertiesItem key={ dataset.uuid } title={
<DownloadDialog downloadUrl={ `/proxy/api/v1/dataset/${dataset.uuid}/download` }
slug="download-authenticated"
postParams={ { mcpd: 'mcpd' } }
buttonTitle={ `${t('common:action.download')}` }
variant="contained"
btnClasses={ `${classes.buttonGreen} ${classes.button}` }
/>
}>
<p>{ t(`datasets.public.c.datasetDisplay.datasetMcpdPasportData`) }</p>
<p>{ `MCPD - ${dataset.uuid}.xlsx` }</p>
</PropertiesItem>
</Authorize>
</Properties>
</Grid>
</Grid>
......
......@@ -30,7 +30,8 @@
"subTitle": "Explore curated sets of subsets"
},
"display": {
"title": "Subset {{subsetTitle: string}}"
"title": "Subset {{subsetTitle: string}}",
"MCPD": "MCPD"
}
}
},
......
......@@ -12,7 +12,7 @@ import { Properties, PropertiesItem } from 'ui/common/Properties';
import CropChips from 'crop/ui/c/CropChips';
import McpdDate from 'ui/common/time/McpdDate';
const SubsetCard = ({subset, complete = false, t, ...other}: { subset: Subset, complete?: boolean, t: any } & React.ClassAttributes<any>) => {
const SubsetCard = ({subset, complete = false, actions, t, ...other}: { subset: Subset, complete?: boolean, actions?: any, t: any } & React.ClassAttributes<any>) => {
return (
<Card>
<CardHeader title={ <SubsetLink to={ subset } /> } />
......@@ -27,9 +27,9 @@ const SubsetCard = ({subset, complete = false, t, ...other}: { subset: Subset, c
</Properties>
</CardContent>
{ false &&
{ actions &&
<CardActions>
Actions
{ actions }
</CardActions>
}
</Card>
......
import * as React from 'react';
import { connect } from 'react-redux';
import {translate} from 'react-i18next';
import {withStyles} from '@material-ui/core/styles';
// util
......@@ -17,6 +18,7 @@ import Grid from '@material-ui/core/Grid';
import Loading from 'ui/common/Loading';
import PagedLoader from 'ui/common/PagedLoader';
import AccessionRefCard from 'accessions/ui/c/AccessionRefCard';
import DownloadDialog from 'ui/common/download-dialog';
const styles = (theme) => ({
accessionSection: {
......@@ -36,10 +38,21 @@ interface IDetailInfoProps extends React.ClassAttributes<any> {
deleteSubset?: (subset: Subset) => any;
loadAccessions: (page: Page<AccessionRef>) => any;
accessions: Page<AccessionRef>;
userRoles: string[];
}
class DetailInfo extends React.Component<IDetailInfoProps, any> {
public state = {
authenticated: false,
};
public componentWillMount() {
const { userRoles } = this.props;
const authenticated: boolean = userRoles.findIndex((role) => role === 'ROLE_USER') !== -1;
this.setState({authenticated});
}
public render() {
const {classes, subset, t, accessions, loadAccessions} = this.props;
......@@ -57,7 +70,16 @@ class DetailInfo extends React.Component<IDetailInfoProps, any> {
// TODO sometimes creator can be null
return (
<div>
<SubsetCard complete subset={ subset }/>
<SubsetCard complete subset={ subset }
actions={
this.state.authenticated &&
<DownloadDialog downloadUrl={ `/proxy/api/v1/subset/${subset.uuid}/download` }
slug="download-authenticated"
postParams={ { mcpd: 'mcpd' } }
buttonTitle={ `${t('common:action.download')} ${t('subsets.public.p.display.MCPD')}` }
/>
}
/>
<Grid container spacing={ 16 } className={ classes.accessionSection } justify={ 'space-between' }>
{ subset.creators &&
<PropertiesCard
......@@ -85,4 +107,8 @@ class DetailInfo extends React.Component<IDetailInfoProps, any> {
}
export default translate()((withStyles as any)(styles)(DetailInfo));
const mapStateToProps = (state, ownProps) => ({
userRoles: state.login.authorities,
});
export default translate()(connect(mapStateToProps, null)((withStyles as any)(styles)(DetailInfo)));
......@@ -71,6 +71,7 @@ interface IDownloadProps extends React.ClassAttributes<any> {
t: any;
variant?: 'text' | 'outlined' | 'contained' | 'contained' | 'fab' | 'extendedFab';
btnClasses?: string;
downloadUrl: string;
buttonTitle: string;
postParams: object;
......@@ -104,13 +105,17 @@ class DownloadDialog extends React.Component<IDownloadProps, any> {
private asyncHide = () => setTimeout(() => this.hide());
public render() {
const {variant = 'text', t, buttonTitle, downloadUrl, postParams, classes, article } = this.props;
const {variant = 'text', t, btnClasses, buttonTitle, downloadUrl, postParams, classes, article } = this.props;
let { disabled } = this.props;
disabled = !!disabled || !downloadUrl;
return (
<div style={ { margin: '0 4px' } }>
<Button onClick={ this.show } disabled={ disabled } className={ this.props.classes.permButton } variant={ variant }>{ buttonTitle }</Button>
<div>
<Button onClick={ this.show }
disabled={ disabled }
className={ btnClasses ? btnClasses : this.props.classes.permButton }
variant={ variant }>{ buttonTitle }
</Button>
{ this.state.open &&
<div>
{ !!disabled ?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment