Add mechanism for fields to support editing during multiselection (re: #7276)

Add `utilCombinedTags` method and use it for the raw tag editor as well as fields
Pass `entityIDs` array into fields instead of single `entity` object
Give field revertion its own path separate from `change`
Add multiselection editing to fields in files: access, address, check, combo, cycleway, input, maxspeed, textarea, and wikidata
This commit is contained in:
Quincy Morgan
2020-01-30 13:53:29 -05:00
parent 1e21eea745
commit 1b331bb678
25 changed files with 808 additions and 339 deletions
+34 -12
View File
@@ -21,13 +21,15 @@ export function uiFieldCheck(field, context) {
var values = [];
var texts = [];
var _tags;
var input = d3_select(null);
var text = d3_select(null);
var label = d3_select(null);
var reverser = d3_select(null);
var _impliedYes;
var _entityID;
var _entityIDs = [];
var _value;
@@ -53,7 +55,7 @@ export function uiFieldCheck(field, context) {
// hack: pretend `oneway` field is a `oneway_yes` field
// where implied oneway tag exists (e.g. `junction=roundabout`) #2220, #1841
if (field.id === 'oneway') {
var entity = context.entity(_entityID);
var entity = context.entity(_entityIDs[0]);
for (var key in entity.tags) {
if (key in osmOneWayTags && (entity.tags[key] in osmOneWayTags[key])) {
_impliedYes = true;
@@ -72,7 +74,7 @@ export function uiFieldCheck(field, context) {
function reverserSetText(selection) {
var entity = context.hasEntity(_entityID);
var entity = _entityIDs.length && context.hasEntity(_entityIDs[0]);
if (reverserHidden() || !entity) return selection;
var first = entity.first();
@@ -127,7 +129,16 @@ export function uiFieldCheck(field, context) {
.on('click', function() {
d3_event.stopPropagation();
var t = {};
t[field.key] = values[(values.indexOf(_value) + 1) % values.length];
if (Array.isArray(_tags[field.key])) {
if (values.indexOf('yes') !== -1) {
t[field.key] = 'yes';
} else {
t[field.key] = values[0];
}
} else {
t[field.key] = values[(values.indexOf(_value) + 1) % values.length];
}
// Don't cycle through `alternating` or `reversible` states - #4970
// (They are supported as translated strings, but should not toggle with clicks)
@@ -147,10 +158,15 @@ export function uiFieldCheck(field, context) {
d3_event.preventDefault();
d3_event.stopPropagation();
context.perform(
actionReverse(_entityID),
function(graph) {
for (var i in _entityIDs) {
graph = actionReverse(_entityIDs[i])(graph);
}
return graph;
},
t('operations.reverse.annotation')
);
// must manually revalidate since no 'change' event was called
context.validator().validate();
@@ -161,15 +177,17 @@ export function uiFieldCheck(field, context) {
};
check.entity = function(_) {
if (!arguments.length) return context.hasEntity(_entityID);
_entityID = _.id;
check.entityIDs = function(val) {
if (!arguments.length) return _entityIDs;
_entityIDs = val;
return check;
};
check.tags = function(tags) {
_tags = tags;
function isChecked(val) {
return val !== 'no' && val !== '' && val !== undefined && val !== null;
}
@@ -181,18 +199,22 @@ export function uiFieldCheck(field, context) {
}
checkImpliedYes();
_value = tags[field.key] && tags[field.key].toLowerCase();
var isMixed = Array.isArray(tags[field.key]);
_value = !isMixed && tags[field.key] && tags[field.key].toLowerCase();
if (field.type === 'onewayCheck' && (_value === '1' || _value === '-1')) {
_value = 'yes';
}
input
.property('indeterminate', field.type !== 'defaultCheck' && !_value)
.property('indeterminate', isMixed || (field.type !== 'defaultCheck' && !_value))
.property('checked', isChecked(_value));
text
.text(textFor(_value));
.text(isMixed ? t('inspector.multiple_values') : textFor(_value))
.classed('mixed', isMixed);
label
.classed('set', !!_value);