mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 21:28:11 +02:00
Variable cleanups and formatting
This commit is contained in:
+26
-27
@@ -67,18 +67,17 @@ export function modeSave(context) {
|
||||
|
||||
|
||||
function save(changeset, tryAgain) {
|
||||
|
||||
var osm = context.connection(),
|
||||
loading = uiLoading(context).message(t('save.uploading')).blocking(true),
|
||||
history = context.history(),
|
||||
origChanges = history.changes(actionDiscardTags(history.difference())),
|
||||
localGraph = context.graph(),
|
||||
remoteGraph = coreGraph(history.base(), true),
|
||||
modified = _filter(history.difference().summary(), {changeType: 'modified'}),
|
||||
toCheck = _map(_map(modified, 'entity'), 'id'),
|
||||
toLoad = withChildNodes(toCheck, localGraph),
|
||||
conflicts = [],
|
||||
errors = [];
|
||||
var osm = context.connection();
|
||||
var loading = uiLoading(context).message(t('save.uploading')).blocking(true);
|
||||
var history = context.history();
|
||||
var origChanges = history.changes(actionDiscardTags(history.difference()));
|
||||
var localGraph = context.graph();
|
||||
var remoteGraph = coreGraph(history.base(), true);
|
||||
var modified = _filter(history.difference().summary(), {changeType: 'modified'});
|
||||
var toCheck = _map(_map(modified, 'entity'), 'id');
|
||||
var toLoad = withChildNodes(toCheck, localGraph);
|
||||
var conflicts = [];
|
||||
var errors = [];
|
||||
|
||||
if (!osm) return;
|
||||
|
||||
@@ -100,8 +99,8 @@ export function modeSave(context) {
|
||||
var entity = graph.entity(id);
|
||||
if (entity.type === 'way') {
|
||||
try {
|
||||
var cn = graph.childNodes(entity);
|
||||
result.push.apply(result, _map(_filter(cn, 'version'), 'id'));
|
||||
var children = graph.childNodes(entity);
|
||||
result.push.apply(result, _map(_filter(children, 'version'), 'id'));
|
||||
} catch (err) {
|
||||
/* eslint-disable no-console */
|
||||
if (typeof console !== 'undefined') console.error(err);
|
||||
@@ -172,8 +171,8 @@ export function modeSave(context) {
|
||||
var children = _union(local.nodes, remote.nodes);
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var a = localGraph.hasEntity(children[i]),
|
||||
b = remoteGraph.hasEntity(children[i]);
|
||||
var a = localGraph.hasEntity(children[i]);
|
||||
var b = remoteGraph.hasEntity(children[i]);
|
||||
|
||||
if (a && b && a.version !== b.version) return false;
|
||||
}
|
||||
@@ -183,23 +182,23 @@ export function modeSave(context) {
|
||||
}
|
||||
|
||||
_each(toCheck, function(id) {
|
||||
var local = localGraph.entity(id),
|
||||
remote = remoteGraph.entity(id);
|
||||
var local = localGraph.entity(id);
|
||||
var remote = remoteGraph.entity(id);
|
||||
|
||||
if (compareVersions(local, remote)) return;
|
||||
|
||||
var action = actionMergeRemoteChanges,
|
||||
merge = action(id, localGraph, remoteGraph, formatUser);
|
||||
var action = actionMergeRemoteChanges;
|
||||
var merge = action(id, localGraph, remoteGraph, formatUser);
|
||||
|
||||
history.replace(merge);
|
||||
|
||||
var mergeConflicts = merge.conflicts();
|
||||
if (!mergeConflicts.length) return; // merged safely
|
||||
|
||||
var forceLocal = action(id, localGraph, remoteGraph).withOption('force_local'),
|
||||
forceRemote = action(id, localGraph, remoteGraph).withOption('force_remote'),
|
||||
keepMine = t('save.conflict.' + (remote.visible ? 'keep_local' : 'restore')),
|
||||
keepTheirs = t('save.conflict.' + (remote.visible ? 'keep_remote' : 'delete'));
|
||||
var forceLocal = action(id, localGraph, remoteGraph).withOption('force_local');
|
||||
var forceRemote = action(id, localGraph, remoteGraph).withOption('force_remote');
|
||||
var keepMine = t('save.conflict.' + (remote.visible ? 'keep_local' : 'restore'));
|
||||
var keepTheirs = t('save.conflict.' + (remote.visible ? 'keep_remote' : 'delete'));
|
||||
|
||||
conflicts.push({
|
||||
id: id,
|
||||
@@ -328,9 +327,9 @@ export function modeSave(context) {
|
||||
.classed('hide-toggle', true)
|
||||
.text(function(d) { return d.msg || t('save.unknown_error_details'); })
|
||||
.on('click', function() {
|
||||
var error = d3_select(this),
|
||||
detail = d3_select(this.nextElementSibling),
|
||||
exp = error.classed('expanded');
|
||||
var error = d3_select(this);
|
||||
var detail = d3_select(this.nextElementSibling);
|
||||
var exp = error.classed('expanded');
|
||||
|
||||
detail.style('display', exp ? 'none' : 'block');
|
||||
error.classed('expanded', !exp);
|
||||
|
||||
+26
-26
@@ -16,9 +16,9 @@ import { utilDetect } from '../util/detect';
|
||||
import { utilRebind } from '../util';
|
||||
|
||||
|
||||
var changeset;
|
||||
var _changeset;
|
||||
var readOnlyTags = [
|
||||
/^changesets_count$/,
|
||||
/^_changesets_count$/,
|
||||
/^created_by$/,
|
||||
/^ideditor:/,
|
||||
/^imagery_used$/,
|
||||
@@ -32,9 +32,9 @@ var hashtagRegex = /(#[^\u2000-\u206F\u2E00-\u2E7F\s\\'!"#$%()*,.\/:;<=>?@\[\]^`
|
||||
|
||||
|
||||
export function uiCommit(context) {
|
||||
var dispatch = d3_dispatch('cancel', 'save'),
|
||||
userDetails,
|
||||
_selection;
|
||||
var dispatch = d3_dispatch('cancel', 'save');
|
||||
var _userDetails;
|
||||
var _selection;
|
||||
|
||||
var changesetEditor = uiChangesetEditor(context)
|
||||
.on('change', changeTags);
|
||||
@@ -51,16 +51,16 @@ export function uiCommit(context) {
|
||||
if (!osm) return;
|
||||
|
||||
// expire stored comment and hashtags after cutoff datetime - #3947
|
||||
var commentDate = +context.storage('commentDate') || 0,
|
||||
currDate = Date.now(),
|
||||
cutoff = 2 * 86400 * 1000; // 2 days
|
||||
var commentDate = +context.storage('commentDate') || 0;
|
||||
var currDate = Date.now();
|
||||
var cutoff = 2 * 86400 * 1000; // 2 days
|
||||
if (commentDate > currDate || currDate - commentDate > cutoff) {
|
||||
context.storage('comment', null);
|
||||
context.storage('hashtags', null);
|
||||
}
|
||||
|
||||
var tags;
|
||||
if (!changeset) {
|
||||
if (!_changeset) {
|
||||
var detected = utilDetect();
|
||||
tags = {
|
||||
comment: context.storage('comment') || '',
|
||||
@@ -78,12 +78,12 @@ export function uiCommit(context) {
|
||||
tags.hashtags = hashtags;
|
||||
}
|
||||
|
||||
changeset = new osmChangeset({ tags: tags });
|
||||
_changeset = new osmChangeset({ tags: tags });
|
||||
}
|
||||
|
||||
tags = _clone(changeset.tags);
|
||||
tags = _clone(_changeset.tags);
|
||||
tags.imagery_used = context.history().imageryUsed().join(';').substr(0, 255);
|
||||
changeset = changeset.update({ tags: tags });
|
||||
_changeset = _changeset.update({ tags: tags });
|
||||
|
||||
var header = selection.selectAll('.header')
|
||||
.data([0]);
|
||||
@@ -114,7 +114,7 @@ export function uiCommit(context) {
|
||||
|
||||
changesetSection
|
||||
.call(changesetEditor
|
||||
.changesetID(changeset.id)
|
||||
.changesetID(_changeset.id)
|
||||
.tags(tags)
|
||||
);
|
||||
|
||||
@@ -146,7 +146,7 @@ export function uiCommit(context) {
|
||||
|
||||
var userLink = d3_select(document.createElement('div'));
|
||||
|
||||
userDetails = user;
|
||||
_userDetails = user;
|
||||
|
||||
if (user.image_url) {
|
||||
userLink
|
||||
@@ -195,7 +195,7 @@ export function uiCommit(context) {
|
||||
.merge(requestReviewEnter);
|
||||
|
||||
var requestReviewInput = requestReview.selectAll('input')
|
||||
.property('checked', isReviewRequested(changeset.tags))
|
||||
.property('checked', isReviewRequested(_changeset.tags))
|
||||
.on('change', toggleRequestReview);
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ export function uiCommit(context) {
|
||||
return (n && n.value.length) ? null : true;
|
||||
})
|
||||
.on('click.save', function() {
|
||||
dispatch.call('save', this, changeset);
|
||||
dispatch.call('save', this, _changeset);
|
||||
});
|
||||
|
||||
|
||||
@@ -256,7 +256,7 @@ export function uiCommit(context) {
|
||||
.call(rawTagEditor
|
||||
.expanded(expanded)
|
||||
.readOnlyTags(readOnlyTags)
|
||||
.tags(_clone(changeset.tags))
|
||||
.tags(_clone(_changeset.tags))
|
||||
);
|
||||
|
||||
|
||||
@@ -273,7 +273,7 @@ export function uiCommit(context) {
|
||||
.call(rawTagEditor
|
||||
.expanded(expanded)
|
||||
.readOnlyTags(readOnlyTags)
|
||||
.tags(_clone(changeset.tags))
|
||||
.tags(_clone(_changeset.tags))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -299,8 +299,8 @@ export function uiCommit(context) {
|
||||
|
||||
|
||||
function findHashtags(tags, commentOnly) {
|
||||
var inComment = commentTags(),
|
||||
inHashTags = hashTags();
|
||||
var inComment = commentTags();
|
||||
var inHashTags = hashTags();
|
||||
|
||||
if (inComment !== null) { // when hashtags are detected in comment...
|
||||
context.storage('hashtags', null); // always remove stored hashtags - #4304
|
||||
@@ -340,7 +340,7 @@ export function uiCommit(context) {
|
||||
|
||||
|
||||
function updateChangeset(changed, onInput) {
|
||||
var tags = _clone(changeset.tags);
|
||||
var tags = _clone(_changeset.tags);
|
||||
|
||||
_forEach(changed, function(v, k) {
|
||||
k = k.trim().substr(0, 255);
|
||||
@@ -371,8 +371,8 @@ export function uiCommit(context) {
|
||||
}
|
||||
|
||||
// always update userdetails, just in case user reauthenticates as someone else
|
||||
if (userDetails && userDetails.changesets_count !== undefined) {
|
||||
var changesetsCount = parseInt(userDetails.changesets_count, 10) + 1; // #4283
|
||||
if (_userDetails && _userDetails.changesets_count !== undefined) {
|
||||
var changesetsCount = parseInt(_userDetails.changesets_count, 10) + 1; // #4283
|
||||
tags.changesets_count = String(changesetsCount);
|
||||
|
||||
// first 100 edits - new user
|
||||
@@ -397,14 +397,14 @@ export function uiCommit(context) {
|
||||
delete tags.changesets_count;
|
||||
}
|
||||
|
||||
if (!_isEqual(changeset.tags, tags)) {
|
||||
changeset = changeset.update({ tags: tags });
|
||||
if (!_isEqual(_changeset.tags, tags)) {
|
||||
_changeset = _changeset.update({ tags: tags });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
commit.reset = function() {
|
||||
changeset = null;
|
||||
_changeset = null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+13
-12
@@ -1,16 +1,17 @@
|
||||
import { select as d3_select } from 'd3-selection';
|
||||
import { uiModal } from './modal';
|
||||
|
||||
|
||||
export function uiLoading(context) {
|
||||
var message = '',
|
||||
blocking = false,
|
||||
modalSelection;
|
||||
var _modalSelection = d3_select(null);
|
||||
var _message = '';
|
||||
var _blocking = false;
|
||||
|
||||
|
||||
var loading = function(selection) {
|
||||
modalSelection = uiModal(selection, blocking);
|
||||
_modalSelection = uiModal(selection, _blocking);
|
||||
|
||||
var loadertext = modalSelection.select('.content')
|
||||
var loadertext = _modalSelection.select('.content')
|
||||
.classed('loading-modal', true)
|
||||
.append('div')
|
||||
.attr('class', 'modal-section fillL');
|
||||
@@ -22,9 +23,9 @@ export function uiLoading(context) {
|
||||
|
||||
loadertext
|
||||
.append('h3')
|
||||
.text(message);
|
||||
.text(_message);
|
||||
|
||||
modalSelection.select('button.close')
|
||||
_modalSelection.select('button.close')
|
||||
.attr('class', 'hide');
|
||||
|
||||
return loading;
|
||||
@@ -32,21 +33,21 @@ export function uiLoading(context) {
|
||||
|
||||
|
||||
loading.message = function(_) {
|
||||
if (!arguments.length) return message;
|
||||
message = _;
|
||||
if (!arguments.length) return _message;
|
||||
_message = _;
|
||||
return loading;
|
||||
};
|
||||
|
||||
|
||||
loading.blocking = function(_) {
|
||||
if (!arguments.length) return blocking;
|
||||
blocking = _;
|
||||
if (!arguments.length) return _blocking;
|
||||
_blocking = _;
|
||||
return loading;
|
||||
};
|
||||
|
||||
|
||||
loading.close = function() {
|
||||
modalSelection.remove();
|
||||
_modalSelection.remove();
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user