mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-23 16:49:40 +02:00
Replace validator tooltip with reference function, add tag diff
This commit is contained in:
@@ -18,7 +18,7 @@ export function validationPrivateData() {
|
||||
};
|
||||
|
||||
// but they might be public if they have one of these other tags
|
||||
var okayModifierKeys = {
|
||||
var publicKeys = {
|
||||
amenity: true,
|
||||
craft: true,
|
||||
historic: true,
|
||||
@@ -39,55 +39,87 @@ export function validationPrivateData() {
|
||||
website: true
|
||||
};
|
||||
|
||||
function privateDataKeys(entity) {
|
||||
var tags = entity.tags;
|
||||
if (!tags.building || !privateBuildingValues[tags.building]) return [];
|
||||
var privateKeys = [];
|
||||
for (var key in tags) {
|
||||
if (okayModifierKeys[key]) return [];
|
||||
if (personalTags[key]) privateKeys.push(key);
|
||||
}
|
||||
return privateKeys;
|
||||
}
|
||||
|
||||
var validation = function checkPrivateData(entity, context) {
|
||||
var privateKeys = privateDataKeys(entity);
|
||||
if (privateKeys.length === 0) return [];
|
||||
var tags = entity.tags;
|
||||
var keepTags = {};
|
||||
var tagDiff = [];
|
||||
if (!tags.building || !privateBuildingValues[tags.building]) return [];
|
||||
|
||||
for (var k in tags) {
|
||||
if (publicKeys[k]) return []; // probably a public feature
|
||||
|
||||
if (personalTags[k]) {
|
||||
tagDiff.push('- ' + k + '=' + tags[k]);
|
||||
} else {
|
||||
keepTags[k] = tags[k];
|
||||
}
|
||||
}
|
||||
|
||||
if (!tagDiff.length) return [];
|
||||
|
||||
var fixID = tagDiff.length === 1 ? 'remove_tag' : 'remove_tags';
|
||||
|
||||
var fixID = privateKeys.length === 1 ? 'remove_tag' : 'remove_tags';
|
||||
return [new validationIssue({
|
||||
type: type,
|
||||
severity: 'warning',
|
||||
message: t('issues.private_data.contact.message', {
|
||||
feature: utilDisplayLabel(entity, context),
|
||||
}),
|
||||
tooltip: t('issues.private_data.tip'),
|
||||
reference: showReference,
|
||||
entities: [entity],
|
||||
data: {
|
||||
privateKeys: privateKeys
|
||||
newTags: keepTags
|
||||
},
|
||||
fixes: [
|
||||
new validationIssueFix({
|
||||
auto: true,
|
||||
icon: 'iD-operation-delete',
|
||||
title: t('issues.fix.' + fixID + '.title'),
|
||||
onClick: function() {
|
||||
var entity = this.issue.entities[0];
|
||||
var tags = Object.assign({}, entity.tags); // shallow copy
|
||||
var privateKeys = this.issue.data.privateKeys;
|
||||
for (var index in privateKeys) {
|
||||
delete tags[privateKeys[index]];
|
||||
}
|
||||
var entityID = this.issue.entities[0].id;
|
||||
var newTags = this.issue.data.newTags;
|
||||
context.perform(
|
||||
actionChangeTags(entity.id, tags),
|
||||
t('issues.fix.remove_private_info.annotation')
|
||||
actionChangeTags(entityID, newTags),
|
||||
t('issues.fix.upgrade_tags.annotation')
|
||||
);
|
||||
}
|
||||
})
|
||||
]
|
||||
})];
|
||||
|
||||
|
||||
function showReference(selection) {
|
||||
var enter = selection.selectAll('.issue-reference')
|
||||
.data([0])
|
||||
.enter();
|
||||
|
||||
enter
|
||||
.append('div')
|
||||
.attr('class', 'issue-reference')
|
||||
.text(t('issues.private_data.tip'));
|
||||
|
||||
enter
|
||||
.append('strong')
|
||||
.text(t('issues.suggested'));
|
||||
|
||||
enter
|
||||
.append('table')
|
||||
.attr('class', 'tagDiff-table')
|
||||
.selectAll('.tagDiff-row')
|
||||
.data(tagDiff)
|
||||
.enter()
|
||||
.append('tr')
|
||||
.attr('class', 'tagDiff-row')
|
||||
.append('td')
|
||||
.attr('class', function(d) {
|
||||
var klass = d.charAt(0) === '+' ? 'add' : 'remove';
|
||||
return 'tagDiff-cell tagDiff-cell-' + klass;
|
||||
})
|
||||
.text(function(d) { return d; });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
validation.type = type;
|
||||
|
||||
return validation;
|
||||
|
||||
Reference in New Issue
Block a user