From 3e97bd7d899ec5122a47b6224eee2c8953e8c77f Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Sat, 6 Dec 2014 22:11:54 -0500 Subject: [PATCH] stub out iD.actions.MergeRemoteChanges --- index.html | 1 + js/id/actions/merge_remote_changes.js | 14 ++++++++ js/id/modes/save.js | 43 ++++++++--------------- test/index.html | 2 ++ test/spec/actions/merge_remote_changes.js | 3 ++ 5 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 js/id/actions/merge_remote_changes.js create mode 100644 test/spec/actions/merge_remote_changes.js diff --git a/index.html b/index.html index f3129da2d..5fc99cc5a 100644 --- a/index.html +++ b/index.html @@ -157,6 +157,7 @@ + diff --git a/js/id/actions/merge_remote_changes.js b/js/id/actions/merge_remote_changes.js new file mode 100644 index 000000000..bfcb78839 --- /dev/null +++ b/js/id/actions/merge_remote_changes.js @@ -0,0 +1,14 @@ +/* jshint ignore:start */ +iD.actions.MergeRemoteChanges = function(base, local, remote) { + + var action = function(graph) { + + // TODO + debugger; + + return graph; + }; + + return action; +}; +/* jshint ignore:end */ diff --git a/js/id/modes/save.js b/js/id/modes/save.js index 3ab835a14..4a2e7a89a 100644 --- a/js/id/modes/save.js +++ b/js/id/modes/save.js @@ -8,13 +8,10 @@ iD.modes.Save = function(context) { } function save(e) { - var altGraph = iD.Graph(context.history().base(), true), + var loading = iD.ui.Loading(context).message(t('save.uploading')).blocking(true), history = context.history(), - connection = context.connection(), - changes = history.changes(iD.actions.DiscardTags(history.difference())), - loading = iD.ui.Loading(context).message(t('save.uploading')).blocking(true), - toCheck = _.pluck(changes.modified, 'id'), - toMerge = []; + altGraph = iD.Graph(history.base(), true), + toCheck = _.pluck(history.changes().modified, 'id'), errors = []; context.container() @@ -25,19 +22,23 @@ iD.modes.Save = function(context) { _.each(toCheck, check); function check(id) { - connection.loadEntity(id, function(err) { + context.connection().loadEntity(id, function(err) { toCheck = _.without(toCheck, id); if (err) { errors.push(err.responseText); } else { - var entity = context.graph().entity(id), - altEntity = context.altGraph().entity(id); + var base = history.base().entity(id), + local = context.graph().entity(id), + remote = context.altGraph().entity(id), + diff; - if (entity.version !== altEntity.version) { - toMerge.push(id); - errors.push('Version mismatch for ' + id + ': local=' + entity.version + ', server=' + altEntity.version); + if (local.version !== remote.version) { + diff = history.perform(iD.actions.MergeRemoteChanges(base, local, remote)); + if (!diff.length) { + errors.push('Version mismatch for ' + id + ': local=' + local.version + ', remote=' + remote.version); + } } } @@ -47,22 +48,12 @@ iD.modes.Save = function(context) { }); } - function merge() { - var diff = context.history().difference(), - altDiff = iD.Difference(context.history().base(), context.altGraph()); - - // TODO - debugger; - } - function finalize() { - if (toMerge.length) merge(); - if (errors.length) { showErrors(); } else { - connection.putChangeset( - changes, + context.connection().putChangeset( + history.changes(iD.actions.DiscardTags(history.difference())), e.comment, history.imageryUsed(), function(err, changeset_id) { @@ -78,7 +69,6 @@ iD.modes.Save = function(context) { } } - function showErrors() { var confirm = iD.ui.confirm(context.container()); @@ -94,9 +84,6 @@ iD.modes.Save = function(context) { .append('p') .text(errors.join('
') || t('save.unknown_error_details')); } - - - } function success(e, changeset_id) { diff --git a/test/index.html b/test/index.html index f5cc7da2a..63dc14ded 100644 --- a/test/index.html +++ b/test/index.html @@ -136,6 +136,7 @@ + @@ -235,6 +236,7 @@ + diff --git a/test/spec/actions/merge_remote_changes.js b/test/spec/actions/merge_remote_changes.js new file mode 100644 index 000000000..a09b4f6e9 --- /dev/null +++ b/test/spec/actions/merge_remote_changes.js @@ -0,0 +1,3 @@ +describe("iD.actions.MergeRemoteChanges", function () { +// TODO +});