get validaiton objects on context

ref #remote-presets
This commit is contained in:
Max Grossman
2018-07-31 13:41:24 -04:00
parent 873b451bef
commit db78df55c8
7 changed files with 38 additions and 4 deletions

View File

@@ -41,9 +41,11 @@ import { utilDetect } from '../util/detect';
import {
utilCallWhenIdle,
utilRebind,
utilExternalPresets
utilExternalPresets,
utilExternalValidationRules
} from '../util';
import { validationCollection } from '../validations';
export var areaKeys = {};
@@ -494,11 +496,21 @@ 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();

View File

@@ -182,7 +182,7 @@ export function presetIndex() {
};
all.fromExternal = function(callback) {
all.fromExternal = function() {
var presetsUrl = utilStringQs(window.location.hash)['presets'];
d3_json(presetsUrl, function(err, presets) {
if (err) all.init();

View File

@@ -38,11 +38,11 @@ export function uiEntityEditor(context) {
var rawTagEditor = uiRawTagEditor(context)
.on('change', changeTags);
function entityEditor(selection) {
var entity = context.entity(_entityID);
var tags = _clone(entity.tags);
console.log(context.validationRules());
// Header
var header = selection.selectAll('.header')
.data([0]);

View File

@@ -8,6 +8,7 @@ export { utilEditDistance } from './util';
export { utilEntitySelector } from './util';
export { utilEntityOrMemberSelector } from './util';
export { utilExternalPresets } from './util';
export { utilExternalValidationRules } from './util';
export { utilFastMouse } from './util';
export { utilFunctor } from './util';
export { utilGetAllNodes } from './util';

View File

@@ -270,3 +270,7 @@ export function utilNoAuto(selection) {
export function utilExternalPresets() {
return utilStringQs(window.location.hash).hasOwnProperty('presets');
}
export function utilExternalValidationRules() {
return utilStringQs(window.location.hash).hasOwnProperty('validations');
}

View File

@@ -1,3 +1,4 @@
export { validationCollection } from './validation_collection';
export { validationDeprecatedTag } from './deprecated_tag';
export { validationDisconnectedHighway } from './disconnected_highway';
export { validationManyDeletions } from './many_deletions';

View File

@@ -0,0 +1,16 @@
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;
}