From 60371afd03dc4c1f9533771807b6e9bbc8992eea Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Thu, 9 May 2019 09:16:36 +0100 Subject: [PATCH] Sketch out hardcoded multi-edit --- app/src/frontend/app.js | 50 ++++++++++++++++++++++++++++++++-- app/src/frontend/map.css | 3 ++ app/src/frontend/map.js | 23 ++++++++++++---- app/src/frontend/multi-edit.js | 25 +++++++++++++++++ 4 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 app/src/frontend/multi-edit.js diff --git a/app/src/frontend/app.js b/app/src/frontend/app.js index 2581d1c7..02d00e5b 100644 --- a/app/src/frontend/app.js +++ b/app/src/frontend/app.js @@ -8,6 +8,7 @@ import './app.css'; import AboutPage from './about'; import BuildingEdit from './building-edit'; import BuildingView from './building-view'; +import MultiEdit from './multi-edit'; import ColouringMap from './map'; import Header from './header'; import Overview from './overview'; @@ -31,15 +32,20 @@ import Welcome from './welcome'; class App extends React.Component { constructor(props) { super(props); + // set building revision id, default 0 + const rev = (props.building)? props.building.revision_id : 0; this.state = { user: props.user, building: props.building, - building_like: props.building_like + building_like: props.building_like, + revision_id: rev }; this.login = this.login.bind(this); this.updateUser = this.updateUser.bind(this); this.logout = this.logout.bind(this); this.selectBuilding = this.selectBuilding.bind(this); + this.colourBuilding = this.colourBuilding.bind(this); + this.increaseRevision = this.increaseRevision.bind(this); } login(user) { @@ -58,8 +64,16 @@ class App extends React.Component { this.setState({user: undefined}); } + increaseRevision(revision_id) { + // bump revision id, only ever increasing + if (revision_id > this.state.revision_id){ + this.setState({revision_id: revision_id}) + } + } + selectBuilding(building) { - // get UPRNs and update + this.increaseRevision(building.revision_id); + // get UPRNs and update fetch(`/building/${building.building_id}/uprns.json`, { method: 'GET', headers:{ @@ -101,6 +115,28 @@ class App extends React.Component { }); } + colourBuilding(building) { + fetch(`/building/${building.building_id}.json`, { + method: 'POST', + body: JSON.stringify({date_year: 1999}), // TODO link to multi/pass in data + headers:{ + 'Content-Type': 'application/json' + }, + credentials: 'same-origin' + }).then( + res => res.json() + ).then(res => { + if (res.error) { + console.error({error: res.error}) + } else { + console.log(res); + this.increaseRevision(res.revision_id); + } + }).catch( + (err) => console.error({error: err}) + ); + } + render() { return ( @@ -122,6 +158,12 @@ class App extends React.Component { mode='edit' user={this.state.user} /> ) } /> + ( + + ) } /> ( - ( + ( ) } /> diff --git a/app/src/frontend/map.css b/app/src/frontend/map.css index 39950f36..bd6e4106 100644 --- a/app/src/frontend/map.css +++ b/app/src/frontend/map.css @@ -20,3 +20,6 @@ border: 1px solid #fff; box-shadow: 0 0 1px 1px #222; } +.leaflet-grab { + cursor: crosshair; +} diff --git a/app/src/frontend/map.js b/app/src/frontend/map.js index 2ce1f243..86314a32 100644 --- a/app/src/frontend/map.js +++ b/app/src/frontend/map.js @@ -29,6 +29,7 @@ class ColouringMap extends Component { this.handleClick = this.handleClick.bind(this); this.handleLocate = this.handleLocate.bind(this); this.themeSwitch = this.themeSwitch.bind(this); + this.getMode = this.getMode.bind(this); } handleLocate(lat, lng, zoom){ @@ -39,9 +40,14 @@ class ColouringMap extends Component { }) } - handleClick(e) { + getMode() { const isEdit = this.props.match.url.match('edit') - const mode = isEdit? 'edit': 'view'; + const isMulti = this.props.match.url.match('multi') + return isEdit? (isMulti? 'multi' : 'edit') : 'view'; + } + + handleClick(e) { + const mode = this.getMode() const lat = e.latlng.lat const lng = e.latlng.lng const newCat = parseCategoryURL(this.props.match.url); @@ -53,8 +59,13 @@ class ColouringMap extends Component { ).then(function(data){ if (data && data.length){ const building = data[0]; - this.props.selectBuilding(building); - this.props.history.push(`/${mode}/${mapCat}/building/${building.building_id}.html`); + if (mode === 'multi') { + // colour building directly + this.props.colourBuilding(building); + } else { + this.props.selectBuilding(building); + this.props.history.push(`/${mode}/${map_cat}/building/${building.building_id}.html`); + } } else { // deselect but keep/return to expected colour theme this.props.selectBuilding(undefined); @@ -94,8 +105,8 @@ class ColouringMap extends Component { } const tileset = tilesetByCat[cat]; // pick revision id to bust browser cache - const rev = this.props.building? this.props.building.revision_id : ''; - const dataLayer = tileset? + const rev = this.props.revision_id; + const dataLayer = data_tileset? { + if (!props.user){ + return + } + const cat = parseCategoryURL(props.match.url); + return ( + +
+

Click a building to colour

+

Set Year built to 1999

+
+
+ ); +} + +export default MultiEdit;