mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 17:52:55 +00:00
76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
import _clone from 'lodash-es/clone';
|
|
import { t } from '../util/locale';
|
|
import { utilPreset } from '../util';
|
|
import { validationIssue, validationIssueFix } from '../core/validator';
|
|
import { actionChangeTags } from '../actions';
|
|
import { discardNames } from '../../node_modules/name-suggestion-index/config/filters.json';
|
|
|
|
|
|
export function validationGenericName() {
|
|
var type = 'generic_name';
|
|
|
|
|
|
function isGenericName(entity) {
|
|
var name = entity.tags.name;
|
|
if (!name) return false;
|
|
|
|
var i, re;
|
|
|
|
// test if the name is just the tag value (e.g. "park")
|
|
var keys = ['amenity', 'leisure', 'shop', 'man_made', 'tourism'];
|
|
for (i = 0; i < keys.length; i++) {
|
|
var val = entity.tags[keys[i]];
|
|
if (val && val.replace(/\_/g, ' ').toLowerCase() === name.toLowerCase()) {
|
|
return name;
|
|
}
|
|
}
|
|
|
|
// test if the name is a generic name (e.g. "pizzaria")
|
|
for (i = 0; i < discardNames.length; i++) {
|
|
re = new RegExp(discardNames[i], 'i');
|
|
if (re.test(name)) {
|
|
return name;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
var validation = function(entity, context) {
|
|
var issues = [];
|
|
var generic = isGenericName(entity);
|
|
if (generic) {
|
|
var preset = utilPreset(entity, context);
|
|
issues.push(new validationIssue({
|
|
type: type,
|
|
severity: 'warning',
|
|
message: t('issues.generic_name.message', {feature: preset.name(), name: generic}),
|
|
tooltip: t('issues.generic_name.tip'),
|
|
entities: [entity],
|
|
fixes: [
|
|
new validationIssueFix({
|
|
icon: 'iD-operation-delete',
|
|
title: t('issues.fix.remove_generic_name.title'),
|
|
onClick: function() {
|
|
var entity = this.issue.entities[0];
|
|
var tags = _clone(entity.tags);
|
|
delete tags.name;
|
|
context.perform(
|
|
actionChangeTags(entity.id, tags),
|
|
t('issues.fix.remove_generic_name.annotation')
|
|
);
|
|
}
|
|
})
|
|
]
|
|
}));
|
|
}
|
|
|
|
return issues;
|
|
};
|
|
|
|
validation.type = type;
|
|
|
|
return validation;
|
|
}
|