Skip to content

Commit

Permalink
Reduce circular dependencies caused by importing from indexes, the lo…
Browse files Browse the repository at this point in the history
…cation of the validation models, and the location of areaKeys (close #6237)
  • Loading branch information
quincylvania committed Apr 24, 2019
1 parent 862eca9 commit d01bb78
Show file tree
Hide file tree
Showing 158 changed files with 509 additions and 478 deletions.
3 changes: 2 additions & 1 deletion modules/actions/add_member.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { osmJoinWays, osmWay } from '../osm';
import { osmJoinWays } from '../osm/multipolygon';
import { osmWay } from '../osm/way';
import { utilArrayGroupBy, utilObjectOmit } from '../util';


Expand Down
2 changes: 1 addition & 1 deletion modules/actions/circularize.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'd3-polygon';

import { geoVecInterp, geoVecLength } from '../geo';
import { osmNode } from '../osm';
import { osmNode } from '../osm/node';
import { utilArrayUniq } from '../util';


Expand Down
4 changes: 2 additions & 2 deletions modules/actions/extract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { geoPath as d3_geoPath } from 'd3-geo';
import { osmNode } from '../osm';
import { osmNode } from '../osm/node';

export function actionExtract(entityID, projection) {

Expand Down Expand Up @@ -73,7 +73,7 @@ export function actionExtract(entityID, projection) {
// remove the tag from the area
delete areaTags[key];
}

if (!isBuilding) {
// ensure that the area keeps the area geometry
areaTags.area = 'yes';
Expand Down
3 changes: 2 additions & 1 deletion modules/actions/join.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { actionDeleteWay } from './delete_way';
import { osmIsInterestingTag, osmJoinWays } from '../osm';
import { osmIsInterestingTag } from '../osm/tags';
import { osmJoinWays } from '../osm/multipolygon';
import { geoPathIntersections } from '../geo';
import { utilArrayGroupBy, utilArrayIntersection } from '../util';

Expand Down
2 changes: 1 addition & 1 deletion modules/actions/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
geoVecAdd, geoVecEqual, geoVecInterp, geoVecSubtract
} from '../geo';

import { osmNode } from '../osm';
import { osmNode } from '../osm/node';
import { utilArrayIntersection } from '../util';


Expand Down
2 changes: 1 addition & 1 deletion modules/actions/restrict_turn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { osmRelation } from '../osm';
import { osmRelation } from '../osm/relation';


// `actionRestrictTurn` creates a turn restriction relation.
Expand Down
4 changes: 3 additions & 1 deletion modules/actions/split.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { actionAddMember } from './add_member';
import { geoSphericalDistance } from '../geo';
import { osmIsOldMultipolygonOuterMember, osmRelation, osmWay } from '../osm';
import { osmIsOldMultipolygonOuterMember } from '../osm/multipolygon';
import { osmRelation } from '../osm/relation';
import { osmWay } from '../osm/way';
import { utilArrayIntersection, utilWrap } from '../util';


Expand Down
2 changes: 1 addition & 1 deletion modules/behavior/add_way.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';

import { behaviorDraw } from './draw';
import { modeBrowse } from '../modes';
import { modeBrowse } from '../modes/browse';
import { utilRebind } from '../util/rebind';


Expand Down
2 changes: 1 addition & 1 deletion modules/behavior/copy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { event as d3_event } from 'd3-selection';

import { uiCmd } from '../ui';
import { uiCmd } from '../ui/cmd';
import { utilArrayGroupBy } from '../util';


Expand Down
9 changes: 6 additions & 3 deletions modules/behavior/draw_way.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import {
} from 'd3-selection';

import { t } from '../util/locale';
import { actionAddMidpoint, actionMoveNode, actionNoop } from '../actions';
import { actionAddMidpoint } from '../actions/add_midpoint';
import { actionMoveNode } from '../actions/move_node';
import { actionNoop } from '../actions/noop';
import { behaviorDraw } from './draw';
import { geoChooseEdge, geoHasSelfIntersections } from '../geo';
import { modeBrowse, modeSelect } from '../modes';
import { osmNode } from '../osm';
import { modeBrowse } from '../modes/browse';
import { modeSelect } from '../modes/select';
import { osmNode } from '../osm/node';
import { utilKeybinding } from '../util';

export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselineGraph) {
Expand Down
2 changes: 1 addition & 1 deletion modules/behavior/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _throttle from 'lodash-es/throttle';
import { select as d3_select } from 'd3-selection';

import { geoSphericalDistance } from '../geo';
import { modeBrowse } from '../modes';
import { modeBrowse } from '../modes/browse';
import { utilObjectOmit, utilQsString, utilStringQs } from '../util';


Expand Down
4 changes: 2 additions & 2 deletions modules/behavior/lasso.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { event as d3_event, select as d3_select } from 'd3-selection';

import { geoExtent, geoPointInPolygon } from '../geo';
import { modeSelect } from '../modes';
import { uiLasso } from '../ui';
import { modeSelect } from '../modes/select';
import { uiLasso } from '../ui/lasso';


export function behaviorLasso(context) {
Expand Down
2 changes: 1 addition & 1 deletion modules/behavior/operation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { event as d3_event } from 'd3-selection';
import { uiFlash } from '../ui';
import { uiFlash } from '../ui/flash';


/* Creates a keybinding behavior for an operation */
Expand Down
7 changes: 4 additions & 3 deletions modules/behavior/paste.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { event as d3_event } from 'd3-selection';

import { actionCopyEntities, actionMove } from '../actions';
import { actionCopyEntities } from '../actions/copy_entities';
import { actionMove } from '../actions/move';
import { geoExtent, geoPointInPolygon, geoVecSubtract } from '../geo';
import { modeMove } from '../modes';
import { uiCmd } from '../ui';
import { modeMove } from '../modes/move';
import { uiCmd } from '../ui/cmd';


export function behaviorPaste(context) {
Expand Down
12 changes: 5 additions & 7 deletions modules/behavior/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import {

import { geoVecLength } from '../geo';

import {
modeBrowse,
modeSelect,
modeSelectData,
modeSelectNote,
modeSelectError
} from '../modes';
import { modeBrowse } from '../modes/browse';
import { modeSelect } from '../modes/select';
import { modeSelectData } from '../modes/select_data';
import { modeSelectNote } from '../modes/select_note';
import { modeSelectError } from '../modes/select_error';

import { osmEntity, osmNote, qaError } from '../osm';

Expand Down
5 changes: 5 additions & 0 deletions modules/core/area_keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export var areaKeys = {};

export function setAreaKeys(value) {
areaKeys = value;
}
13 changes: 4 additions & 9 deletions modules/core/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion modules/core/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/core/validation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { validationIssue, validationIssueFix } from './models';
79 changes: 79 additions & 0 deletions modules/core/validation/models.js
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 81 deletions modules/core/validator.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion modules/geo/extent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { geoMetersToLat, geoMetersToLon } from './index';
import { geoMetersToLat, geoMetersToLon } from './geo';


export function geoExtent(min, max) {
Expand Down
Loading

0 comments on commit d01bb78

Please sign in to comment.