mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
presets test w/build
This commit is contained in:
@@ -21,7 +21,8 @@ import { rendererBackground, rendererFeatures, rendererMap } from '../renderer';
|
||||
import { services } from '../services';
|
||||
import { uiInit } from '../ui/init';
|
||||
import { utilDetect } from '../util/detect';
|
||||
import { utilCallWhenIdle, utilKeybinding, utilRebind } from '../util';
|
||||
import { utilCallWhenIdle, utilKeybinding, utilRebind, utilStringQs } from '../util';
|
||||
|
||||
|
||||
|
||||
export var areaKeys = {};
|
||||
@@ -441,16 +442,16 @@ export function coreContext() {
|
||||
}
|
||||
|
||||
/* Presets */
|
||||
var presets;
|
||||
presets = presetIndex();
|
||||
if (utilExternalPresets()) {
|
||||
if (utilStringQs(window.location.hash).presets) {
|
||||
presets.fromExternal();
|
||||
} else {
|
||||
presets.init();
|
||||
}
|
||||
|
||||
context.presets = function() { return presets; };
|
||||
|
||||
if (utilExternalValidationRules()) {
|
||||
if (utilStringQs(window.location.hash).validations) {
|
||||
var validationsUrl = utilStringQs(window.location.hash).validations;
|
||||
d3_json(validationsUrl, function (err, mapcss) {
|
||||
if (err) return;
|
||||
|
||||
+36
-39
@@ -3,18 +3,14 @@ import _forEach from 'lodash-es/forEach';
|
||||
import _reject from 'lodash-es/reject';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
|
||||
import { json as d3_json } from 'd3-request';
|
||||
|
||||
import { data } from '../../data/index';
|
||||
import { presetCategory } from './category';
|
||||
import { presetCollection } from './collection';
|
||||
import { presetField } from './field';
|
||||
import { presetPreset } from './preset';
|
||||
import { utilStringQs } from '../util';
|
||||
|
||||
import { json as d3_json } from 'd3-request';
|
||||
import {
|
||||
select as d3_select,
|
||||
selectAll as d3_selectAll
|
||||
} from 'd3-selection';
|
||||
import { utilQsString } from '../util';
|
||||
|
||||
export { presetCategory };
|
||||
export { presetCollection };
|
||||
@@ -27,7 +23,7 @@ export function presetIndex() {
|
||||
// loading new data and returning defaults
|
||||
|
||||
var all = presetCollection([]);
|
||||
var _defaults = {};
|
||||
var _defaults = { area: all, line: all, point: all, vertex: all, relation: all };
|
||||
var _fields = {};
|
||||
var _universal = [];
|
||||
var _recent = presetCollection([]);
|
||||
@@ -123,10 +119,11 @@ export function presetIndex() {
|
||||
areaKeys[key][value] = true;
|
||||
}
|
||||
});
|
||||
|
||||
return areaKeys;
|
||||
};
|
||||
|
||||
all.build = function (d, visible) {
|
||||
all.build = function(d, visibility) {
|
||||
if (d.fields) {
|
||||
_forEach(d.fields, function(d, id) {
|
||||
_fields[id] = presetField(id, d);
|
||||
@@ -142,7 +139,7 @@ export function presetIndex() {
|
||||
|
||||
if (d.presets) {
|
||||
_forEach(d.presets, function(d, id) {
|
||||
all.collection.push(presetPreset(id, d, _fields, visible));
|
||||
all.collection.push(presetPreset(id, d, _fields, visibility));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -154,16 +151,13 @@ export function presetIndex() {
|
||||
|
||||
if (d.defaults) {
|
||||
var getItem = _bind(all.item, all);
|
||||
_forEach(Object.keys(d.defaults), function (k) {
|
||||
_defaults[k] = presetCollection(d.defaults[k].map(getItem));
|
||||
});
|
||||
// _defaults = {
|
||||
// area: presetCollection(d.defaults.area.map(getItem)),
|
||||
// line: presetCollection(d.defaults.line.map(getItem)),
|
||||
// point: presetCollection(d.defaults.point.map(getItem)),
|
||||
// vertex: presetCollection(d.defaults.vertex.map(getItem)),
|
||||
// relation: presetCollection(d.defaults.relation.map(getItem))
|
||||
// };
|
||||
_defaults = {
|
||||
area: presetCollection(d.defaults.area.map(getItem)),
|
||||
line: presetCollection(d.defaults.line.map(getItem)),
|
||||
point: presetCollection(d.defaults.point.map(getItem)),
|
||||
vertex: presetCollection(d.defaults.vertex.map(getItem)),
|
||||
relation: presetCollection(d.defaults.relation.map(getItem))
|
||||
};
|
||||
}
|
||||
|
||||
for (var i = 0; i < all.collection.length; i++) {
|
||||
@@ -177,22 +171,30 @@ export function presetIndex() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
all.fromExternal = function() {
|
||||
var presetsUrl = utilStringQs(window.location.hash).presets;
|
||||
d3_json(presetsUrl, function(err, presets) {
|
||||
if (err) all.init();
|
||||
all.build(presets, true);
|
||||
all.build(data.presets, false);
|
||||
all.areaKeys();
|
||||
});
|
||||
return all;
|
||||
};
|
||||
|
||||
all.init = function() {
|
||||
all.build(data.presets, true);
|
||||
all.collection = [];
|
||||
_recent.collection = [];
|
||||
_fields = {};
|
||||
_universal = [];
|
||||
_index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} };
|
||||
|
||||
all.build(data.presets);
|
||||
|
||||
return all;
|
||||
};
|
||||
|
||||
all.fromExternal = function() {
|
||||
var external = utilQsString(window.location.hash).presets;
|
||||
d3_json(external, function(err, presets) {
|
||||
if (err) {
|
||||
all.init();
|
||||
} else {
|
||||
all.build(data.presets, false); // make default presets hidden to begin
|
||||
all.build(presets, true); // make the external visible
|
||||
}
|
||||
});
|
||||
return all;
|
||||
};
|
||||
|
||||
@@ -207,12 +209,7 @@ export function presetIndex() {
|
||||
all.defaults = function(geometry, n) {
|
||||
var rec = _recent.matchGeometry(geometry).collection.slice(0, 4);
|
||||
var def = _uniq(rec.concat(_defaults[geometry].collection)).slice(0, n - 1);
|
||||
var fin = _uniq(rec.concat(def).concat(all.item(geometry))).filter(function(d) { return d.visible(); });
|
||||
return presetCollection(fin);
|
||||
};
|
||||
|
||||
all.defaultTypes = function() {
|
||||
return Object.keys(_defaults);
|
||||
return presetCollection(_uniq(rec.concat(def).concat(all.item(geometry))));
|
||||
};
|
||||
|
||||
all.choose = function(preset) {
|
||||
|
||||
@@ -27,7 +27,7 @@ export { utilRebind } from './rebind';
|
||||
export { utilSetTransform } from './util';
|
||||
export { utilSessionMutex } from './session_mutex';
|
||||
export { utilStringQs } from './util';
|
||||
export { utilSuggestNames } from './suggest_names';
|
||||
// export { utilSuggestNames } from './suggest_names';
|
||||
export { utilTagText } from './util';
|
||||
export { utilTiler } from './tiler';
|
||||
export { utilTriggerEvent } from './trigger_event';
|
||||
|
||||
+16
-16
@@ -62,29 +62,29 @@
|
||||
<script src='spec/actions/straighten.js'></script>
|
||||
<script src='spec/actions/unrestrict_turn.js'></script>
|
||||
<script src='spec/actions/reflect.js'></script>
|
||||
<script src='spec/actions/detach_node.js'></script>
|
||||
<script src='spec/actions/detach_node.js'></script> -->
|
||||
|
||||
<script src='spec/behavior/hash.js'></script>
|
||||
<!-- <script src='spec/behavior/hash.js'></script>
|
||||
<script src='spec/behavior/hover.js'></script>
|
||||
<script src='spec/behavior/select.js'></script>
|
||||
<script src='spec/behavior/lasso.js'></script>
|
||||
<script src='spec/behavior/lasso.js'></script> -->
|
||||
|
||||
<script src='spec/core/context.js'></script>
|
||||
<!-- <script src='spec/core/context.js'></script>
|
||||
<script src='spec/core/difference.js'></script>
|
||||
<script src='spec/core/graph.js'></script>
|
||||
<script src='spec/core/history.js'></script>
|
||||
<script src='spec/core/tree.js'></script>
|
||||
<script src='spec/core/tree.js'></script> -->
|
||||
|
||||
<script src='spec/geo/extent.js'></script>
|
||||
<!-- <script src='spec/geo/extent.js'></script>
|
||||
<script src='spec/geo/geo.js'></script>
|
||||
<script src='spec/geo/geom.js'></script>
|
||||
<script src='spec/geo/vector.js'></script>
|
||||
<script src='spec/geo/vector.js'></script> -->
|
||||
|
||||
<script src='spec/lib/locale.js'></script>
|
||||
|
||||
<script src='spec/modes/add_point.js'></script>
|
||||
<script src='spec/modes/add_note.js'></script>
|
||||
<!-- <script src='spec/lib/locale.js'></script> -->
|
||||
|
||||
<!-- <script src='spec/modes/add_point.js'></script>
|
||||
<script src='spec/modes/add_note.js'></script> -->
|
||||
<!--
|
||||
<script src='spec/osm/changeset.js'></script>
|
||||
<script src='spec/osm/entity.js'></script>
|
||||
<script src='spec/osm/intersection.js'></script>
|
||||
@@ -93,12 +93,12 @@
|
||||
<script src='spec/osm/node.js'></script>
|
||||
<script src='spec/osm/note.js'></script>
|
||||
<script src='spec/osm/relation.js'></script>
|
||||
<script src='spec/osm/way.js'></script>
|
||||
<script src='spec/osm/way.js'></script> -->
|
||||
|
||||
<script src='spec/presets/category.js'></script>
|
||||
<script src='spec/presets/collection.js'></script>
|
||||
<script src='spec/presets/index.js'></script> -->
|
||||
<script src='spec/presets/preset.js'></script>
|
||||
<!-- <script src='spec/presets/category.js'></script>
|
||||
<script src='spec/presets/collection.js'></script> -->
|
||||
<script src='spec/presets/index.js'></script>
|
||||
<!-- <script src='spec/presets/preset.js'></script> -->
|
||||
|
||||
<!-- <script src='spec/renderer/background_source.js'></script>
|
||||
<script src='spec/renderer/features.js'></script>
|
||||
|
||||
+40
-41
@@ -110,6 +110,7 @@ describe('iD.presetIndex', function() {
|
||||
geometry: ['point', 'area']
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
it('whitelists keys for presets with area geometry', function() {
|
||||
@@ -156,50 +157,48 @@ describe('iD.presetIndex', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#overwrite', function() {
|
||||
it('overwrites iD presets with provided list of presets', function() {
|
||||
var testPresets = {
|
||||
presets: {
|
||||
'amenity/fuel/shell': {
|
||||
tags: { 'amenity': 'fuel' },
|
||||
geometry: ['point','area'],
|
||||
suggestion: true
|
||||
},
|
||||
'highway/foo': {
|
||||
tags: { 'highway': 'foo' },
|
||||
geometry: ['area']
|
||||
},
|
||||
'leisure/track': {
|
||||
tags: { 'leisure': 'track' },
|
||||
geometry: ['line', 'area']
|
||||
},
|
||||
'natural': {
|
||||
tags: { 'natural': '*' },
|
||||
geometry: ['point', 'vertex', 'area']
|
||||
},
|
||||
'natural/peak': {
|
||||
tags: { 'natural': 'peak' },
|
||||
geometry: ['point', 'vertex']
|
||||
},
|
||||
'natural/tree_row': {
|
||||
tags: { 'natural': 'tree_row' },
|
||||
geometry: ['line']
|
||||
},
|
||||
'natural/wood': {
|
||||
tags: { 'natural': 'wood' },
|
||||
geometry: ['point', 'area']
|
||||
}
|
||||
}
|
||||
};
|
||||
var currentPresets = iD.Context().presets();
|
||||
var overwrittenPresets = iD.Context().presets().overwrite(testPresets);
|
||||
expect(currentPresets).to.not.eql(overwrittenPresets);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#build', function () {
|
||||
it('builds presets from provided', function() {
|
||||
var surfShop = iD.Node({ tags: { amenity: 'shop', 'shop:type': 'surf' }}),
|
||||
graph = iD.Graph([surfShop]),
|
||||
presets = iD.Context().presets(),
|
||||
morePresets = {
|
||||
presets: {
|
||||
'amenity/shop/surf': {
|
||||
tags: { amenity: 'shop', 'shop:type': 'surf' },
|
||||
geometry: ['point', 'area']
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
expect(presets.match(surfShop, graph)).to.eql(undefined); // no surfshop preset yet...
|
||||
presets.build(morePresets, true);
|
||||
expect(presets.match(surfShop, graph).addTags).to.eql({amenity: 'shop', 'shop:type': 'surf' });
|
||||
});
|
||||
it('configures presets\' initial visibility', function() {
|
||||
var surfShop = iD.Node({ tags: { amenity: 'shop', 'shop:type': 'surf' }}),
|
||||
firstStreetJetty = iD.Node({ tags: { man_made: 'jetty' }}),
|
||||
entities = [surfShop, firstStreetJetty],
|
||||
graph = iD.Graph(entities),
|
||||
presets = iD.Context().presets(),
|
||||
morePresets = {
|
||||
presets: {
|
||||
'amenity/shop/surf': {
|
||||
tags: { amenity: 'shop', 'shop:type': 'surf' },
|
||||
geometry: ['point', 'area']
|
||||
},
|
||||
'man_made/jetty': {
|
||||
tags: { man_made: 'jetty' },
|
||||
geometry: [ 'point' ]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
presets.build(morePresets, false);
|
||||
entities.forEach(function(entity) {
|
||||
var preset = presets.match(entity, graph);
|
||||
expect(preset.visible()).to.be.false;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user