mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
initial plumbing for iD validation errors
ref #remote-presets
This commit is contained in:
@@ -7,9 +7,16 @@ import _isObject from 'lodash-es/isObject';
|
||||
import _isString from 'lodash-es/isString';
|
||||
|
||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||
import { json as d3_json } from 'd3-request';
|
||||
|
||||
import {
|
||||
json as d3_json,
|
||||
text as d3_text
|
||||
} from 'd3-request';
|
||||
|
||||
import { select as d3_select } from 'd3-selection';
|
||||
|
||||
import mapcssParse from 'mapcss-parse/source/index';
|
||||
|
||||
import {
|
||||
t,
|
||||
currentLocale,
|
||||
@@ -24,6 +31,7 @@ import {
|
||||
dataEn
|
||||
} from '../../data';
|
||||
|
||||
|
||||
import { geoRawMercator } from '../geo/raw_mercator';
|
||||
import { modeSelect } from '../modes/select';
|
||||
import { presetIndex } from '../presets';
|
||||
@@ -40,13 +48,13 @@ import { utilDetect } from '../util/detect';
|
||||
|
||||
import {
|
||||
utilCallWhenIdle,
|
||||
utilRebind,
|
||||
utilExternalPresets,
|
||||
utilExternalValidationRules
|
||||
utilExternalValidationRules,
|
||||
utilMapCSSRule,
|
||||
utilRebind,
|
||||
utilStringQs
|
||||
} from '../util';
|
||||
|
||||
import { validationCollection } from '../validations';
|
||||
|
||||
export var areaKeys = {};
|
||||
|
||||
export function setAreaKeys(value) {
|
||||
@@ -448,6 +456,15 @@ export function coreContext() {
|
||||
locale = locale.split('-')[0];
|
||||
}
|
||||
|
||||
if (utilExternalValidationRules()) {
|
||||
var validationsUrl = utilStringQs(window.location.hash)['validations'];
|
||||
d3_text(validationsUrl, function (err, mapcss) {
|
||||
if (err) return;
|
||||
var validations = _map(mapcssParse(mapcss), function(mapcssConfig) { return utilMapCSSRule(mapcsS) });
|
||||
context.validationRules = function() { return validations; };
|
||||
});
|
||||
}
|
||||
|
||||
history = coreHistory(context);
|
||||
context.graph = history.graph;
|
||||
context.changes = history.changes;
|
||||
@@ -497,20 +514,12 @@ export function coreContext() {
|
||||
background.init();
|
||||
features.init();
|
||||
|
||||
// get external data if directed by query parameters
|
||||
if (utilExternalPresets()) {
|
||||
presets.fromExternal();
|
||||
} else {
|
||||
presets.init();
|
||||
}
|
||||
|
||||
if (utilExternalValidationRules()) {
|
||||
var validations = validationCollection();
|
||||
validations.init(function(rules) {
|
||||
context.validationRules = function() { return rules; };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
areaKeys = presets.areaKeys();
|
||||
|
||||
|
||||
|
||||
@@ -282,7 +282,15 @@ export function coreHistory(context) {
|
||||
|
||||
validate: function(changes) {
|
||||
return _flatten(
|
||||
_map(Validations, function(fn) { return fn()(changes, _stack[_index].graph); })
|
||||
_map(Validations, function(fn) {
|
||||
var warnings;
|
||||
if (fn === Validations.validationMapCSSChecks) {
|
||||
warnings = fn()(changes, _stack[_index].graph, context.validationRules());
|
||||
} else {
|
||||
warnings = fn()(changes, _stack[_index].graph);
|
||||
}
|
||||
return warnings;
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ export function uiEntityEditor(context) {
|
||||
var entity = context.entity(_entityID);
|
||||
var tags = _clone(entity.tags);
|
||||
|
||||
console.log(context.validationRules());
|
||||
// Header
|
||||
var header = selection.selectAll('.header')
|
||||
.data([0]);
|
||||
|
||||
@@ -15,6 +15,7 @@ export { utilGetAllNodes } from './util';
|
||||
export { utilGetPrototypeOf } from './util';
|
||||
export { utilGetSetValue } from './get_set_value';
|
||||
export { utilIdleWorker} from './idle_worker';
|
||||
export { utilMapCSSRule } from './mapcss_rule';
|
||||
export { utilNoAuto } from './util';
|
||||
export { utilPrefixCSSProperty } from './util';
|
||||
export { utilPrefixDOMProperty } from './util';
|
||||
|
||||
1
modules/util/mapcss_rule.js
Normal file
1
modules/util/mapcss_rule.js
Normal file
@@ -0,0 +1 @@
|
||||
export function mapcssRule() {}
|
||||
@@ -1,7 +1,7 @@
|
||||
export { validationCollection } from './validation_collection';
|
||||
export { validationDeprecatedTag } from './deprecated_tag';
|
||||
export { validationDisconnectedHighway } from './disconnected_highway';
|
||||
export { validationManyDeletions } from './many_deletions';
|
||||
export { validationMapCSSChecks } from './mapcss_checks';
|
||||
export { validationMissingTag } from './missing_tag';
|
||||
export { validationOldMultipolygon } from './old_multipolygon';
|
||||
export { validationTagSuggestsArea } from './tag_suggests_area';
|
||||
|
||||
20
modules/validations/mapcss_checks.js
Normal file
20
modules/validations/mapcss_checks.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// import { t } from '../util/locale';
|
||||
|
||||
export function validationMapCSSChecks() {
|
||||
var validation = function(changes, graph, rules) {
|
||||
var warnings = [];
|
||||
var createdModified = ['created', 'modified'];
|
||||
for (var i = 0; i < createdModified.length; i++) {
|
||||
var entities = changes[createdModified[i]];
|
||||
for (var j = 0; j < entities.length; j++) {
|
||||
var entity = entities[i];
|
||||
for (var k = 0; k < rules.length; k++) {
|
||||
var rule = rules[k];
|
||||
rules.findWarnings(entity, rules);
|
||||
}
|
||||
}
|
||||
}
|
||||
return warnings;
|
||||
};
|
||||
return validation;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { utilStringQs } from '../util';
|
||||
import { text as d3_text } from 'd3-request';
|
||||
import mapcssParse from 'mapcss-parse/source/index';
|
||||
|
||||
export function validationCollection() {
|
||||
var validations = {};
|
||||
validations.init = function (callback) {
|
||||
var validationsUrl = utilStringQs(window.location.hash)['validations'];
|
||||
d3_text(validationsUrl, function(err, mapcss) {
|
||||
if (err) return;
|
||||
callback(mapcssParse(mapcss));
|
||||
});
|
||||
};
|
||||
|
||||
return validations;
|
||||
}
|
||||
Reference in New Issue
Block a user