Support more *:wikidata tags for field locking and pin styling

This commit is contained in:
Bryan Housel
2021-01-18 17:18:37 -05:00
parent f39f73e3ae
commit 4228b65602
4 changed files with 76 additions and 23 deletions
+7 -1
View File
@@ -155,7 +155,13 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) {
_this.reference = () => {
// Lookup documentation on Wikidata...
const qid = _this.tags.wikidata || _this.tags['brand:wikidata'] || _this.tags['operator:wikidata'];
const qid = (
_this.tags.wikidata ||
_this.tags['flag:wikidata'] ||
_this.tags['brand:wikidata'] ||
_this.tags['network:wikidata'] ||
_this.tags['operator:wikidata']
);
if (qid) {
return { qid: qid };
}
+9 -1
View File
@@ -160,7 +160,15 @@ export function svgTagClasses() {
}
// If this is a wikidata-tagged item, add a class for that..
if (t.wikidata || t['brand:wikidata']) {
var qid = (
t.wikidata ||
t['flag:wikidata'] ||
t['brand:wikidata'] ||
t['network:wikidata'] ||
t['operator:wikidata']
);
if (qid) {
classes.push('tag-wikidata');
}
+34 -4
View File
@@ -34,11 +34,41 @@ export function uiFieldText(field, context) {
.catch(function() { /* ignore */ });
}
function i(selection) {
var entity = _entityIDs.length && context.hasEntity(_entityIDs[0]);
var preset = entity && presetManager.match(entity, context.graph());
var isLocked = preset && preset.suggestion && field.id === 'brand';
function calcLocked() {
// Protect certain fields that have a companion `*:wikidata` value
var isLocked = (field.id === 'brand' || field.id === 'network' || field.id === 'operator' || field.id === 'flag') &&
_entityIDs.length &&
_entityIDs.some(function(entityID) {
var entity = context.graph().hasEntity(entityID);
if (!entity) return false;
var which = field.id; // 'brand', 'network', 'operator', 'flag'
// If the value was already edited manually then unlock and allow further editing
var base = context.graph().base().entities[_entityIDs[0]];
if (base) {
var hasOriginalValue = entity.tags[which] && entity.tags[which] === base.tags[which];
if (!hasOriginalValue) return false;
}
// Features linked to Wikidata are likely important and should be protected
if (entity.tags.wikidata) return true;
var preset = presetManager.match(entity, context.graph());
var isSuggestion = preset && preset.suggestion;
// Lock the field if there is a value and a companion `*:wikidata` value
return isSuggestion && !!entity.tags[which] && !!entity.tags[which + ':wikidata'];
});
field.locked(isLocked);
}
function i(selection) {
calcLocked();
var isLocked = field.locked();
var wrap = selection.selectAll('.form-field-input-wrap')
.data([0]);
+26 -17
View File
@@ -83,34 +83,43 @@ export function uiFieldLocalized(field, context) {
function calcLocked() {
// only lock the Name field
var isLocked = field.id === 'name' &&
// Protect name field for suggestion presets that don't display a brand/operator field
var isLocked = (field.id === 'name') &&
_entityIDs.length &&
// lock the field if any feature needs it
_entityIDs.some(function(entityID) {
var entity = context.graph().hasEntity(entityID);
if (!entity) return false;
var original = context.graph().base().entities[_entityIDs[0]];
var hasOriginalName = original && entity.tags.name && entity.tags.name === original.tags.name;
// if the name was already edited manually then allow further editing
if (!hasOriginalName) return false;
// If the value was already edited manually then unlock and allow further editing
var base = context.graph().base().entities[_entityIDs[0]];
if (base) {
var hasOriginalValue = entity.tags.name && entity.tags.name === base.tags.name;
if (!hasOriginalValue) return false;
}
// features linked to Wikidata are likely important and should be protected
// Features linked to Wikidata are likely important and should be protected
if (entity.tags.wikidata) return true;
// assume the name has already been confirmed if its source has been researched
// Assume the name has already been confirmed if its source has been researched
if (entity.tags['name:etymology:wikidata']) return true;
// Lock the name if this is a suggestion preset that assigns the name
var preset = presetManager.match(entity, context.graph());
var isSuggestion = preset && preset.suggestion;
var showsBrand = preset && preset.originalFields.filter(function(d) {
return d.id === 'brand';
}).length;
// protect standardized brand names
return isSuggestion && !showsBrand;
if (preset) {
var isSuggestion = preset.suggestion;
var showsBrandField = preset.originalFields.some(function(d) { return d.id === 'brand'; });
var showsOperatorField = preset.originalFields.some(function(d) { return d.id === 'operator'; });
var setsName = preset.addTags.name;
var setsBrandWikidata = preset.addTags['brand:wikidata'];
var setsOperatorWikidata = preset.addTags['operator:wikidata'];
return isSuggestion && setsName && (
(setsBrandWikidata && !showsBrandField) ||
(setsOperatorWikidata && !showsOperatorField)
);
}
return false;
});
field.locked(isLocked);