Skip to content
Snippets Groups Projects
Commit 9e69299f authored by Jack Reed's avatar Jack Reed Committed by Chris Beer
Browse files

Setup collections to open and close the collection selection modal

parent 448e48a8
Branches
No related tags found
No related merge requests found
...@@ -13,16 +13,18 @@ ...@@ -13,16 +13,18 @@
<script type="text/javascript"> <script type="text/javascript">
var miradorInstance = Mirador.viewer({ var miradorInstance = Mirador.viewer({
id: 'mirador', id: 'mirador',
windows: [{ windows: [
{
collectionPath: [
"https://www.e-codices.unifr.ch/metadata/iiif/collection.json",
"https://www.e-codices.unifr.ch/metadata/iiif/collection/stabs.json"
],
manifestId: "https://www.e-codices.unifr.ch/metadata/iiif/stabs-StAlban-DD1-1580/manifest.json"
},
{
manifestId: 'https://www.e-codices.unifr.ch/metadata/iiif/collection.json' manifestId: 'https://www.e-codices.unifr.ch/metadata/iiif/collection.json'
}], }
// windows: [{ ],
// collectionPath: [
// "https://www.e-codices.unifr.ch/metadata/iiif/collection.json",
// "https://www.e-codices.unifr.ch/metadata/iiif/collection/stabs.json"
// ],
// manifestId: "https://www.e-codices.unifr.ch/metadata/iiif/stabs-StAlban-DD1-1580/manifest.json"
// }],
catalog: [ catalog: [
{ manifestId: "https://www.e-codices.unifr.ch/metadata/iiif/collection.json" }, { manifestId: "https://www.e-codices.unifr.ch/metadata/iiif/collection.json" },
] ]
......
...@@ -4,6 +4,7 @@ import { PrimaryWindow } from '../../../src/components/PrimaryWindow'; ...@@ -4,6 +4,7 @@ import { PrimaryWindow } from '../../../src/components/PrimaryWindow';
import WindowSideBar from '../../../src/containers/WindowSideBar'; import WindowSideBar from '../../../src/containers/WindowSideBar';
import WindowViewer from '../../../src/containers/WindowViewer'; import WindowViewer from '../../../src/containers/WindowViewer';
import GalleryView from '../../../src/containers/GalleryView'; import GalleryView from '../../../src/containers/GalleryView';
import CollectionDialog from '../../../src/containers/CollectionDialog';
/** create wrapper */ /** create wrapper */
function createWrapper(props) { function createWrapper(props) {
...@@ -37,4 +38,10 @@ describe('PrimaryWindow', () => { ...@@ -37,4 +38,10 @@ describe('PrimaryWindow', () => {
const wrapper = createWrapper({ isFetching: false, view: 'gallery', windowId: 'window-2' }); const wrapper = createWrapper({ isFetching: false, view: 'gallery', windowId: 'window-2' });
expect(wrapper.find(GalleryView)).toHaveLength(1); expect(wrapper.find(GalleryView)).toHaveLength(1);
}); });
it('should render <CollectionDialog> and <SelectCollection> if manifest is collection and isCollectionDialogVisible', () => {
const wrapper = createWrapper({ isCollection: true, isCollectionDialogVisible: true });
const lazyComponent = wrapper.find('lazy');
expect(lazyComponent.type().displayName).toBe('SelectCollection');
expect(wrapper.find(CollectionDialog)).toHaveLength(1);
});
}); });
...@@ -102,12 +102,15 @@ export class CollectionDialog extends Component { ...@@ -102,12 +102,15 @@ export class CollectionDialog extends Component {
/** */ /** */
placeholder() { placeholder() {
const { classes, hideCollectionDialog } = this.props; const { classes, containerId, hideCollectionDialog, windowId } = this.props;
return ( return (
<Dialog <Dialog
className={classes.dialog}
onClose={hideCollectionDialog} onClose={hideCollectionDialog}
open open
container={document.querySelector(`#${containerId} #${windowId}`)}
BackdropProps={{ classes: classes.dialog }}
> >
<DialogTitle id="select-collection" disableTypography> <DialogTitle id="select-collection" disableTypography>
<Skeleton className={classes.placeholder} variant="text" /> <Skeleton className={classes.placeholder} variant="text" />
...@@ -125,12 +128,14 @@ export class CollectionDialog extends Component { ...@@ -125,12 +128,14 @@ export class CollectionDialog extends Component {
const { const {
classes, classes,
collection, collection,
containerId,
error, error,
hideCollectionDialog, hideCollectionDialog,
isMultipart, isMultipart,
manifest, manifest,
ready, ready,
t, t,
windowId,
} = this.props; } = this.props;
const { filter } = this.state; const { filter } = this.state;
...@@ -152,7 +157,10 @@ export class CollectionDialog extends Component { ...@@ -152,7 +157,10 @@ export class CollectionDialog extends Component {
return ( return (
<Dialog <Dialog
className={classes.dialog}
onClose={hideCollectionDialog} onClose={hideCollectionDialog}
container={document.querySelector(`#${containerId} #${windowId}`)}
BackdropProps={{ classes: { root: classes.dialog }}}
open open
> >
<DialogTitle id="select-collection" disableTypography> <DialogTitle id="select-collection" disableTypography>
...@@ -260,6 +268,7 @@ CollectionDialog.propTypes = { ...@@ -260,6 +268,7 @@ CollectionDialog.propTypes = {
CollectionDialog.defaultProps = { CollectionDialog.defaultProps = {
collection: null, collection: null,
collectionPath: [], collectionPath: [],
containerId: null,
error: null, error: null,
isMultipart: false, isMultipart: false,
ready: false, ready: false,
......
import React, { Component } from 'react'; import React, { Component, lazy } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import WindowSideBar from '../containers/WindowSideBar'; import WindowSideBar from '../containers/WindowSideBar';
...@@ -7,6 +7,9 @@ import GalleryView from '../containers/GalleryView'; ...@@ -7,6 +7,9 @@ import GalleryView from '../containers/GalleryView';
import CompanionArea from '../containers/CompanionArea'; import CompanionArea from '../containers/CompanionArea';
import ns from '../config/css-ns'; import ns from '../config/css-ns';
const SelectCollection = lazy(() => import('../containers/SelectCollection'));
SelectCollection.displayName = 'SelectCollection';
/** /**
* WindowMiddleContent - component that renders the "middle" area of the * WindowMiddleContent - component that renders the "middle" area of the
* Mirador Window * Mirador Window
...@@ -18,7 +21,16 @@ export class PrimaryWindow extends Component { ...@@ -18,7 +21,16 @@ export class PrimaryWindow extends Component {
* @return {(String|null)} * @return {(String|null)}
*/ */
renderViewer() { renderViewer() {
const { isFetching, view, windowId } = this.props; const {
isCollection, isFetching, view, windowId,
} = this.props;
if (isCollection) {
return (
<SelectCollection
windowId={windowId}
/>
);
}
if (isFetching === false) { if (isFetching === false) {
if (view === 'gallery') { if (view === 'gallery') {
return ( return (
...@@ -53,12 +65,14 @@ export class PrimaryWindow extends Component { ...@@ -53,12 +65,14 @@ export class PrimaryWindow extends Component {
PrimaryWindow.propTypes = { PrimaryWindow.propTypes = {
classes: PropTypes.objectOf(PropTypes.string).isRequired, classes: PropTypes.objectOf(PropTypes.string).isRequired,
isCollection: PropTypes.bool,
isFetching: PropTypes.bool, isFetching: PropTypes.bool,
view: PropTypes.string, view: PropTypes.string,
windowId: PropTypes.string.isRequired, windowId: PropTypes.string.isRequired,
}; };
PrimaryWindow.defaultProps = { PrimaryWindow.defaultProps = {
isCollection: false,
isFetching: false, isFetching: false,
view: undefined, view: undefined,
}; };
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';
import Typography from '@material-ui/core/Typography';
import ListSharpIcon from '@material-ui/icons/ListSharp';
/**
*
*/
export class SelectCollection extends Component {
/** */
constructor(props) {
super(props);
this.openCollectionDialog = this.openCollectionDialog.bind(this);
}
/** */
openCollectionDialog() {
const {
collectionPath, manifestId, showCollectionDialog, windowId,
} = this.props;
showCollectionDialog(manifestId, collectionPath.slice(0, -1), windowId);
}
/** */
render() {
const {
t,
} = this.props;
return (
<Grid container justify="center" alignItems="center">
<Grid container direction="column" alignItems="center">
<Typography variant="h4" paragraph>
<em>
{t('noItemSelected')}
</em>
</Typography>
<Button
color="primary"
variant="contained"
onClick={this.openCollectionDialog}
startIcon={<ListSharpIcon />}
>
{t('showCollection')}
</Button>
</Grid>
</Grid>
);
}
}
SelectCollection.propTypes = {
collectionPath: PropTypes.arrayOf(PropTypes.string),
manifestId: PropTypes.string,
showCollectionDialog: PropTypes.func.isRequired,
t: PropTypes.func,
windowId: PropTypes.string,
};
SelectCollection.defaultProps = {
collectionPath: [],
manifestId: null,
t: () => {},
windowId: null,
};
...@@ -4,7 +4,9 @@ import { withStyles } from '@material-ui/core'; ...@@ -4,7 +4,9 @@ import { withStyles } from '@material-ui/core';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { getManifest, getManifestoInstance, getSequenceBehaviors } from '../state/selectors'; import {
getContainerId, getManifest, getManifestoInstance, getSequenceBehaviors,
} from '../state/selectors';
import { CollectionDialog } from '../components/CollectionDialog'; import { CollectionDialog } from '../components/CollectionDialog';
/** /**
...@@ -35,6 +37,7 @@ const mapStateToProps = (state) => { ...@@ -35,6 +37,7 @@ const mapStateToProps = (state) => {
return { return {
collection: collection && getManifestoInstance(state, { manifestId: collection.id }), collection: collection && getManifestoInstance(state, { manifestId: collection.id }),
collectionPath, collectionPath,
containerId: getContainerId(state),
error: manifest && manifest.error, error: manifest && manifest.error,
isMultipart: getSequenceBehaviors(state, { manifestId }).includes('multi-part'), isMultipart: getSequenceBehaviors(state, { manifestId }).includes('multi-part'),
manifest: manifest && getManifestoInstance(state, { manifestId }), manifest: manifest && getManifestoInstance(state, { manifestId }),
...@@ -57,6 +60,9 @@ const styles = theme => ({ ...@@ -57,6 +60,9 @@ const styles = theme => ({
dark: { dark: {
color: '#000000', color: '#000000',
}, },
dialog: {
position: 'absolute !important',
},
dialogContent: { dialogContent: {
padding: 0, padding: 0,
}, },
......
import { compose } from 'redux'; import { compose } from 'redux';
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import { getManifestoInstance } from '../state/selectors';
import { PrimaryWindow } from '../components/PrimaryWindow'; import { PrimaryWindow } from '../components/PrimaryWindow';
/** */
const mapStateToProps = (state, { windowId }) => {
const manifestoInstance = getManifestoInstance(state, { windowId });
return {
isCollection: manifestoInstance && manifestoInstance.isCollection(),
};
};
const styles = { const styles = {
primaryWindow: { primaryWindow: {
display: 'flex', display: 'flex',
...@@ -13,6 +23,7 @@ const styles = { ...@@ -13,6 +23,7 @@ const styles = {
const enhance = compose( const enhance = compose(
withStyles(styles), withStyles(styles),
connect(mapStateToProps),
withPlugins('PrimaryWindow'), withPlugins('PrimaryWindow'),
); );
......
import { compose } from 'redux';
import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core/styles';
import * as actions from '../state/actions';
import { withPlugins } from '../extend/withPlugins';
import {
getWindow,
} from '../state/selectors';
import { SelectCollection } from '../components/SelectCollection';
/** */
const mapStateToProps = (state, { windowId }) => {
const { collectionPath, manifestId } = (getWindow(state, { windowId }) || {});
return {
collectionPath,
manifestId,
};
};
const mapDispatchToProps = {
showCollectionDialog: actions.showCollectionDialog,
};
/** */
const styles = (theme) => ({
});
const enhance = compose(
withTranslation(),
withStyles(styles),
connect(mapStateToProps, mapDispatchToProps),
withPlugins('SelectCollection'),
);
export default enhance(SelectCollection);
...@@ -90,6 +90,7 @@ ...@@ -90,6 +90,7 @@
"moveCompanionWindowToBottom": "Move to bottom", "moveCompanionWindowToBottom": "Move to bottom",
"moveCompanionWindowToRight": "Move to right", "moveCompanionWindowToRight": "Move to right",
"nextCanvas": "Next item", "nextCanvas": "Next item",
"noItemSelected": "No item selected",
"numItems": "{{number}} items", "numItems": "{{number}} items",
"off": "Off", "off": "Off",
"openCompanionWindow_annotations": "Annotations", "openCompanionWindow_annotations": "Annotations",
......
...@@ -95,7 +95,6 @@ export function toggleDraggingEnabled() { ...@@ -95,7 +95,6 @@ export function toggleDraggingEnabled() {
/** */ /** */
export function showCollectionDialog(manifestId, collectionPath = [], windowId = null) { export function showCollectionDialog(manifestId, collectionPath = [], windowId = null) {
console.log(manifestId, collectionPath);
return { return {
collectionPath, collectionPath,
manifestId, manifestId,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment