Reduce circular dependencies caused by importing from indexes, the location of the validation models, and the location of areaKeys (close #6237)

This commit is contained in:
Quincy Morgan
2019-04-24 13:45:59 -07:00
parent 862eca9ddd
commit d01bb78707
158 changed files with 503 additions and 472 deletions
+5
View File
@@ -0,0 +1,5 @@
export var areaKeys = {};
export function setAreaKeys(value) {
areaKeys = value;
}
+4 -9
View File
@@ -6,6 +6,8 @@ import { select as d3_select } from 'd3-selection';
import { t, currentLocale, addTranslation, setLocale } from '../util/locale';
import { setAreaKeys } from './area_keys';
import { coreHistory } from './history';
import { coreValidator } from './validator';
import { dataLocales, dataEn } from '../../data';
@@ -19,13 +21,6 @@ import { utilDetect } from '../util/detect';
import { utilCallWhenIdle, utilKeybinding, utilRebind, utilStringQs } from '../util';
export var areaKeys = {};
export function setAreaKeys(value) {
areaKeys = value;
}
export function coreContext() {
var dispatch = d3_dispatch('enter', 'exit', 'change');
var context = utilRebind({}, dispatch, 'on');
@@ -554,11 +549,11 @@ export function coreContext() {
var external = utilStringQs(window.location.hash).presets;
presets.fromExternal(external, function(externalPresets) {
context.presets = function() { return externalPresets; }; // default + external presets...
areaKeys = presets.areaKeys();
setAreaKeys(presets.areaKeys());
});
} else {
presets.init();
areaKeys = presets.areaKeys();
setAreaKeys(presets.areaKeys());
}
return context;
+1 -1
View File
@@ -6,7 +6,7 @@ import { coreDifference } from './difference';
import { coreGraph } from './graph';
import { coreTree } from './tree';
import { osmEntity } from '../osm/entity';
import { uiLoading } from '../ui';
import { uiLoading } from '../ui/loading';
import {
utilArrayDifference, utilArrayGroupBy, utilArrayUnion,
utilObjectOmit, utilRebind, utilSessionMutex
+1
View File
@@ -0,0 +1 @@
export { validationIssue, validationIssueFix } from './models';
+79
View File
@@ -0,0 +1,79 @@
import { geoExtent } from '../../geo';
import { osmEntity } from '../../osm/entity';
export function validationIssue(attrs) {
this.type = attrs.type; // required - name of rule that created the issue (e.g. 'missing_tag')
this.severity = attrs.severity; // required - 'warning' or 'error'
this.message = attrs.message; // required - localized string
this.reference = attrs.reference; // optional - function(selection) to render reference information
this.entities = attrs.entities; // optional - array of entities involved in the issue
this.loc = attrs.loc; // optional - [lon, lat] to zoom in on to see the issue
this.data = attrs.data; // optional - object containing extra data for the fixes
this.fixes = attrs.fixes; // optional - array of validationIssueFix objects
this.hash = attrs.hash; // optional - string to further differentiate the issue
this.id = generateID.apply(this); // generated - see below
this.autoFix = null; // generated - if autofix exists, will be set below
// A unique, deterministic string hash.
// Issues with identical id values are considered identical.
function generateID() {
var parts = [this.type];
if (this.hash) { // subclasses can pass in their own differentiator
parts.push(this.hash);
}
// include entities this issue is for
// (sort them so the id is deterministic)
if (this.entities) {
var entityKeys = this.entities.map(osmEntity.key).sort();
parts.push.apply(parts, entityKeys);
}
// include loc since two separate issues can have an
// idential type and entities, e.g. in crossing_ways
if (this.loc) {
parts.push.apply(parts, this.loc);
}
return parts.join(':');
}
var _extent;
this.extent = function(resolver) {
if (_extent) return _extent;
if (this.loc) {
return _extent = geoExtent(this.loc);
}
if (this.entities && this.entities.length) {
return _extent = this.entities.reduce(function(extent, entity) {
return extent.extend(entity.extent(resolver));
}, geoExtent());
}
return null;
};
if (this.fixes) { // add a reference in the fixes to the issue for use in fix actions
for (var i = 0; i < this.fixes.length; i++) {
var fix = this.fixes[i];
fix.issue = this;
if (fix.autoArgs) {
this.autoFix = fix;
}
}
}
}
export function validationIssueFix(attrs) {
this.title = attrs.title; // Required
this.onClick = attrs.onClick; // Required
this.icon = attrs.icon; // Optional - shows 'iD-icon-wrench' if not set
this.entityIds = attrs.entityIds || []; // Optional - Used for hover-higlighting.
this.autoArgs = attrs.autoArgs; // Optional - pass [actions, annotation] arglist if this fix can automatically run
this.issue = null; // Generated link - added by ValidationIssue constructor
}
-81
View File
@@ -1,8 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { coreDifference } from './difference';
import { geoExtent } from '../geo';
import { osmEntity } from '../osm';
import { utilArrayGroupBy, utilCallWhenIdle, utilRebind } from '../util';
import * as Validations from '../validations/index';
@@ -346,82 +344,3 @@ export function coreValidator(context) {
return validator;
}
export function validationIssue(attrs) {
this.type = attrs.type; // required - name of rule that created the issue (e.g. 'missing_tag')
this.severity = attrs.severity; // required - 'warning' or 'error'
this.message = attrs.message; // required - localized string
this.reference = attrs.reference; // optional - function(selection) to render reference information
this.entities = attrs.entities; // optional - array of entities involved in the issue
this.loc = attrs.loc; // optional - [lon, lat] to zoom in on to see the issue
this.data = attrs.data; // optional - object containing extra data for the fixes
this.fixes = attrs.fixes; // optional - array of validationIssueFix objects
this.hash = attrs.hash; // optional - string to further differentiate the issue
this.id = generateID.apply(this); // generated - see below
this.autoFix = null; // generated - if autofix exists, will be set below
// A unique, deterministic string hash.
// Issues with identical id values are considered identical.
function generateID() {
var parts = [this.type];
if (this.hash) { // subclasses can pass in their own differentiator
parts.push(this.hash);
}
// include entities this issue is for
// (sort them so the id is deterministic)
if (this.entities) {
var entityKeys = this.entities.map(osmEntity.key).sort();
parts.push.apply(parts, entityKeys);
}
// include loc since two separate issues can have an
// idential type and entities, e.g. in crossing_ways
if (this.loc) {
parts.push.apply(parts, this.loc);
}
return parts.join(':');
}
var _extent;
this.extent = function(resolver) {
if (_extent) return _extent;
if (this.loc) {
return _extent = geoExtent(this.loc);
}
if (this.entities && this.entities.length) {
return _extent = this.entities.reduce(function(extent, entity) {
return extent.extend(entity.extent(resolver));
}, geoExtent());
}
return null;
};
if (this.fixes) { // add a reference in the fixes to the issue for use in fix actions
for (var i = 0; i < this.fixes.length; i++) {
var fix = this.fixes[i];
fix.issue = this;
if (fix.autoArgs) {
this.autoFix = fix;
}
}
}
}
export function validationIssueFix(attrs) {
this.title = attrs.title; // Required
this.onClick = attrs.onClick; // Required
this.icon = attrs.icon; // Optional - shows 'iD-icon-wrench' if not set
this.entityIds = attrs.entityIds || []; // Optional - Used for hover-higlighting.
this.autoArgs = attrs.autoArgs; // Optional - pass [actions, annotation] arglist if this fix can automatically run
this.issue = null; // Generated link - added by ValidationIssue constructor
}