Skip to content

Commit

Permalink
Accept IDs of loaded relations in the raw membership editor (close #3487
Browse files Browse the repository at this point in the history
)
  • Loading branch information
quincylvania committed Aug 9, 2019
1 parent dbbaca5 commit 53e7a26
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions modules/ui/raw_membership_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,35 +99,52 @@ export function uiRawMembershipEditor(context) {

function fetchNearbyRelations(q, callback) {
var newRelation = { relation: null, value: t('inspector.new_relation') };

var result = [];
var graph = context.graph();

context.intersects(context.extent()).forEach(function(entity) {
if (entity.type !== 'relation' || entity.id === _entityID) return;
var graph = context.graph();

function baseDisplayLabel(entity) {
var matched = context.presets().match(entity, graph);
var presetName = (matched && matched.name()) || t('inspector.relation');
var entityName = utilDisplayName(entity) || '';

var value = presetName + ' ' + entityName;
if (q && (value + ' ' + entity.id).toLowerCase().indexOf(q.toLowerCase()) === -1) return;
return presetName + ' ' + entityName;
}

result.push({ relation: entity, value: value });
});
var explicitRelation = q && context.hasEntity(q.toLowerCase());
if (explicitRelation && explicitRelation.type === 'relation' && explicitRelation.id !== _entityID) {
// loaded relation is specified explicitly, only show that

result.sort(function(a, b) {
return osmRelation.creationOrder(a.relation, b.relation);
});
result.push({
relation: explicitRelation,
value: baseDisplayLabel(explicitRelation) + ' ' + explicitRelation.id
});
} else {

context.intersects(context.extent()).forEach(function(entity) {
if (entity.type !== 'relation' || entity.id === _entityID) return;

// Dedupe identical names by appending relation id - see #2891
var dupeGroups = Object.values(utilArrayGroupBy(result, 'value'))
.filter(function(v) { return v.length > 1; });
var value = baseDisplayLabel(entity);
if (q && (value + ' ' + entity.id).toLowerCase().indexOf(q.toLowerCase()) === -1) return;

dupeGroups.forEach(function(group) {
group.forEach(function(obj) {
obj.value += ' ' + obj.relation.id;
result.push({ relation: entity, value: value });
});
});

result.sort(function(a, b) {
return osmRelation.creationOrder(a.relation, b.relation);
});

// Dedupe identical names by appending relation id - see #2891
var dupeGroups = Object.values(utilArrayGroupBy(result, 'value'))
.filter(function(v) { return v.length > 1; });

dupeGroups.forEach(function(group) {
group.forEach(function(obj) {
obj.value += ' ' + obj.relation.id;
});
});
}

result.forEach(function(obj) {
obj.title = obj.value;
Expand Down

0 comments on commit 53e7a26

Please sign in to comment.