Add countryCodes property to preset schema

Copy countryCodes from name suggestion index
Use countryCodes to filter the preset search results (close #6124)
This commit is contained in:
Quincy Morgan
2019-03-28 11:44:05 -04:00
parent d18b951c67
commit b12e7277df
6 changed files with 1541 additions and 1505 deletions
+1
View File
@@ -243,6 +243,7 @@ function suggestionsToPresets(presets) {
addTags: suggestion.tags,
removeTags: suggestion.tags,
reference: preset.reference,
countryCodes: suggestion.countryCodes,
matchScore: 2,
suggestion: true
};
+6
View File
@@ -58,6 +58,12 @@ The complete JSON schema for presets can be found in [`data/presets/schema/prese
#### Preset Properties
##### `countryCodes`
An array of two-letter, lowercase [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes. The preset will only be searchable when the user is editing over the specified countries. The locale and language of iD are not factors, just the position of the map.
By default, presets are available everywhere.
##### `fields`/`moreFields`
Both these properties are arrays of field paths (e.g. `description` or `generator/type`).
+1495 -1495
View File
File diff suppressed because it is too large Load Diff
+9
View File
@@ -95,6 +95,15 @@
"replacement": {
"description": "The ID of a preset that is preferable to this one",
"type": "string"
},
"countryCodes": {
"description": "Countries where to display the preset, as lowercase ISO 3166-1 alpha-2 codes (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)",
"type": "array",
"uniqueItems": true,
"items": {
"type": "string",
"pattern": "^[a-z]{2}$"
}
}
},
"additionalProperties": false
+10 -4
View File
@@ -41,7 +41,7 @@ export function presetCollection(collection) {
return this.item(id);
},
search: function(value, geometry) {
search: function(value, geometry, countryCode) {
if (!value) return this;
value = value.toLowerCase();
@@ -78,11 +78,17 @@ export function presetCollection(collection) {
return aCompare.length - bCompare.length;
}
var searchable = this.collection.filter(function(a) {
var pool = this.collection;
if (countryCode) {
pool = pool.filter(function(a) {
if (!a.countryCodes) return true;
return a.countryCodes.indexOf(countryCode) !== -1;
});
}
var searchable = pool.filter(function(a) {
return a.searchable !== false && a.suggestion !== true;
});
var suggestions = this.collection.filter(function(a) {
var suggestions = pool.filter(function(a) {
return a.suggestion === true;
});
+20 -6
View File
@@ -9,6 +9,7 @@ import {
import { t, textDirection } from '../util/locale';
import { actionChangePreset } from '../actions/index';
import { operationDelete } from '../operations/index';
import { services } from '../services';
import { svgIcon } from '../svg/index';
import { tooltip } from '../util/tooltip';
import { uiPresetIcon } from './preset_icon';
@@ -21,6 +22,7 @@ export function uiPresetList(context) {
var _entityID;
var _currentPreset;
var _autofocus = false;
var geocoder = services.geocoder;
function presetList(selection) {
@@ -99,12 +101,24 @@ export function uiPresetList(context) {
var value = search.property('value');
list.classed('filtered', value.length);
if (value.length) {
var results = presets.search(value, geometry);
message.text(t('inspector.results', {
n: results.collection.length,
search: value
}));
list.call(drawList, results);
var entity = context.entity(_entityID);
if (geocoder && entity) {
var center = entity.extent(context.graph()).center();
geocoder.countryCode(center, function countryCallback(err, countryCode) {
var results;
if (!err && countryCode) {
countryCode = countryCode.toLowerCase();
results = presets.search(value, geometry, countryCode);
} else {
results = presets.search(value, geometry);
}
message.text(t('inspector.results', {
n: results.collection.length,
search: value
}));
list.call(drawList, results);
});
}
} else {
list.call(drawList, context.presets().defaults(geometry, 36));
message.text(t('inspector.choose'));