Skip to content
Snippets Groups Projects
MapApp.js 9.54 KiB
Newer Older
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles';
import withWidth from '@material-ui/core/withWidth';
import compose from 'recompose/compose';
import Paper from '@material-ui/core/Paper';
import ResultTable from '../components/ResultTable';
import LeafletMap from '../components/LeafletMap';
import Pie from '../components/Pie';
import TopBar from '../components/TopBar';
import CircularProgress from '@material-ui/core/CircularProgress';
import purple from '@material-ui/core/colors/purple';
Esko Ikkala's avatar
Esko Ikkala committed
  toggleDataset,
  fetchSuggestions,
  clearSuggestions,
  fetchManuscripts,
  fetchPlaces,
  fetchPlace,
  fetchResults,
  clearManuscripts,
  clearPlaces,
  getGeoJSON,
  updateResultFormat,
esikkala's avatar
esikkala committed
  updateResultsFilter,
  sortResults,
Esko Ikkala's avatar
Esko Ikkala committed
  bounceMarker,
Esko Ikkala's avatar
Esko Ikkala committed
const logoPadding = 50;
const logoHeight = 52;

const styles = theme => ({
  root: {
    flexGrow: 1,
    height: '100%',
  },
Esko Ikkala's avatar
Esko Ikkala committed
  flex: {
    flexGrow: 1,
Esko Ikkala's avatar
Esko Ikkala committed
  appFrame: {
    height: '100%',
    zIndex: 1,
Esko Ikkala's avatar
Esko Ikkala committed
    overflow: 'hidden',
Esko Ikkala's avatar
Esko Ikkala committed
    position: 'relative',
Esko Ikkala's avatar
Esko Ikkala committed
    width: '100%',
    minWidth: 640,
    minHeight: 700
Esko Ikkala's avatar
Esko Ikkala committed
  mainContainer: {
    display: 'flex',
    width: '100%',
Esko Ikkala's avatar
Esko Ikkala committed
    marginTop: 64,
    height: 'calc(100% - 128px)',
    borderRight: '4px solid' + theme.palette.primary.main,
    borderLeft: '4px solid' + theme.palette.primary.main,
  },
  resultTable: {
    width: 1024,
    height: 'calc(100% - 5px)',
    borderRight: '4px solid' + theme.palette.primary.main,

  },
  resultTableOneColumn: {
    height: 'calc(100% - 5px)',
    overflow: 'auto'
  },
  rightColumn: {
    height: '100%',
    width: 'calc(100% - 1024px)',
  },
  map: {
    width: '100%',
    height: '50%',
    borderBottom: '4px solid' + theme.palette.primary.main,
Esko Ikkala's avatar
Esko Ikkala committed
  },
  fullMap: {
    width: '100%',
    height: '100%',
  },
Esko Ikkala's avatar
Esko Ikkala committed
  statistics: {
    width: '100%',
    height: '50%',
Esko Ikkala's avatar
Esko Ikkala committed
  statisticsOneColumn: {
    width: '100%',
    height: '100%',
  },
  progress: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
esikkala's avatar
esikkala committed
  progressTitle: {
    marginRight: 15
  },
  footer: {
    position: 'absolute',
    borderTop: '4px solid' + theme.palette.primary.main,
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    bottom: 0,
    width: '100%',
    height: 64,
    background: theme.palette.primary.main,
    borderRadius: 0,
  },
Esko Ikkala's avatar
Esko Ikkala committed
  oxfordLogo: {
Esko Ikkala's avatar
Esko Ikkala committed
    height: logoHeight
  },
  pennLogo: {
    paddingLeft: logoPadding,
    height: logoHeight - 8
  },
  aaltoLogo: {
    paddingLeft: logoPadding,
    height: logoHeight - 8
Esko Ikkala's avatar
Esko Ikkala committed
    paddingLeft: logoPadding,
    height: logoHeight
Esko Ikkala's avatar
Esko Ikkala committed
    paddingLeft: logoPadding,
    height: logoHeight - 5
Esko Ikkala's avatar
Esko Ikkala committed
    paddingLeft: logoPadding,
    height: logoHeight - 10
  const { classes, options, search, map, manuscripts, creationPlaces, place, facet } = props;
  // browser
  //console.log(manuscripts)
  //console.log(place)
  if (search.fetchingManuscripts) {
    const tableClass = oneColumnView ? classes.resultTableOneColumn : classes.resultTable;

    //<Typography className={classes.progressTitle} variant="h4">Fetching manuscript data</Typography>
      <div className={[tableClass, classes.progress].join(' ')}>
esikkala's avatar
esikkala committed
        <CircularProgress style={{ color: purple[500] }} thickness={5} />
  } else {
    if ((oneColumnView && options.resultFormat === 'table') || (!oneColumnView)) {
      //console.log(facetValues)
      table = (
        <div className={oneColumnView ? classes.resultTableOneColumn : classes.resultTable}>
          <ResultTable
            rows={manuscripts}
            fetchManuscripts={props.fetchManuscripts}
            fetchFacet={props.fetchFacet}
            results={props.results}
            page={props.page}
  let mapElement = '';
  if ((oneColumnView && options.resultFormat === 'map') || (!oneColumnView)) {
    mapElement = (
      <LeafletMap
        fetchPlaces={props.fetchPlaces}
        fetchPlace={props.fetchPlace}
        fetchManuscripts={props.fetchManuscripts}
        results={creationPlaces}
        place={place}
        mapMode={options.mapMode}
        geoJSON={map.geoJSON}
        geoJSONKey={map.geoJSONKey}
        getGeoJSON={props.getGeoJSON}
        bouncingMarker={map.bouncingMarker}
        popupMarker={map.popupMarker}
        bouncingMarkerKey={map.bouncingMarkerKey}
        openPopupMarkerKey={map.openPopupMarkerKey}
      />
    );
  //console.log(creationPlaces)
  if ((oneColumnView && options.resultFormat === 'statistics') || (!oneColumnView)) {
Esko Ikkala's avatar
Esko Ikkala committed
      <div className={oneColumnView ? classes.statisticsOneColumn : classes.statistics}>
        <Pie data={creationPlaces} groupBy={props.search.groupBy} query={props.search.query} />
  }

  let mainResultsView = '';
  if (oneColumnView) {
    switch(options.resultFormat) {
      case 'table': {
        mainResultsView = table;
        break;
      }
      case 'map': {
        mainResultsView = (
          <div className={classes.fullMap}>
esikkala's avatar
esikkala committed
            {mapElement}
          </div>
        );
        break;
      }
      case 'statistics': {
        mainResultsView = statistics;
        break;
      }
    }
    mainResultsView = table;
  return (
    <div className={classes.root}>
      <div className={classes.appFrame}>
        <TopBar
          oneColumnView={oneColumnView}
          mapMode={options.mapMode}
          resultFormat={options.resultFormat}
          updateMapMode={props.updateMapMode}
          updateResultFormat={props.updateResultFormat}
esikkala's avatar
esikkala committed
          fetchManuscripts={props.fetchManuscripts}
          fetchResults={props.fetchResults}
          toggleDataset={props.toggleDataset}
        <div className={classes.mainContainer}>
          {!oneColumnView &&
            <div className={classes.rightColumn}>
              <div className={classes.map}>
        <Paper className={classes.footer}>
Esko Ikkala's avatar
Esko Ikkala committed
          <img className={classes.oxfordLogo} src='img/logos/oxford-logo-white.png' alt='Oxford University logo'/>
          <img className={classes.pennLogo} src='img/logos/penn-logo-white.png' alt='Oxford University logo'/>
          <img className={classes.aaltoLogo} src='img/logos/aalto-logo-white-no-background-small.png' alt='Aalto University logo'/>
          <img className={classes.uhLogo} src='img/logos/university-of-helsinki-logo-white-no-background-small.png' alt='University of Helsinki logo'/>
          <img className={classes.secoLogo} src='img/logos/seco-logo-white-no-background-small.png' alt='SeCo logo'/>
          <img className={classes.heldigLogo} src='img/logos/heldig-logo-small.png' alt='HELDIG logo'/>
Esko Ikkala's avatar
Esko Ikkala committed

const mapStateToProps = (state) => {
  return {
    options: state.options,
    browser: state.browser,
    search: state.search,
Esko Ikkala's avatar
Esko Ikkala committed
    manuscripts:state.search.manuscripts,
    creationPlaces: state.search.places,
    place: state.search.place,
    results: state.search.results,
    page: state.search.page

const mapDispatchToProps = ({
  updateQuery,
Esko Ikkala's avatar
Esko Ikkala committed
  toggleDataset,
  fetchSuggestions,
  clearSuggestions,
  fetchManuscripts,
  fetchPlaces,
  fetchPlace,
  fetchResults,
  clearManuscripts,
  clearPlaces,
esikkala's avatar
esikkala committed
  sortResults,
  getGeoJSON,
  updateResultFormat,
Esko Ikkala's avatar
Esko Ikkala committed
  updateResultsFilter,
});

MapApp.propTypes = {
  classes: PropTypes.object.isRequired,
  theme: PropTypes.object.isRequired,
  //error: PropTypes.object.isRequired,
  browser: PropTypes.object.isRequired,

  options: PropTypes.object.isRequired,
  search: PropTypes.object.isRequired,
  map: PropTypes.object.isRequired,
  manuscripts: PropTypes.array,
  creationPlaces: PropTypes.array.isRequired,
  place: PropTypes.object.isRequired,
  manuscriptsPropertyValues: PropTypes.object.isRequired,
  facet: PropTypes.object.isRequired,
  results: PropTypes.number.isRequired,
  page: PropTypes.number.isRequired,
  updateQuery: PropTypes.func.isRequired,
Esko Ikkala's avatar
Esko Ikkala committed
  toggleDataset: PropTypes.func.isRequired,
  fetchSuggestions: PropTypes.func.isRequired,
  clearSuggestions: PropTypes.func.isRequired,
  fetchManuscripts: PropTypes.func.isRequired,
  fetchPlaces: PropTypes.func.isRequired,
  fetchPlace:  PropTypes.func.isRequired,
  fetchFacet: PropTypes.func.isRequired,
  fetchResults: PropTypes.func.isRequired,
  clearManuscripts: PropTypes.func.isRequired,
  clearPlaces: PropTypes.func.isRequired,
  clearFacet: PropTypes.func.isRequired,
esikkala's avatar
esikkala committed
  sortResults: PropTypes.func.isRequired,
Esko Ikkala's avatar
Esko Ikkala committed
  getGeoJSON: PropTypes.func.isRequired,
Esko Ikkala's avatar
Esko Ikkala committed
  bounceMarker: PropTypes.func.isRequired,
  openMarkerPopup: PropTypes.func.isRequired,
  removeTempMarker: PropTypes.func.isRequired,
  updateResultFormat: PropTypes.func.isRequired,
  updateMapMode: PropTypes.func.isRequired,
  updateResultsFilter: PropTypes.func.isRequired,
export default compose(
  connect(
    mapStateToProps,
    mapDispatchToProps
  ),
  withWidth(),
  withStyles(styles, {withTheme: true}),
)(MapApp);