Skip to content

Commit

Permalink
COLUMBIA: DownloadDialog plugin responds to presence of 'no-download'…
Browse files Browse the repository at this point in the history
… behavior on canvas
  • Loading branch information
barmintor committed Apr 24, 2024
1 parent a4390ea commit b5b6fd1
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import Badge from '@mui/material/Badge';
import DownloadIcon from '@mui/icons-material/VerticalAlignBottomSharp';
import PropTypes from 'prop-types';
import { MiradorMenuButton } from '../../../components/MiradorMenuButton';

/** */
const DownloadButton = ({
config, containerId, t, updateConfig,
config, containerId, suppressDownload, t, updateConfig,
}) => {
const { dialogOpen, enabled } = config;
if (!enabled) {
return null;
}
const buttonLabel = suppressDownload ? 'limitedDownloadOptions' : 'showDownloadOptions';
return (
<MiradorMenuButton
aria-expanded={dialogOpen}
aria-haspopup
aria-label={t('showDownloadOptions')}
aria-label={t(buttonLabel)}
onClick={() => updateConfig({
...config,
dialogOpen: !dialogOpen,
})}
>
<DownloadIcon />
<Badge color="error" invisible={!suppressDownload} variant="dot">
<DownloadIcon />
</Badge>
</MiradorMenuButton>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const DownloadDialog = ({
infoResponse,
manifestRenderings,
manifestUrl,
suppressDownload,
t,
updateConfig,
visibleCanvases,
Expand Down Expand Up @@ -64,6 +65,7 @@ const DownloadDialog = ({
key={canvas.id}
label={canvasLabel(canvas.id)}
sizes={infoResponse(canvas.id).json?.sizes}
suppressDownload={suppressDownload}
t={t}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import PropTypes from 'prop-types';
import { anyImageServices } from '../../../../lib/typeFilters';

import ImageDownloadLinks from './ImageDownloadLinks';
import SuppressedDownload from './SuppressedDownload';

/**
* Filter the misnamed imageResources property to actual imageResources
Expand All @@ -19,11 +20,15 @@ const anyImageResources = (imageResources) => (imageResources || []).filter((r)

/** */
const CanvasDownloadLinks = ({
canvas, canvasRenderings, label, sizes, t,
canvas, canvasRenderings, label, sizes, suppressDownload, t,
}) => {
const theme = useTheme();
const behaviors = canvas?.behaviors || [];
if (behaviors.includes('no-download')) return null;

if (suppressDownload) {
return (
<SuppressedDownload label={label} t={t} />
);
}

if (anyImageResources(canvas?.imageResources).length > 0) {
return (
Expand All @@ -32,6 +37,7 @@ const CanvasDownloadLinks = ({
key={canvas.id}
label={label}
sizes={sizes}
suppressDownload={suppressDownload}
t={t}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import Typography from '@mui/material/Typography';
import PropTypes from 'prop-types';

import ImageLink from './ImageLink';
import SuppressedDownload from './SuppressedDownload';

/** */
const ImageDownloadLinks = ({
canvas, label, sizes, t,
canvas, label, sizes, suppressDownload, t,
}) => {
const behaviors = canvas?.behaviors || [];
if (behaviors.includes('no-download')) return null;
if (suppressDownload) {
return (
<SuppressedDownload label={label} t={t} />
);
}

return (
<Card className="mb-3" raised>
<CardContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Box from '@mui/material/Box';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import Typography from '@mui/material/Typography';
import PropTypes from 'prop-types';

/** */
const SuppressedDownload = ({ label, t }) => (
<Card className="mb-3" raised>
<CardContent>
<Typography component="h5" style={{ textTransform: 'none' }} variant="h6">
<Box fontWeight="fontWeightBold" textTransform="none">
{`${t(
'suppressedDownloads',
)}: ${label}`}
</Box>
</Typography>
</CardContent>
</Card>
);

SuppressedDownload.propTypes = {
label: PropTypes.string.isRequired,
t: PropTypes.func.isRequired,
};

export default SuppressedDownload;
4 changes: 3 additions & 1 deletion src/culPlugins/mirador-downloaddialog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import DownloadButton from './components/DownloadButton';
import DownloadDialog from './components/DownloadDialog';
import translations from './locales';
import { getPluginConfig } from './state/selectors';
import { getPluginConfig, getSuppressDownload } from './state/selectors';

export default [
{
Expand All @@ -29,6 +29,7 @@ export default [
mapStateToProps: (state, { windowId }) => ({
config: getPluginConfig(state, { windowId }),
containerId: getContainerId(state),
suppressDownload: getSuppressDownload(state, { windowId }),
}),
mode: 'add',
name: 'DownloadButton',
Expand All @@ -50,6 +51,7 @@ export default [
infoResponse: (canvasId) => selectInfoResponse(state, { canvasId, windowId }) ?? {},
manifestRenderings: getManifestRenderings(state, { windowId }),
manifestUrl: getManifestUrl(state, { windowId }),
suppressDownload: getSuppressDownload(state, { windowId }),
visibleCanvases: getVisibleCanvases(state, { windowId }),
}),
mode: 'add',
Expand Down
6 changes: 6 additions & 0 deletions src/culPlugins/mirador-downloaddialog/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ export default {
downloadOptions: 'Download-Optionen',
iiifManifest: 'IIIF-Manifest',
image: 'Einzelbild',
limitedDownloadOptions: 'Begrenzte Download-Optionen',
otherDownloadOptions: 'Andere Download-Optionen',
pixels: 'Pixel',
showDownloadOptions: 'Download-Optionen anzeigen',
suppressedDownloads: 'Download nicht erlaubt',
},
en: {
close: 'Close',
downloadOptions: 'Download options',
iiifManifest: 'IIIF manifest',
image: 'Single image',
limitedDownloadOptions: 'Limited download options',
otherDownloadOptions: 'Other download options',
pixels: 'pixels',
showDownloadOptions: 'Show download options',
suppressedDownloads: 'Download not allowed',
},
fr: {
close: 'Fermer',
downloadOptions: 'Options de téléchargement',
iiifManifest: 'Manifeste IIIF',
image: 'Image',
limitedDownloadOptions: 'Options de téléchargement limitées',
otherDownloadOptions: 'Autres liens de téléchargement',
pixels: 'pixels',
showDownloadOptions: 'Afficher les options de téléchargement',
suppressedDownloads: 'Téléchargement non autorisé',
},
};
10 changes: 8 additions & 2 deletions src/culPlugins/mirador-downloaddialog/state/selectors/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSelector } from 'reselect';
import { getWindowConfig } from '../../../../state/selectors';
import { getCurrentCanvas, getWindowConfig } from '../../../../state/selectors';

const defaultConfig = {
// Open the download dialog
Expand All @@ -17,4 +17,10 @@ const getPluginConfig = createSelector(
}),
);

export { getPluginConfig };
/** Check the behaviors for no-download */
const getSuppressDownload = createSelector(
[getCurrentCanvas],
(canvas) => ((canvas?.getProperty('behavior') || []).includes('no-download')),
);

export { getPluginConfig, getSuppressDownload };

0 comments on commit b5b6fd1

Please sign in to comment.