Fix errors with changeset fields and warnings, improve styles

This commit is contained in:
Bryan Housel
2017-08-13 23:25:37 -04:00
parent 78e874d6c4
commit 9b37ac7b6c
3 changed files with 71 additions and 35 deletions

View File

@@ -1370,6 +1370,9 @@ button.save.has-count .count::before {
padding: 0 20px 20px 20px;
font-weight: bold;
}
.changeset-editor .more-fields {
padding: 15px 20px 0 20px;
}
.more-fields label {
display: flex;

View File

@@ -1,5 +1,4 @@
import * as d3 from 'd3';
import _ from 'lodash';
import { d3combobox } from '../lib/d3.combobox.js';
import { t } from '../util/locale';
import { uiField } from './field';
@@ -13,19 +12,26 @@ import {
export function uiChangesetEditor(context) {
var dispatch = d3.dispatch('change'),
fieldsArr,
changeset;
tags,
changesetId;
function changesetEditor(selection) {
var tags = _.clone(changeset.tags);
render(selection);
}
function render(selection) {
var initial = false;
if (!fieldsArr) {
initial = true;
var presets = context.presets();
fieldsArr = [
uiField(context, presets.field('comment'), changeset),
uiField(context, presets.field('source'), changeset, { show: false }),
uiField(context, presets.field('hashtags'), changeset, { show: false }),
uiField(context, presets.field('comment'), null, { show: true, revert: false }),
uiField(context, presets.field('source'), null, { show: false, revert: false }),
uiField(context, presets.field('hashtags'), null, { show: false, revert: false }),
];
fieldsArr.forEach(function(field) {
@@ -50,7 +56,7 @@ export function uiChangesetEditor(context) {
form = form.enter()
.append('div')
.attr('class', 'preset-form inspector-inner fillL3')
.attr('class', 'preset-form')
.merge(form);
@@ -77,6 +83,12 @@ export function uiChangesetEditor(context) {
});
if (initial) {
var node = d3.select('#preset-input-comment').node();
node && node.focus();
node && node.select();
}
notShown = notShown.map(function(field) {
return {
title: field.label(),
@@ -129,16 +141,25 @@ export function uiChangesetEditor(context) {
.on('accept', function (d) {
var field = d.field;
field.show = true;
changesetEditor(selection);
render(selection);
field.focus();
})
);
}
changesetEditor.changeset = function(_) {
if (!arguments.length) return changeset;
changeset = _;
changesetEditor.tags = function(_) {
if (!arguments.length) return tags;
tags = _;
// Don't reset fieldsArr here.
return changesetEditor;
};
changesetEditor.changesetID = function(_) {
if (!arguments.length) return changesetId;
if (changesetId === _) return changesetEditor;
changesetId = _;
fieldsArr = null;
return changesetEditor;
};

View File

@@ -50,19 +50,21 @@ export function uiCommit(context) {
comment = '';
}
var tags;
if (!changeset) {
var detected = utilDetect(),
tags = {
comment: comment,
created_by: ('iD ' + context.version).substr(0, 255),
imagery_used: context.history().imageryUsed().join(';').substr(0, 255),
host: detected.host.substr(0, 255),
locale: detected.locale.substr(0, 255)
};
var detected = utilDetect();
tags = {
comment: comment,
created_by: ('iD ' + context.version).substr(0, 255),
imagery_used: context.history().imageryUsed().join(';').substr(0, 255),
host: detected.host.substr(0, 255),
locale: detected.locale.substr(0, 255)
};
changeset = new osmChangeset({ tags: tags });
}
tags = _.clone(changeset.tags);
var header = selection.selectAll('.header')
.data([0]);
@@ -93,7 +95,8 @@ export function uiCommit(context) {
changesetSection
.call(changesetEditor
.changeset(changeset)
.changesetID(changeset.id)
.tags(tags)
);
@@ -157,41 +160,50 @@ export function uiCommit(context) {
// Warnings
var warnings = body.selectAll('div.warning-section')
.data([context.history().validate(changes)]);
var warnings = context.history().validate(changes);
var warningSection = body.selectAll('div.warning-section')
.data(warnings.length ? [0] : []);
warnings = warnings.enter()
warningSection.exit()
.remove();
var warningEnter = warningSection.enter()
.append('div')
.attr('class', 'modal-section warning-section fillL2')
.style('display', function(d) { return _.isEmpty(d) ? 'none' : null; })
.merge(warnings);
.attr('class', 'modal-section warning-section fillL2');
warnings
warningEnter
.append('h3')
.text(t('commit.warnings'));
warnings
warningEnter
.append('ul')
.attr('class', 'changeset-list');
var warningLi = warnings.select('ul').selectAll('li')
.data(function(d) { return d; });
warningSection = warningEnter
.merge(warningSection);
warningLi = warningLi.enter()
var warningItems = warningSection.select('ul').selectAll('li')
.data(warnings);
warningItems.exit()
.remove();
warningItems = warningItems.enter()
.append('li')
.on('mouseover', mouseover)
.on('mouseout', mouseout)
.on('click', warningClick)
.merge(warningLi);
.merge(warningItems);
warningLi
warningItems
.call(svgIcon('#icon-alert', 'pre-text'));
warningLi
warningItems
.append('strong')
.text(function(d) { return d.message; });
warningLi.filter(function(d) { return d.tooltip; })
warningItems.filter(function(d) { return d.tooltip; })
.call(tooltip()
.title(function(d) { return d.tooltip; })
.placement('top')