Skip to content

Commit

Permalink
Merge pull request #5582 from quincylvania/more-fields
Browse files Browse the repository at this point in the history
Define additional preset-specific fields for the "Add field" dropdown
  • Loading branch information
quincylvania authored Dec 9, 2018
2 parents cbcafae + 4285f2f commit f9552e6
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 121 deletions.
17 changes: 16 additions & 1 deletion build_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const requireESM = require('esm')(module);
const _cloneDeep = requireESM('lodash-es/cloneDeep').default;
const _forEach = requireESM('lodash-es/forEach').default;
const _intersection = requireESM('lodash-es/intersection').default;
const _isEmpty = requireESM('lodash-es/isEmpty').default;
const _merge = requireESM('lodash-es/merge').default;
const _toPairs = requireESM('lodash-es/toPairs').default;
Expand Down Expand Up @@ -214,6 +215,7 @@ function suggestionsToPresets(presets) {
name: name,
icon: preset.icon,
fields: preset.fields,
moreFields: preset.moreFields,
geometry: preset.geometry,
tags: _merge({}, preset.tags, wikidataTag),
addTags: suggestion.tags,
Expand Down Expand Up @@ -461,11 +463,24 @@ function validatePresetFields(presets, fields) {
if (preset.fields) {
preset.fields.forEach(function(field) {
if (fields[field] === undefined) {
console.error('Unknown preset field: ' + field + ' in preset ' + preset.name);
console.error('Unknown preset field "' + field + '" in "fields" array of preset ' + preset.name);
process.exit(1);
}
});
}
if (preset.moreFields) {
preset.moreFields.forEach(function(field) {
if (fields[field] === undefined) {
console.error('Unknown preset field "' + field + '" in "moreFields" array of preset ' + preset.name);
process.exit(1);
}
});
}
var fieldsIntersection = _intersection(preset.fields, preset.moreFields);
if (fieldsIntersection.length > 0) {
console.error('Preset field "' + fieldsIntersection[0] + '" in both "fields" and "moreFields" arrays of preset ' + preset.name);
process.exit(1);
}
});
}

Expand Down
9 changes: 8 additions & 1 deletion data/presets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ A basic preset is of the form:
{
// The icon in iD which represents this feature.
"icon": "maki-park",
// An array of field names. See the fields documentation for details of what's valid here.
// The names of fields that will appear by default in the editor sidebar.
// See the fields documentation for details of what's valid here.
"fields": [
"address"
],
// The names of fields that the user can add manually. These will also
// appear if the corresponding tags are present.
"moreFields": [
"phone",
"website"
],
// The geometry types for which this preset is valid.
// options are point, area, line, and vertex.
// vertexes are points that are parts of lines, like the nodes in a road
Expand Down
206 changes: 103 additions & 103 deletions data/presets/presets.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion data/presets/presets/amenity/cafe.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
"opening_hours",
"internet_access",
"internet_access/fee",
"internet_access/ssid",
"smoking",
"outdoor_seating",
"takeaway"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
"point",
"area"
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/amenity/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"opening_hours",
"internet_access",
"internet_access/fee",
"internet_access/ssid",
"ref/isil"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
"point",
"area"
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/amenity/love_hotel.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"smoking",
"rooms",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/leisure/marina.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"sanitary_dump_station",
"power_supply",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/tourism/alpine_hut.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"address",
"building_area",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/tourism/apartment.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"smoking",
"rooms",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/tourism/camp_site.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"capacity",
"fee",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/tourism/caravan_site.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"sanitary_dump_station",
"power_supply",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/tourism/chalet.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"building_area",
"smoking",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/tourism/guest_house.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"smoking",
"rooms",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/tourism/hostel.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"smoking",
"rooms",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
6 changes: 4 additions & 2 deletions data/presets/presets/tourism/hotel.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"address",
"building_area",
"smoking",
"stars",
"rooms",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields": [
"stars",
"internet_access/ssid"
],
"geometry": [
Expand Down
4 changes: 3 additions & 1 deletion data/presets/presets/tourism/motel.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"smoking",
"rooms",
"internet_access",
"internet_access/fee",
"internet_access/fee"
],
"moreFields" : [
"internet_access/ssid"
],
"geometry": [
Expand Down
9 changes: 8 additions & 1 deletion data/presets/schema/preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@
}
},
"fields": {
"description": "Form fields that are displayed for the preset",
"description": "Default form fields that are displayed for the preset",
"type": "array",
"items": {
"type": "string"
}
},
"moreFields": {
"description": "Additional form fields that can be attached with the 'Add field' dropdown",
"type": "array",
"items": {
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions modules/presets/preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function presetPreset(id, preset, fields) {

preset.id = id;
preset.fields = (preset.fields || []).map(getFields);
preset.moreFields = (preset.moreFields || []).map(getFields);
preset.geometry = (preset.geometry || []);


Expand Down
10 changes: 9 additions & 1 deletion modules/ui/preset_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,22 @@ export function uiPresetEditor(context) {
);
}

presets.universal().forEach(function(field) {
_preset.moreFields.forEach(function(field) {
if (_preset.fields.indexOf(field) === -1) {
_fieldsArr.push(
uiField(context, field, entity, { show: false })
);
}
});

presets.universal().forEach(function(field) {
if (_preset.fields.indexOf(field) === -1 && _preset.moreFields.indexOf(field) === -1) {
_fieldsArr.push(
uiField(context, field, entity, { show: false })
);
}
});

_fieldsArr.forEach(function(field) {
field
.on('change', function(t, onInput) {
Expand Down

0 comments on commit f9552e6

Please sign in to comment.