2018-10-01 07:45:33 -04:00
|
|
|
import React, { Fragment } from 'react';
|
2018-09-30 19:13:01 -04:00
|
|
|
import { Link, NavLink } from 'react-router-dom';
|
2018-10-04 17:50:33 -04:00
|
|
|
import queryString from 'query-string';
|
2018-09-09 17:22:44 -04:00
|
|
|
|
2018-09-11 15:59:59 -04:00
|
|
|
import Sidebar from './sidebar';
|
|
|
|
import Tooltip from './tooltip';
|
2018-09-13 15:41:42 -04:00
|
|
|
import InfoBox from './info-box';
|
2018-10-01 12:20:25 -04:00
|
|
|
import { HelpIcon, EditIcon } from './icons';
|
2018-09-11 15:59:59 -04:00
|
|
|
|
2018-10-03 16:47:49 -04:00
|
|
|
import CONFIG from './fields-config.json';
|
2018-09-30 19:32:24 -04:00
|
|
|
|
2018-10-03 16:47:49 -04:00
|
|
|
|
|
|
|
const BuildingView = (props) => {
|
|
|
|
if (!props.building_id){
|
|
|
|
return (
|
|
|
|
<Sidebar title="Building Not Found">
|
|
|
|
<InfoBox msg="We can't find that one anywhere - try the map again?" />
|
|
|
|
<div className="buttons-container with-space">
|
2018-10-05 17:20:02 -04:00
|
|
|
<Link to="/map/age.html" className="btn btn-secondary">Back to maps</Link>
|
2018-10-03 16:47:49 -04:00
|
|
|
</div>
|
|
|
|
</Sidebar>
|
|
|
|
);
|
|
|
|
}
|
2018-10-04 17:50:33 -04:00
|
|
|
const search = (props.location && props.location.search)? queryString.parse(props.location.search): {};
|
2018-10-03 16:47:49 -04:00
|
|
|
return (
|
2018-10-25 06:18:42 -04:00
|
|
|
<Sidebar title={`Building Data`} back={search.cat? `/map/${search.cat}.html` : "/map/age.html"}>
|
2018-10-03 16:47:49 -04:00
|
|
|
{
|
|
|
|
CONFIG.map(section_props => (
|
|
|
|
<DataSection
|
2018-10-04 17:50:33 -04:00
|
|
|
key={section_props.slug} search={search}
|
2018-10-03 16:47:49 -04:00
|
|
|
building_id={props.building_id}
|
2018-10-04 17:50:33 -04:00
|
|
|
{...section_props}>
|
2018-10-03 16:47:49 -04:00
|
|
|
{
|
|
|
|
section_props.fields.map(field_props => (
|
|
|
|
<DataEntry
|
2018-10-04 17:50:33 -04:00
|
|
|
key={field_props.slug}
|
2018-10-03 16:47:49 -04:00
|
|
|
title={field_props.title}
|
|
|
|
value={props[field_props.slug]}
|
|
|
|
tooltip={field_props.tooltip} />
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</DataSection>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</Sidebar>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const DataSection = (props) => {
|
2018-10-04 17:50:33 -04:00
|
|
|
const match = props.search.cat === props.slug;
|
2018-09-30 19:32:24 -04:00
|
|
|
return (
|
2018-10-03 16:47:49 -04:00
|
|
|
<section id={props.slug} className={(props.inactive)? "data-section inactive": "data-section"}>
|
2018-10-25 07:15:19 -04:00
|
|
|
<header className={(match? "active " : "") + " section-header view"}>
|
2018-10-04 17:50:33 -04:00
|
|
|
<NavLink
|
|
|
|
to={`/building/${props.building_id}.html` + ((match)? '': `?cat=${props.slug}`)}
|
2018-10-25 05:47:19 -04:00
|
|
|
title={(props.inactive)? 'Coming soon… Click the ? for more info.' :
|
|
|
|
(match)? 'Hide details' : 'Show details'}
|
2018-10-04 17:50:33 -04:00
|
|
|
isActive={() => match}>
|
2018-10-01 11:59:39 -04:00
|
|
|
<h3 className="h3">{props.title}</h3>
|
|
|
|
</NavLink>
|
2018-10-05 04:10:20 -04:00
|
|
|
<nav className="icon-buttons">
|
2018-10-01 11:59:39 -04:00
|
|
|
{
|
2018-10-04 17:50:33 -04:00
|
|
|
props.help?
|
2018-10-25 06:48:25 -04:00
|
|
|
<a className="icon-button help" title="Find out more" href={props.help}>
|
|
|
|
Help
|
2018-10-01 12:20:25 -04:00
|
|
|
<HelpIcon />
|
2018-10-01 11:59:39 -04:00
|
|
|
</a>
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
{
|
|
|
|
!props.inactive?
|
2018-10-04 17:50:33 -04:00
|
|
|
<NavLink className="icon-button edit" title="Edit data"
|
|
|
|
to={`/building/${props.building_id}/edit.html?cat=${props.slug}`}>
|
2018-10-25 06:48:25 -04:00
|
|
|
Edit
|
2018-10-01 11:59:39 -04:00
|
|
|
<EditIcon />
|
|
|
|
</NavLink>
|
|
|
|
: null
|
|
|
|
}
|
2018-10-05 04:10:20 -04:00
|
|
|
</nav>
|
2018-10-01 11:59:39 -04:00
|
|
|
</header>
|
2018-10-03 16:47:49 -04:00
|
|
|
{ match? <dl className="data-list">{props.children}</dl> : null }
|
2018-10-01 11:59:39 -04:00
|
|
|
{
|
2018-10-01 07:45:33 -04:00
|
|
|
(match && !props.inactive)?
|
|
|
|
<div className="buttons-container with-space">
|
2018-10-05 13:41:12 -04:00
|
|
|
<Link to={`/building/${props.building_id}/edit.html?cat=${props.slug}`} className="btn btn-primary">Edit data</Link>
|
2018-10-01 07:45:33 -04:00
|
|
|
</div>
|
|
|
|
: null
|
2018-10-01 11:59:39 -04:00
|
|
|
}
|
2018-09-30 19:32:24 -04:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-03 16:47:49 -04:00
|
|
|
const DataEntry = (props) => (
|
|
|
|
<Fragment>
|
|
|
|
<dt>
|
|
|
|
{ props.title }
|
|
|
|
{ props.tooltip? <Tooltip text={ props.tooltip } /> : null }
|
|
|
|
</dt>
|
2018-10-25 06:52:11 -04:00
|
|
|
<dd>{props.value ? props.value : '\u00A0'}</dd>
|
2018-10-03 16:47:49 -04:00
|
|
|
</Fragment>
|
|
|
|
);
|
2018-09-09 17:22:44 -04:00
|
|
|
|
|
|
|
export default BuildingView;
|