Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preset field inheritance #5712

Merged
merged 6 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions build_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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 @@ -459,28 +458,29 @@ function validateCategoryPresets(categories, presets) {
}

function validatePresetFields(presets, fields) {
var betweenBracketsRegex = /([^{]*?)(?=\})/;
_forEach(presets, function(preset) {
if (preset.fields) {
preset.fields.forEach(function(field) {
if (fields[field] === undefined) {
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);
}
// the keys for properties that contain arrays of field ids
var fieldKeys = ['fields', 'moreFields'];
fieldKeys.forEach(function(fieldsKey) {
if (preset[fieldsKey]) {
preset[fieldsKey].forEach(function(field) {
if (fields[field] === undefined) {
var regexResult = betweenBracketsRegex.exec(field);
if (regexResult) {
var foreignPresetID = regexResult[0];
if (presets[foreignPresetID] === undefined) {
console.error('Unknown preset "' + foreignPresetID + '" referenced in "' + fieldsKey + '" array of preset ' + preset.name);
process.exit(1);
}
} else {
console.error('Unknown preset field "' + field + '" in "' + fieldsKey + '" array of preset ' + preset.name);
process.exit(1);
}
}
});
}
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion data/presets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ en:
onsen: Japanese Onsen
beauty:
# beauty=*
label: Shop Type
label: Beauty Specialty
bench:
# bench=*
label: Bench
Expand Down
35 changes: 34 additions & 1 deletion data/presets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,40 @@ The complete JSON schema for presets can be found in [`data/presets/schema/prese

#### Preset Properties

##### searchable
##### `fields`/`moreFields`

Both these properties are arrays of field paths (e.g. `description` or `generator/type`).
`fields` are shown by default and `moreFields` are shown if manually added by the
user or if a matching tag is present. Note that some fields have a `prerequisiteTag`
property that limits when they will be shown.

A preset can reference the fields of another by using that preset's name contained in
brackets, like `{preset}`. For example, `shop/books` references and extends the fields
of `shop`:

```javascript
"fields": [
"{shop}",
"internet_access"
],
"moreFields": [
"{shop}",
"internet_access/fee",
"internet_access/ssid"
],
"tags": {
"shop": "books"
}
```

If `fields` or `moreFields` are not defined, the values of the preset's "parent"
preset are used. For example, `shop/convenience` automatically uses the same
fields as `shop`.

In both explicit and implicit inheritance, fields for keys that define the
preset are not inherited. E.g. the `shop` field is not inherited by `shop/…` presets.

##### `searchable`

Deprecated or generic presets can include the property `"searchable": false`.
This means that they will be recognized by iD when editing existing data,
Expand Down
2 changes: 1 addition & 1 deletion data/presets/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"bath/open_air": {"key": "bath:open_air", "label": "Open Air", "type": "check"},
"bath/sand_bath": {"key": "bath:sand_bath", "label": "Sand Bath", "type": "check"},
"bath/type": {"key": "bath:type", "type": "combo", "label": "Specialty", "strings": {"options": {"onsen": "Japanese Onsen", "foot_bath": "Foot Bath", "hot_spring": "Hot Spring"}}},
"beauty": {"key": "beauty", "type": "combo", "label": "Shop Type"},
"beauty": {"key": "beauty", "type": "combo", "label": "Beauty Specialty"},
"bench": {"key": "bench", "type": "check", "label": "Bench"},
"bicycle_parking": {"key": "bicycle_parking", "type": "combo", "label": "Type"},
"bin": {"key": "bin", "type": "check", "label": "Waste Bin"},
Expand Down
2 changes: 1 addition & 1 deletion data/presets/fields/beauty.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"key": "beauty",
"type": "combo",
"label": "Shop Type"
"label": "Beauty Specialty"
}
2 changes: 1 addition & 1 deletion data/presets/fields/shop.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"key": "shop",
"type": "typeCombo",
"label": "Type"
}
}
Loading