mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-20 23:44:47 +02:00
Rename "visible" property of presets to "addable" (re: a06ec59514b30a52601e3614ef69006d2dc1bc91)
This commit is contained in:
+13
-10
@@ -184,7 +184,7 @@ export function presetIndex(context) {
|
||||
}, {});
|
||||
};
|
||||
|
||||
all.build = function(d, visible) {
|
||||
all.build = function(d, addable) {
|
||||
if (d.fields) {
|
||||
Object.keys(d.fields).forEach(function(id) {
|
||||
var f = d.fields[id];
|
||||
@@ -200,11 +200,11 @@ export function presetIndex(context) {
|
||||
Object.keys(d.presets).forEach(function(id) {
|
||||
var p = d.presets[id];
|
||||
var existing = all.index(id);
|
||||
var isVisible = typeof visible === 'function' ? visible(id, p) : visible;
|
||||
var isAddable = typeof addable === 'function' ? addable(id, p) : addable;
|
||||
if (existing !== -1) {
|
||||
all.collection[existing] = presetPreset(id, p, _fields, isVisible, rawPresets);
|
||||
all.collection[existing] = presetPreset(id, p, _fields, isAddable, rawPresets);
|
||||
} else {
|
||||
all.collection.push(presetPreset(id, p, _fields, isVisible, rawPresets));
|
||||
all.collection.push(presetPreset(id, p, _fields, isAddable, rawPresets));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -260,14 +260,14 @@ export function presetIndex(context) {
|
||||
_universal = [];
|
||||
_index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} };
|
||||
|
||||
var show = true;
|
||||
var addable = true;
|
||||
if (addablePresetIDs) {
|
||||
show = function(presetID) {
|
||||
addable = function(presetID) {
|
||||
return addablePresetIDs.indexOf(presetID) !== -1;
|
||||
};
|
||||
}
|
||||
|
||||
return all.build(data.presets, show);
|
||||
return all.build(data.presets, addable);
|
||||
};
|
||||
|
||||
|
||||
@@ -294,8 +294,11 @@ export function presetIndex(context) {
|
||||
all.reset();
|
||||
d3_json(external)
|
||||
.then(function(externalPresets) {
|
||||
all.build(data.presets, false); // make default presets hidden to begin
|
||||
all.build(externalPresets, true); // make the external visible
|
||||
all.build(data.presets, false); // load the default presets as non-addable to start
|
||||
|
||||
_addablePresetIDs = externalPresets.presets && Object.keys(externalPresets.presets);
|
||||
|
||||
all.build(externalPresets, true); // then load the external presets as addable
|
||||
})
|
||||
.catch(function() {
|
||||
all.init();
|
||||
@@ -381,7 +384,7 @@ export function presetIndex(context) {
|
||||
_recents = (JSON.parse(context.storage('preset_recents')) || [])
|
||||
.reduce(function(output, d) {
|
||||
var item = ribbonItemForMinified(d, 'recent');
|
||||
if (item) output.push(item);
|
||||
if (item && item.preset.addable()) output.push(item);
|
||||
return output;
|
||||
}, []);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { utilArrayUniq, utilObjectOmit } from '../util';
|
||||
import { utilSafeClassName } from '../util/util';
|
||||
|
||||
|
||||
export function presetPreset(id, preset, fields, visible, rawPresets) {
|
||||
export function presetPreset(id, preset, fields, addable, rawPresets) {
|
||||
preset = Object.assign({}, preset); // shallow copy
|
||||
|
||||
preset.id = id;
|
||||
@@ -97,7 +97,7 @@ export function presetPreset(id, preset, fields, visible, rawPresets) {
|
||||
preset.moreFields = (preset.moreFields || []).map(getFields);
|
||||
preset.geometry = (preset.geometry || []);
|
||||
|
||||
visible = visible || false;
|
||||
addable = addable || false;
|
||||
|
||||
function getFields(f) {
|
||||
return fields[f];
|
||||
@@ -182,10 +182,10 @@ export function presetPreset(id, preset, fields, visible, rawPresets) {
|
||||
return tagCount === 0 || (tagCount === 1 && preset.tags.hasOwnProperty('area'));
|
||||
};
|
||||
|
||||
preset.visible = function(val) {
|
||||
if (!arguments.length) return visible;
|
||||
visible = val;
|
||||
return visible;
|
||||
preset.addable = function(val) {
|
||||
if (!arguments.length) return addable;
|
||||
addable = val;
|
||||
return addable;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -156,11 +156,11 @@ export function uiPresetList(context) {
|
||||
var collection = presets.collection.reduce(function(collection, preset) {
|
||||
if (preset.members) {
|
||||
if (preset.members.collection.filter(function(preset) {
|
||||
return preset.visible();
|
||||
return preset.addable();
|
||||
}).length > 1) {
|
||||
collection.push(CategoryItem(preset));
|
||||
}
|
||||
} else if (preset.visible()) {
|
||||
} else if (preset.addable()) {
|
||||
collection.push(PresetItem(preset));
|
||||
}
|
||||
return collection;
|
||||
|
||||
@@ -162,7 +162,7 @@ describe('iD.presetIndex', function () {
|
||||
presets.build(morePresets, false);
|
||||
entities.forEach(function (entity) {
|
||||
var preset = presets.match(entity, graph);
|
||||
expect(preset.visible()).to.be.false;
|
||||
expect(preset.addable()).to.be.false;
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -252,7 +252,7 @@ describe('iD.presetIndex', function () {
|
||||
server.restore();
|
||||
});
|
||||
|
||||
it('builds presets w/external sources set to visible', function () {
|
||||
it('builds presets w/external sources set to addable', function () {
|
||||
var surfShop = iD.osmNode({ tags: { amenity: 'shop', 'shop:type': 'surf' } });
|
||||
var graph = iD.coreGraph([surfShop]);
|
||||
var url = 'https://fakemaprules.io/fake.json';
|
||||
@@ -274,12 +274,12 @@ describe('iD.presetIndex', function () {
|
||||
server.respond();
|
||||
});
|
||||
|
||||
it('makes only the external presets initially visible', function () {
|
||||
it('makes only the external presets initially addable', function () {
|
||||
var url = 'https://fakemaprules.io/fake.json';
|
||||
|
||||
iD.coreContext().presets().fromExternal(url, function(externalPresets) {
|
||||
var external = externalPresets.collection.reduce(function(presets, preset) {
|
||||
if (!preset.hasOwnProperty('members') && preset.visible()) {
|
||||
if (!preset.hasOwnProperty('members') && preset.addable()) {
|
||||
presets.push(preset.id);
|
||||
}
|
||||
return presets;
|
||||
|
||||
@@ -194,12 +194,12 @@ describe('iD.presetPreset', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#visible', function() {
|
||||
describe('#addable', function() {
|
||||
it('sets/gets visibility of preset', function() {
|
||||
var preset = iD.presetPreset('test', {}, false);
|
||||
expect(preset.visible()).to.be.false;
|
||||
preset.visible(true);
|
||||
expect(preset.visible()).to.be.true;
|
||||
expect(preset.addable()).to.be.false;
|
||||
preset.addable(true);
|
||||
expect(preset.addable()).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user