Default 0 storeys (handle nulls)

This commit is contained in:
Tom Russell 2018-09-30 23:06:30 +01:00
parent a9b3a394de
commit ddd300405c
4 changed files with 23 additions and 20 deletions

View File

@ -27,9 +27,9 @@ class BuildingEdit extends Component {
facade_upper: props.facade_upper, facade_upper: props.facade_upper,
facade_lower: props.facade_lower, facade_lower: props.facade_lower,
facade_source: props.facade_source, facade_source: props.facade_source,
size_attic: props.size_attic, size_storeys_attic: props.size_storeys_attic,
size_core: props.size_core, size_storeys_core: props.size_storeys_core,
size_basement: props.size_basement, size_storeys_basement: props.size_storeys_basement,
likes_total: props.likes_total, likes_total: props.likes_total,
liked: props.liked liked: props.liked
}; };
@ -41,7 +41,7 @@ class BuildingEdit extends Component {
handleChange(event) { handleChange(event) {
const target = event.target; const target = event.target;
const value = target.value; const value = (target.value === '')? null : target.value;
const name = target.name; const name = target.name;
this.setState({ this.setState({
@ -202,24 +202,24 @@ class BuildingEdit extends Component {
<legend className="h3 bullet-prefix size">Size</legend> <legend className="h3 bullet-prefix size">Size</legend>
<div id="data-list-size" className="data-list"> <div id="data-list-size" className="data-list">
<label htmlFor="size_attic">Attic storeys</label> <label htmlFor="size_storeys_attic">Attic storeys</label>
<input className="form-control" type="number" step="1" <input className="form-control" type="number" step="1"
id="size_attic" name="size_attic" id="size_storeys_attic" name="size_storeys_attic"
value={this.state.size_attic} value={this.state.size_storeys_attic}
onChange={this.handleChange} onChange={this.handleChange}
/> />
<label htmlFor="size_core">Core storeys</label> <label htmlFor="size_storeys_core">Core storeys</label>
<input className="form-control" type="number" step="1" <input className="form-control" type="number" step="1"
id="size_core" name="size_core" id="size_storeys_core" name="size_storeys_core"
value={this.state.size_core} value={this.state.size_storeys_core}
onChange={this.handleChange} onChange={this.handleChange}
/> />
<label htmlFor="size_basement">Basement storeys</label> <label htmlFor="size_storeys_basement">Basement storeys</label>
<input className="form-control" type="number" step="1" <input className="form-control" type="number" step="1"
id="size_basement" name="size_basement" id="size_storeys_basement" name="size_storeys_basement"
value={this.state.size_basement} value={this.state.size_storeys_basement}
onChange={this.handleChange} onChange={this.handleChange}
/> />
</div> </div>

View File

@ -64,11 +64,11 @@ const BuildingView = function(props){
<h3 className="h3 bullet-prefix size">Size</h3> <h3 className="h3 bullet-prefix size">Size</h3>
<dl className="data-list"> <dl className="data-list">
<dt>Attic storeys</dt> <dt>Attic storeys</dt>
<dd>{props.size_attic? props.size_attic : '-'}</dd> <dd>{props.size_storeys_attic? props.size_storeys_attic : '-'}</dd>
<dt>Core storeys</dt> <dt>Core storeys</dt>
<dd>{props.size_core? props.size_core : '-'}</dd> <dd>{props.size_storeys_core? props.size_storeys_core : '-'}</dd>
<dt>Basement storeys</dt> <dt>Basement storeys</dt>
<dd>{props.size_basement? props.size_basement : '-'}</dd> <dd>{props.size_storeys_basement? props.size_storeys_basement : '-'}</dd>
</dl> </dl>
</section> </section>
<section className="data-section"> <section className="data-section">

View File

@ -81,7 +81,10 @@ router.get('/size_storeys/:z/:x/:y.png', function(req, res) {
// const table_def = 'geometries' // const table_def = 'geometries'
const table_def = `( const table_def = `(
SELECT SELECT
(b.size_attic + b.size_core) as size_storeys, (
coalesce(b.size_storeys_attic, 0) +
coalesce(b.size_storeys_core, 0)
) as size_storeys,
g.geometry_geom g.geometry_geom
FROM FROM
geometries as g, geometries as g,

View File

@ -51,11 +51,11 @@ ALTER TABLE buildings ADD CONSTRAINT buildings_facade_source_len CHECK (length(f
-- Size -- Size
-- Attic storeys -- Attic storeys
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_storeys_attic smallint; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_storeys_attic smallint DEFAULT 0;
-- Core storeys -- Core storeys
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_storeys_core smallint; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_storeys_core smallint DEFAULT 0;
-- Basement storeys -- Basement storeys
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_storeys_basement smallint; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_storeys_basement smallint DEFAULT 0;
-- Height to apex (m) -- Height to apex (m)
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_height_apex real; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_height_apex real;