mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 16:19:48 +02:00
Added mechanism for displaying fields conditionally based on tags
This commit is contained in:
@@ -233,6 +233,26 @@ For number fields, the lowest valid value. There is no default.
|
||||
|
||||
For number fields, the greatest valid value. There is no default.
|
||||
|
||||
##### `prerequisiteTag`
|
||||
|
||||
An object defining the tags the feature needs before this field will be displayed. It must have this property:
|
||||
|
||||
- `key`: The key for the required tag.
|
||||
|
||||
And may optionally have one of these properties:
|
||||
|
||||
- `value`: The value that the key must have.
|
||||
- `valueNot`: The value that the key must not have.
|
||||
|
||||
For example, this is how we show the Internet Access Field only if the feature has an `internet_access` tag not equal to `no`.
|
||||
|
||||
```js
|
||||
"prerequisiteTag": {
|
||||
"key": "internet_access",
|
||||
"valueNot": "no"
|
||||
}
|
||||
```
|
||||
|
||||
## Icons
|
||||
|
||||
You can use any of the following open source map icon sets as preset icons.
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
"dance/style": {"key": "dance:style", "type": "semiCombo", "label": "Dance Styles"},
|
||||
"date": {"key": "date", "type": "check", "label": "Date"},
|
||||
"delivery": {"key": "delivery", "type": "check", "label": "Delivery"},
|
||||
"denomination": {"key": "denomination", "type": "combo", "label": "Denomination"},
|
||||
"denomination": {"key": "denomination", "type": "combo", "label": "Denomination", "prerequisiteTag": {"key": "religion"}},
|
||||
"denotation": {"key": "denotation", "type": "combo", "label": "Denotation"},
|
||||
"description": {"key": "description", "type": "textarea", "label": "Description", "universal": true},
|
||||
"design": {"key": "design", "type": "combo", "label": "Design"},
|
||||
@@ -147,8 +147,8 @@
|
||||
"inscription": {"key": "inscription", "type": "textarea", "label": "Inscription"},
|
||||
"intermittent": {"key": "intermittent", "type": "check", "label": "Intermittent"},
|
||||
"internet_access": {"key": "internet_access", "type": "combo", "label": "Internet Access", "strings": {"options": {"yes": "Yes", "no": "No", "wlan": "Wifi", "wired": "Wired", "terminal": "Terminal"}}},
|
||||
"internet_access/fee": {"key": "internet_access:fee", "type": "check", "label": "Internet Access Fee"},
|
||||
"internet_access/ssid": {"key": "internet_access:ssid", "type": "text", "label": "SSID (Network Name)"},
|
||||
"internet_access/fee": {"key": "internet_access:fee", "type": "check", "label": "Internet Access Fee", "prerequisiteTag": {"key": "internet_access", "valueNot": "no"}},
|
||||
"internet_access/ssid": {"key": "internet_access:ssid", "type": "text", "label": "SSID (Network Name)", "prerequisiteTag": {"key": "internet_access", "valueNot": "no"}},
|
||||
"kerb": {"key": "kerb", "type": "combo", "label": "Curb"},
|
||||
"label": {"key": "label", "type": "textarea", "label": "Label"},
|
||||
"lamp_type": {"key": "lamp_type", "type": "combo", "label": "Type"},
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"key": "denomination",
|
||||
"type": "combo",
|
||||
"label": "Denomination"
|
||||
}
|
||||
"label": "Denomination",
|
||||
"prerequisiteTag": {
|
||||
"key": "religion"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"key": "internet_access:fee",
|
||||
"type": "check",
|
||||
"label": "Internet Access Fee"
|
||||
"label": "Internet Access Fee",
|
||||
"prerequisiteTag": {
|
||||
"key": "internet_access",
|
||||
"valueNot": "no"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"key": "internet_access:ssid",
|
||||
"type": "text",
|
||||
"label": "SSID (Network Name)"
|
||||
"label": "SSID (Network Name)",
|
||||
"prerequisiteTag": {
|
||||
"key": "internet_access",
|
||||
"valueNot": "no"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,28 @@
|
||||
"maxValue": {
|
||||
"description": "Maximum field value (number fields only)",
|
||||
"type": "integer"
|
||||
},
|
||||
"prerequisiteTag": {
|
||||
"description": "Tagging constraint for showing this field in the editor",
|
||||
"type": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"key": {
|
||||
"description": "The key of the required tag",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
"value": {
|
||||
"description": "The value that the tag must have. (alternative to 'valueNot')",
|
||||
"type": "string"
|
||||
},
|
||||
"valueNot": {
|
||||
"description": "The value that the tag cannot have. (alternative to 'value')",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
||||
+42
-5
@@ -40,10 +40,13 @@ export function uiField(context, presetField, entity, options) {
|
||||
dispatch.call('change', field, t, onInput);
|
||||
});
|
||||
|
||||
// if this field cares about the entity, pass it along
|
||||
if (entity && field.impl.entity) {
|
||||
if (entity) {
|
||||
field.entityID = entity.id;
|
||||
field.impl.entity(entity);
|
||||
|
||||
// if this field cares about the entity, pass it along
|
||||
if (field.impl.entity) {
|
||||
field.impl.entity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
field.keys = field.keys || [field.key];
|
||||
@@ -206,6 +209,11 @@ export function uiField(context, presetField, entity, options) {
|
||||
};
|
||||
|
||||
|
||||
field.hasValue = function() {
|
||||
return _some(field.keys, function(key) { return !!_tags[key]; });
|
||||
};
|
||||
|
||||
|
||||
field.show = function() {
|
||||
_show = true;
|
||||
if (field.default && field.key && _tags[field.key] !== field.default) {
|
||||
@@ -215,9 +223,38 @@ export function uiField(context, presetField, entity, options) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// A shown field has a visible UI, a non-shown field is in the 'Add field' dropdown
|
||||
field.isShown = function() {
|
||||
return _show || _some(field.keys, function(key) { return !!_tags[key]; });
|
||||
return _show || field.hasValue();
|
||||
};
|
||||
|
||||
// An allowed field can appear in the UI or in the 'Add field' dropdown.
|
||||
// A non-allowed field is hidden from the user altogether
|
||||
field.isAllowed = function() {
|
||||
|
||||
if (field.hasValue()) {
|
||||
// always allow a field with a value to display
|
||||
return true;
|
||||
}
|
||||
|
||||
var prerequisiteTag = field.prerequisiteTag;
|
||||
if (prerequisiteTag && field.entityID) {
|
||||
if (prerequisiteTag.key) {
|
||||
var value = context.graph().entity(field.entityID).tags[prerequisiteTag.key];
|
||||
if (value) {
|
||||
if (prerequisiteTag.valueNot) {
|
||||
return prerequisiteTag.valueNot !== value;
|
||||
}
|
||||
if (prerequisiteTag.value) {
|
||||
return prerequisiteTag.value === value;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -14,9 +14,18 @@ export function uiFormFields(context) {
|
||||
}
|
||||
|
||||
|
||||
formFields.tagsChanged = function() {};
|
||||
|
||||
function render(selection, klass) {
|
||||
var shown = _fieldsArr.filter(function(field) { return field.isShown(); });
|
||||
var notShown = _fieldsArr.filter(function(field) { return !field.isShown(); });
|
||||
|
||||
formFields.tagsChanged = function() {
|
||||
render(selection, klass);
|
||||
};
|
||||
|
||||
var allowedFields = _fieldsArr.filter(function(field) { return field.isAllowed(); });
|
||||
|
||||
var shown = allowedFields.filter(function(field) { return field.isShown(); });
|
||||
var notShown = allowedFields.filter(function(field) { return !field.isShown(); });
|
||||
|
||||
var container = selection.selectAll('.form-fields-container')
|
||||
.data([0]);
|
||||
|
||||
@@ -117,6 +117,7 @@ export function uiPresetEditor(context) {
|
||||
presetEditor.tags = function(val) {
|
||||
if (!arguments.length) return _tags;
|
||||
_tags = val;
|
||||
formFields.tagsChanged();
|
||||
// Don't reset _fieldsArr here.
|
||||
return presetEditor;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user