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 -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 || []);