-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic implementation of Table of Contents view
- Loading branch information
1 parent
b0626e9
commit 91247a9
Showing
7 changed files
with
178 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<title>Mirador - Table of contents</title> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"> | ||
</head> | ||
<body> | ||
<div id="mirador" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0;"></div> | ||
<script>document.write("<script type='text/javascript' src='../../../dist/mirador.min.js?v=" + Date.now() + "'><\/script>");</script> | ||
<script type="text/javascript"> | ||
var miradorInstance = Mirador.viewer({ | ||
id: 'mirador', | ||
windows: [{ | ||
manifestId: 'https://iiif.bodleian.ox.ac.uk/iiif/manifest/390fd0e8-9eae-475d-9564-ed916ab9035c.json', | ||
canvasId: 'https://iiif.bodleian.ox.ac.uk/iiif/canvas/a024a538-aef3-44b3-ad11-51c6a8b04ea2.json' | ||
}], | ||
window: { | ||
sideBarOpenByDefault: true, | ||
defaultSideBarPanel: 'canvas' | ||
}, | ||
manifests: { | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import TreeView from '@material-ui/lab/TreeView'; | ||
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; | ||
import ChevronRightIcon from '@material-ui/icons/ChevronRight'; | ||
import TreeItem from '@material-ui/lab/TreeItem'; | ||
|
||
/** */ | ||
export class SidebarIndexTableOfContents extends Component { | ||
/** */ | ||
selectTreeItem(node) { | ||
const { setCanvas, windowId } = this.props; | ||
// Do not select if there are child nodes | ||
if (node.nodes.length > 0) { | ||
return; | ||
} | ||
const canvas = node.data.getCanvasIds()[0]; | ||
setCanvas(windowId, canvas); | ||
} | ||
|
||
/** */ | ||
buildTreeItems(nodes) { | ||
return ( | ||
nodes.map(node => ( | ||
<TreeItem | ||
key={node.id} | ||
nodeId={node.id} | ||
label={node.label} | ||
onClick={() => this.selectTreeItem(node)} | ||
> | ||
{node.nodes.length > 0 ? this.buildTreeItems(node.nodes) : null} | ||
</TreeItem> | ||
)) | ||
); | ||
} | ||
|
||
/** */ | ||
render() { | ||
const { | ||
classes, treeStructure, | ||
} = this.props; | ||
|
||
if (!treeStructure) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<> | ||
<TreeView | ||
className={classes.root} | ||
defaultCollapseIcon={<ExpandMoreIcon />} | ||
defaultExpandIcon={<ChevronRightIcon />} | ||
> | ||
{this.buildTreeItems(treeStructure.nodes)} | ||
</TreeView> | ||
</> | ||
); | ||
} | ||
} | ||
|
||
SidebarIndexTableOfContents.propTypes = { | ||
classes: PropTypes.objectOf(PropTypes.string).isRequired, | ||
setCanvas: PropTypes.func.isRequired, | ||
treeStructure: PropTypes.objectOf().isRequired, | ||
windowId: PropTypes.string.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { compose } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import { withTranslation } from 'react-i18next'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import { withPlugins } from '../extend/withPlugins'; | ||
import { SidebarIndexTableOfContents } from '../components/SidebarIndexTableOfContents'; | ||
import { | ||
getManifestoInstance, | ||
getManifestTreeStructure, | ||
getVisibleCanvases, | ||
} from '../state/selectors'; | ||
import * as actions from '../state/actions'; | ||
|
||
|
||
/** | ||
* mapStateToProps - to hook up connect | ||
*/ | ||
const mapStateToProps = (state, { id, windowId }) => ({ | ||
canvases: getVisibleCanvases(state, { windowId }), | ||
manifesto: getManifestoInstance(state, { windowId }), | ||
treeStructure: getManifestTreeStructure(state, { windowId }), | ||
}); | ||
|
||
/** | ||
* mapStateToProps - used to hook up connect to state | ||
* @memberof SidebarIndexTableOfContents | ||
* @private | ||
*/ | ||
const mapDispatchToProps = (dispatch, { id, windowId }) => ({ | ||
setCanvas: (...args) => dispatch(actions.setCanvas(...args)), | ||
}); | ||
|
||
/** | ||
* Styles for withStyles HOC | ||
*/ | ||
const styles = theme => ({ | ||
root: { | ||
flexGrow: 1, | ||
}, | ||
}); | ||
|
||
const enhance = compose( | ||
withStyles(styles), | ||
withTranslation(), | ||
connect(mapStateToProps, mapDispatchToProps), | ||
withPlugins('SidebarIndexTableOfContents'), | ||
); | ||
|
||
export default enhance(SidebarIndexTableOfContents); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters