Moved field inheritance resolution from the data build to the preset initialization

Removed the data build check for duplicate values between fields and moreFields
Renamed the shop field from Type to Shop Type
Renamed the beauty field from Shop Type to Beauty Specialty
Added the brand field to the shop preset under moreFields
This commit is contained in:
Quincy Morgan
2019-01-15 09:53:26 -05:00
parent 78853e1dc1
commit ae7c099c8a
24 changed files with 1274 additions and 1293 deletions
+3 -40
View File
@@ -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;
@@ -258,39 +257,8 @@ function generatePresets(tstrings, faIcons) {
faIcons[preset.icon] = {};
}
});
presets = resolvePresetFieldInheritance(presets);
presets = _merge(presets, suggestionsToPresets(presets));
return presets;
}
// For presets without fields, use the fields of the parent preset.
// Replace "{inherit}" placeholders with the fields of the parent preset.
function resolvePresetFieldInheritance(presets) {
for (var id in presets) {
var endIndex = id.lastIndexOf('/');
if (endIndex < 0) {
continue;
}
var parentID = id.substring(0, endIndex);
var parentPreset = presets[parentID];
if (!parentPreset) {
continue;
}
var preset = presets[id];
['fields', 'moreFields'].forEach(function(fieldsKey) {
if (parentPreset[fieldsKey]) {
if (preset[fieldsKey]) {
var inheritIndex = preset[fieldsKey].indexOf('{inherit}');
if (inheritIndex >= 0) {
// replace the {inherit} placeholder with the parent preset's fields for the key
preset[fieldsKey].splice.apply(preset[fieldsKey], [inheritIndex, 1].concat(parentPreset[fieldsKey]));
}
} else {
preset[fieldsKey] = parentPreset[fieldsKey];
}
}
});
}
presets = _merge(presets, suggestionsToPresets(presets));
return presets;
}
@@ -493,7 +461,7 @@ function validatePresetFields(presets, fields) {
_forEach(presets, function(preset) {
if (preset.fields) {
preset.fields.forEach(function(field) {
if (fields[field] === undefined) {
if (field !== '{inherit}' && fields[field] === undefined) {
console.error('Unknown preset field "' + field + '" in "fields" array of preset ' + preset.name);
process.exit(1);
}
@@ -501,17 +469,12 @@ function validatePresetFields(presets, fields) {
}
if (preset.moreFields) {
preset.moreFields.forEach(function(field) {
if (fields[field] === undefined) {
if (field !== '{inherit}' && 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);
}
});
}
+2 -2
View File
@@ -226,7 +226,7 @@ en:
onsen: Japanese Onsen
beauty:
# beauty=*
label: Shop Type
label: Beauty Specialty
bench:
# bench=*
label: Bench
@@ -1637,7 +1637,7 @@ en:
label: Type
shop:
# shop=*
label: Type
label: Shop Type
siren/purpose:
# 'siren:purpose=*'
label: Purpose
+2 -2
View File
@@ -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"},
@@ -280,7 +280,7 @@
"service/vehicle": {"key": "service:vehicle:", "type": "multiCombo", "label": "Services"},
"shelter_type": {"key": "shelter_type", "type": "combo", "label": "Type"},
"shelter": {"key": "shelter", "type": "check", "label": "Shelter"},
"shop": {"key": "shop", "type": "typeCombo", "label": "Type"},
"shop": {"key": "shop", "type": "typeCombo", "label": "Shop Type"},
"siren/purpose": {"key": "siren:purpose", "type": "combo", "label": "Purpose"},
"siren/type": {"key": "siren:type", "type": "combo", "label": "Type", "strings": {"options": {"pneumatic": "Pneumatic", "electronic": "Electronic", "other": "Other"}}},
"site_type": {"key": "site_type", "type": "combo", "label": "Site Type"},
+1 -1
View File
@@ -1,5 +1,5 @@
{
"key": "beauty",
"type": "combo",
"label": "Shop Type"
"label": "Beauty Specialty"
}
+2 -2
View File
@@ -1,5 +1,5 @@
{
"key": "shop",
"type": "typeCombo",
"label": "Type"
}
"label": "Shop Type"
}
+1196 -1196
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -9,7 +9,8 @@
],
"moreFields": [
"opening_hours",
"payment_multi"
"payment_multi",
"brand"
],
"geometry": [
"point",
+1 -4
View File
@@ -1,10 +1,7 @@
{
"icon": "maki-bicycle",
"fields": [
"name",
"operator",
"address",
"building_area",
"{inherit}",
"service/bicycle"
],
"geometry": [
+1 -3
View File
@@ -3,9 +3,7 @@
"fields": [
"name",
"clothes",
"operator",
"address",
"building_area"
"{inherit}"
],
"geometry": [
"point",
+1 -3
View File
@@ -3,9 +3,7 @@
"fields": [
"name",
"brand",
"operator",
"address",
"building_area",
"{inherit}",
"second_hand",
"service/vehicle"
],
+1 -4
View File
@@ -1,10 +1,7 @@
{
"icon": "maki-car-repair",
"fields": [
"name",
"operator",
"address",
"building_area",
"{inherit}",
"service/vehicle"
],
"geometry": [
+1 -3
View File
@@ -3,9 +3,7 @@
"fields": [
"name",
"brand",
"operator",
"address",
"building_area",
"{inherit}",
"second_hand",
"service/vehicle"
],
+1 -4
View File
@@ -1,10 +1,7 @@
{
"icon": "maki-shop",
"fields": [
"name",
"operator",
"address",
"building_area",
"{inherit}",
"second_hand"
],
"geometry": [
+3 -2
View File
@@ -1,8 +1,9 @@
{
"icon": "maki-clothing-store",
"fields": [
"{inherit}",
"clothes"
"name",
"clothes",
"{inherit}"
],
"geometry": [
"point",
+1 -3
View File
@@ -3,9 +3,7 @@
"fields": [
"name",
"clothes",
"operator",
"address",
"building_area"
"{inherit}"
],
"geometry": [
"point",
+1 -3
View File
@@ -1,9 +1,7 @@
{
"icon": "maki-shop",
"fields": [
"name",
"operator",
"address",
"{inherit}",
"fuel_multi",
"building_area"
],
+1 -4
View File
@@ -1,10 +1,7 @@
{
"icon": "maki-shop",
"fields": [
"name",
"operator",
"address",
"building_area",
"{inherit}",
"levels"
],
"geometry": [
+1 -3
View File
@@ -3,9 +3,7 @@
"fields": [
"name",
"brand",
"operator",
"address",
"building_area"
"{inherit}"
],
"geometry": [
"point",
@@ -1,10 +1,7 @@
{
"icon": "fas-motorcycle",
"fields": [
"name",
"operator",
"address",
"building_area",
"{inherit}",
"service/vehicle"
],
"geometry": [
+3 -2
View File
@@ -1,8 +1,9 @@
{
"icon": "maki-shop",
"fields": [
"{inherit}",
"trade"
"name",
"trade",
"{inherit}"
],
"geometry": [
"point",
+2 -2
View File
@@ -5403,7 +5403,7 @@
},
{
"key": "shop",
"description": "🄿 Shop, 🄵 Type",
"description": "🄿 Shop, 🄵 Shop Type",
"object_types": ["node", "area"],
"icon_url": "https://raw.githubusercontent.com/mapbox/maki/master/icons/shop-15.svg?sanitize=true"
},
@@ -7133,7 +7133,7 @@
{"key": "bath:type", "value": "onsen", "description": "🄵 Specialty"},
{"key": "bath:type", "value": "foot_bath", "description": "🄵 Specialty"},
{"key": "bath:type", "value": "hot_spring", "description": "🄵 Specialty"},
{"key": "beauty", "description": "🄵 Shop Type"},
{"key": "beauty", "description": "🄵 Beauty Specialty"},
{"key": "bench", "description": "🄵 Bench"},
{"key": "bicycle_parking", "description": "🄵 Type"},
{"key": "bin", "description": "🄵 Waste Bin"},
+2 -2
View File
@@ -2014,7 +2014,7 @@
}
},
"beauty": {
"label": "Shop Type"
"label": "Beauty Specialty"
},
"bench": {
"label": "Bench"
@@ -3191,7 +3191,7 @@
"label": "Shelter"
},
"shop": {
"label": "Type"
"label": "Shop Type"
},
"siren/purpose": {
"label": "Purpose"
+3 -2
View File
@@ -136,12 +136,13 @@ export function presetIndex() {
_universal.splice(_universal.indexOf(_fields.wikipedia)+1, 0, _fields.wikidata);
if (d.presets) {
var rawPresets = d.presets;
_forEach(d.presets, function(d, id) {
var existing = all.index(id);
if (existing !== -1) {
all.collection[existing] = presetPreset(id, d, _fields, visible);
all.collection[existing] = presetPreset(id, d, _fields, visible, rawPresets);
} else {
all.collection.push(presetPreset(id, d, _fields, visible));
all.collection.push(presetPreset(id, d, _fields, visible, rawPresets));
}
});
}
+42 -1
View File
@@ -1,14 +1,55 @@
import _clone from 'lodash-es/clone';
import _omit from 'lodash-es/omit';
import _union from 'lodash-es/union';
import { t } from '../util/locale';
import { areaKeys } from '../core/context';
export function presetPreset(id, preset, fields, visible) {
export function presetPreset(id, preset, fields, visible, rawPresets) {
preset = _clone(preset);
preset.id = id;
preset.parentPresetID = function() {
var endIndex = preset.id.lastIndexOf('/');
if (endIndex < 0) {
return null;
}
return preset.id.substring(0, endIndex);
};
// For a preset without fields, use the fields of the parent preset.
// Replace "{inherit}" placeholders with the fields of the parent preset.
function resolveFieldInheritance() {
var parentPreset = rawPresets[preset.parentPresetID()];
if (parentPreset) {
// the property keys that contain arrays of field ids
var fieldKeys = ['fields', 'moreFields'];
fieldKeys.forEach(function(fieldsKey) {
if (parentPreset[fieldsKey]) {
if (preset[fieldsKey]) {
var inheritIndex = preset[fieldsKey].indexOf('{inherit}');
if (inheritIndex >= 0) {
// replace the {inherit} placeholder with the parent preset's fields
preset[fieldsKey].splice.apply(preset[fieldsKey], [inheritIndex, 1].concat(parentPreset[fieldsKey]));
// remove duplicates
preset[fieldsKey] = _union(preset[fieldsKey]);
}
} else {
// there are no fields defined, so use the parent's
preset[fieldsKey] = parentPreset[fieldsKey];
}
// update the raw object to allow for multiple levels of inheritance
rawPresets[preset.id][fieldsKey] = preset[fieldsKey];
}
});
}
}
if (rawPresets) {
resolveFieldInheritance();
}
preset.fields = (preset.fields || []).map(getFields);
preset.moreFields = (preset.moreFields || []).map(getFields);
preset.geometry = (preset.geometry || []);