Skip to content

Commit

Permalink
Don't add empty source tag on a changeset
Browse files Browse the repository at this point in the history
(closes #4993)
  • Loading branch information
bhousel committed Apr 18, 2018
1 parent a86167f commit d8f6faf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
43 changes: 21 additions & 22 deletions modules/ui/changeset_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import { utilRebind, utilTriggerEvent } from '../util';


export function uiChangesetEditor(context) {
var dispatch = d3_dispatch('change'),
formFields = uiFormFields(context),
fieldsArr,
tags,
changesetId;

var dispatch = d3_dispatch('change');
var formFields = uiFormFields(context);
var _fieldsArr;
var _tags;
var _changesetID;


function changesetEditor(selection) {
Expand All @@ -27,37 +26,37 @@ export function uiChangesetEditor(context) {
function render(selection) {
var initial = false;

if (!fieldsArr) {
if (!_fieldsArr) {
initial = true;
var presets = context.presets();

fieldsArr = [
_fieldsArr = [
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) {
_fieldsArr.forEach(function(field) {
field
.on('change', function(t, onInput) {
dispatch.call('change', field, t, onInput);
});
});
}

fieldsArr.forEach(function(field) {
_fieldsArr.forEach(function(field) {
field
.tags(tags);
.tags(_tags);
});


selection
.call(formFields.fieldsArr(fieldsArr));
.call(formFields.fieldsArr(_fieldsArr));


if (initial) {
var commentField = selection.select('#preset-input-comment'),
commentNode = commentField.node();
var commentField = selection.select('#preset-input-comment');
var commentNode = commentField.node();

if (commentNode) {
commentNode.focus();
Expand Down Expand Up @@ -91,7 +90,7 @@ export function uiChangesetEditor(context) {
}

// Add warning if comment mentions Google
var hasGoogle = tags.comment.match(/google/i);
var hasGoogle = _tags.comment.match(/google/i);
var commentWarning = selection.select('.form-field-comment').selectAll('.comment-warning')
.data(hasGoogle ? [0] : []);

Expand Down Expand Up @@ -123,18 +122,18 @@ export function uiChangesetEditor(context) {


changesetEditor.tags = function(_) {
if (!arguments.length) return tags;
tags = _;
// Don't reset fieldsArr here.
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;
if (!arguments.length) return _changesetID;
if (_changesetID === _) return changesetEditor;
_changesetID = _;
_fieldsArr = null;
return changesetEditor;
};

Expand Down
11 changes: 6 additions & 5 deletions modules/ui/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { utilRebind } from '../util';

var _changeset;
var readOnlyTags = [
/^_changesets_count$/,
/^changesets_count$/,
/^created_by$/,
/^ideditor:/,
/^imagery_used$/,
Expand Down Expand Up @@ -65,7 +65,6 @@ export function uiCommit(context) {
var detected = utilDetect();
tags = {
comment: context.storage('comment') || '',
source: context.storage('source') || '',
created_by: ('iD ' + context.version).substr(0, 255),
host: detected.host.substr(0, 255),
locale: detected.locale.substr(0, 255)
Expand All @@ -80,6 +79,11 @@ export function uiCommit(context) {
tags.hashtags = hashtags;
}

var source = context.storage('source');
if (source) {
tags.source = source;
}

_changeset = new osmChangeset({ tags: tags });
}

Expand Down Expand Up @@ -293,9 +297,6 @@ export function uiCommit(context) {
}
}
if (changed.hasOwnProperty('source')) {
if (changed.source === undefined) {
changed.source = '';
}
if (!onInput) {
context.storage('source', changed.source);
context.storage('commentDate', Date.now());
Expand Down

0 comments on commit d8f6faf

Please sign in to comment.