From 9b37ac7b6c8a4cdc5adbfa156b4be457fc06a3db Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Sun, 13 Aug 2017 23:25:37 -0400 Subject: [PATCH] Fix errors with changeset fields and warnings, improve styles --- css/80_app.css | 3 ++ modules/ui/changeset_editor.js | 43 +++++++++++++++++------- modules/ui/commit.js | 60 ++++++++++++++++++++-------------- 3 files changed, 71 insertions(+), 35 deletions(-) diff --git a/css/80_app.css b/css/80_app.css index ef585e645..028d6967a 100644 --- a/css/80_app.css +++ b/css/80_app.css @@ -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; diff --git a/modules/ui/changeset_editor.js b/modules/ui/changeset_editor.js index 935e3c4b4..a157e58f1 100644 --- a/modules/ui/changeset_editor.js +++ b/modules/ui/changeset_editor.js @@ -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; }; diff --git a/modules/ui/commit.js b/modules/ui/commit.js index f416236d8..e93fac86a 100644 --- a/modules/ui/commit.js +++ b/modules/ui/commit.js @@ -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')