Add external modules to validations

This commit is contained in:
Kushan Joshi
2016-06-18 16:59:05 +05:30
parent 25485c40fb
commit 68e0400332
6 changed files with 126 additions and 11 deletions
+1 -6
View File
@@ -49,8 +49,7 @@ MODULE_TARGETS = \
js/lib/id/ui/index.js \
js/lib/id/ui/core.js \
js/lib/id/ui/intro.js \
js/lib/id/ui/preset.js \
js/lib/id/validations.js
js/lib/id/ui/preset.js
js/lib/id/index.js: $(shell find modules/index.js -type f)
@rm -f $@
@@ -84,10 +83,6 @@ js/lib/id/ui/preset.js: $(shell find modules/ui/preset -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD.ui.preset modules/ui/preset/index.js --no-strict -o $@
js/lib/id/validations.js: $(shell find modules/validations -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD.validations modules/validations/index.js --no-strict -o $@
dist/iD.js: \
js/lib/bootstrap-tooltip.js \
js/lib/d3.v3.js \
-2
View File
@@ -45,8 +45,6 @@
<script src='js/lib/id/ui/intro.js'></script>
<script src='js/lib/id/ui/preset.js'></script>
<script src='js/lib/id/validations.js'></script>
<script src='data/data_dev.js'></script>
<script src='js/lib/locale.js'></script>
+120
View File
@@ -12840,6 +12840,122 @@
presets: presets$1
});
function DeprecatedTag() {
var validation = function(changes) {
var warnings = [];
for (var i = 0; i < changes.created.length; i++) {
var change = changes.created[i],
deprecatedTags = change.deprecatedTags();
if (!_.isEmpty(deprecatedTags)) {
var tags = tagText({ tags: deprecatedTags });
warnings.push({
id: 'deprecated_tags',
message: t('validations.deprecated_tags', { tags: tags }),
entity: change
});
}
}
return warnings;
};
return validation;
}
function ManyDeletions() {
var threshold = 100;
var validation = function(changes) {
var warnings = [];
if (changes.deleted.length > threshold) {
warnings.push({
id: 'many_deletions',
message: t('validations.many_deletions', { n: changes.deleted.length })
});
}
return warnings;
};
return validation;
}
function MissingTag() {
// Slightly stricter check than Entity#isUsed (#3091)
function hasTags(entity, graph) {
return _.without(Object.keys(entity.tags), 'area', 'name').length > 0 ||
graph.parentRelations(entity).length > 0;
}
var validation = function(changes, graph) {
var warnings = [];
for (var i = 0; i < changes.created.length; i++) {
var change = changes.created[i],
geometry = change.geometry(graph);
if ((geometry === 'point' || geometry === 'line' || geometry === 'area') && !hasTags(change, graph)) {
warnings.push({
id: 'missing_tag',
message: t('validations.untagged_' + geometry),
tooltip: t('validations.untagged_' + geometry + '_tooltip'),
entity: change
});
}
}
return warnings;
};
return validation;
}
function TagSuggestsArea() {
// https://github.com/openstreetmap/josm/blob/mirror/src/org/
// openstreetmap/josm/data/validation/tests/UnclosedWays.java#L80
function tagSuggestsArea(tags) {
if (_.isEmpty(tags)) return false;
var presence = ['landuse', 'amenities', 'tourism', 'shop'];
for (var i = 0; i < presence.length; i++) {
if (tags[presence[i]] !== undefined) {
return presence[i] + '=' + tags[presence[i]];
}
}
if (tags.building && tags.building === 'yes') return 'building=yes';
}
var validation = function(changes, graph) {
var warnings = [];
for (var i = 0; i < changes.created.length; i++) {
var change = changes.created[i],
geometry = change.geometry(graph),
suggestion = (geometry === 'line' ? tagSuggestsArea(change.tags) : undefined);
if (suggestion) {
warnings.push({
id: 'tag_suggests_area',
message: t('validations.tag_suggests_area', { tag: suggestion }),
entity: change
});
}
}
return warnings;
};
return validation;
}
var validations = Object.freeze({
DeprecatedTag: DeprecatedTag,
ManyDeletions: ManyDeletions,
MissingTag: MissingTag,
TagSuggestsArea: TagSuggestsArea
});
exports.actions = actions;
exports.geo = geo;
exports.svg = svg;
@@ -12860,7 +12976,11 @@
exports.presets = presets;
>>>>>>> ed34eb3... external modules for presets
exports.util = util;
<<<<<<< HEAD
>>>>>>> 42ce4cf... external modules for util
=======
exports.validations = validations;
>>>>>>> 44cf7f1... Add external modules to validations
exports.Connection = Connection;
exports.Difference = Difference;
exports.Entity = Entity;
+3 -1
View File
@@ -5,6 +5,7 @@ import * as modes from './modes/index';
import * as util from './util/index';
import * as operations from './operations/index';
import * as presets from './presets/index';
import * as validations from './validations/index';
export { Connection } from './core/connection';
export { Difference } from './core/difference';
@@ -24,5 +25,6 @@ export {
modes,
operations,
presets,
util
util,
validations
};
+2 -1
View File
@@ -1,3 +1,4 @@
import { tagText } from '../util/index';
export function DeprecatedTag() {
var validation = function(changes) {
@@ -7,7 +8,7 @@ export function DeprecatedTag() {
deprecatedTags = change.deprecatedTags();
if (!_.isEmpty(deprecatedTags)) {
var tags = iD.util.tagText({ tags: deprecatedTags });
var tags = tagText({ tags: deprecatedTags });
warnings.push({
id: 'deprecated_tags',
message: t('validations.deprecated_tags', { tags: tags }),
-1
View File
@@ -49,7 +49,6 @@
<script src='../js/lib/id/ui/core.js'></script>
<script src='../js/lib/id/ui/preset.js'></script>
<script src='../js/lib/id/validations.js'></script>
<script src='../js/lib/locale.js'></script>