Remove Connection#user and always use #userDetails

Because the embedded iD does not show the account
UI, Connection#userDetails was not being called, so
the commit UI didn't show the user name and image.

Fixes #1464
This commit is contained in:
John Firebaugh
2013-06-13 17:31:29 -07:00
parent 34bf86a904
commit 3861879f62
5 changed files with 49 additions and 42 deletions
+2 -1
View File
@@ -150,7 +150,8 @@ en:
title: Save Changes
description_placeholder: Brief description of your contributions
message_label: Commit message
upload_explanation: "The changes you upload as {user} will be visible on all maps that use OpenStreetMap data."
upload_explanation: "The changes you upload will be visible on all maps that use OpenStreetMap data."
upload_explanation_with_user: "The changes you upload as {user} will be visible on all maps that use OpenStreetMap data."
save: Save
cancel: Cancel
warnings: Warnings
+2 -1
View File
@@ -189,7 +189,8 @@
"title": "Save Changes",
"description_placeholder": "Brief description of your contributions",
"message_label": "Commit message",
"upload_explanation": "The changes you upload as {user} will be visible on all maps that use OpenStreetMap data.",
"upload_explanation": "The changes you upload will be visible on all maps that use OpenStreetMap data.",
"upload_explanation_with_user": "The changes you upload as {user} will be visible on all maps that use OpenStreetMap data.",
"save": "Save",
"cancel": "Cancel",
"warnings": "Warnings",
+17 -11
View File
@@ -3,7 +3,6 @@ iD.Connection = function() {
var event = d3.dispatch('authenticating', 'authenticated', 'auth', 'loading', 'load', 'loaded'),
url = 'http://www.openstreetmap.org',
connection = {},
user = {},
inflight = {},
loadedTiles = {},
oauth = osmAuth({
@@ -173,7 +172,7 @@ iD.Connection = function() {
// Generate [osmChange](http://wiki.openstreetmap.org/wiki/OsmChange)
// XML. Returns a string.
connection.osmChangeJXON = function(userid, changeset_id, changes) {
connection.osmChangeJXON = function(changeset_id, changes) {
function nest(x, order) {
var groups = {};
for (var i = 0; i < x.length; i++) {
@@ -228,7 +227,7 @@ iD.Connection = function() {
method: 'POST',
path: '/api/0.6/changeset/' + changeset_id + '/upload',
options: { header: { 'Content-Type': 'text/xml' } },
content: JXON.stringify(connection.osmChangeJXON(user.id, changeset_id, changes))
content: JXON.stringify(connection.osmChangeJXON(changeset_id, changes))
}, function(err) {
if (err) return callback(err);
oauth.xhr({
@@ -241,21 +240,34 @@ iD.Connection = function() {
});
};
var userDetails;
connection.userDetails = function(callback) {
if (userDetails) {
callback(undefined, userDetails);
return;
}
function done(err, user_details) {
if (err) return callback(err);
var u = user_details.getElementsByTagName('user')[0],
img = u.getElementsByTagName('img'),
image_url = '';
if (img && img[0] && img[0].getAttribute('href')) {
image_url = img[0].getAttribute('href');
}
callback(undefined, connection.user({
userDetails = {
display_name: u.attributes.display_name.nodeValue,
image_url: image_url,
id: u.attributes.id.nodeValue
}).user());
};
callback(undefined, userDetails);
}
oauth.xhr({ method: 'GET', path: '/api/0.6/user/details' }, done);
};
@@ -349,12 +361,6 @@ iD.Connection = function() {
return connection;
};
connection.user = function(_) {
if (!arguments.length) return user;
user = _;
return connection;
};
connection.flush = function() {
_.forEach(inflight, abortRequest);
loadedTiles = {};
+24 -19
View File
@@ -23,8 +23,7 @@ iD.ui.Commit = function(context) {
}
function commit(selection) {
var changes = context.history().changes(),
user = context.connection().user();
var changes = context.history().changes();
function changesLength(d) { return changes[d].length; }
@@ -61,24 +60,30 @@ iD.ui.Commit = function(context) {
var saveSection = body.append('div')
.attr('class','modal-section fillL cf');
var userLink = d3.select(document.createElement('div'));
if (user.image_url) {
userLink.append('img')
.attr('src', user.image_url)
.attr('class', 'icon icon-pre-text user-icon');
}
userLink.append('a')
.attr('class','user-info')
.text(user.display_name)
.attr('href', context.connection().userURL(user.display_name))
.attr('tabindex', -1)
.attr('target', '_blank');
saveSection.append('p')
var prose = saveSection.append('p')
.attr('class', 'commit-info')
.html(t('commit.upload_explanation', {user: userLink.html()}));
.html(t('commit.upload_explanation'));
context.connection().userDetails(function(err, user) {
if (err) return;
var userLink = d3.select(document.createElement('div'));
if (user.image_url) {
userLink.append('img')
.attr('src', user.image_url)
.attr('class', 'icon icon-pre-text user-icon');
}
userLink.append('a')
.attr('class','user-info')
.text(user.display_name)
.attr('href', context.connection().userURL(user.display_name))
.attr('tabindex', -1)
.attr('target', '_blank');
prose.html(t('commit.upload_explanation_with_user', {user: userLink.html()}));
});
// Confirm Button
var saveButton = saveSection.append('button')
+4 -10
View File
@@ -9,12 +9,6 @@ describe('iD.Connection', function () {
expect(c).to.be.ok;
});
it('gets/sets user', function () {
var user = { name: 'tom' };
expect(c.user(user)).to.equal(c);
expect(c.user()).to.equal(user);
});
describe('#changesetUrl', function() {
it('provides a changeset url', function() {
expect(c.changesetURL(2)).to.eql('http://www.openstreetmap.org/browse/changeset/2');
@@ -134,7 +128,7 @@ describe('iD.Connection', function () {
describe('#osmChangeJXON', function() {
it('converts change data to JXON', function() {
var jxon = c.osmChangeJXON('jfire', '1234', {created: [], modified: [], deleted: []});
var jxon = c.osmChangeJXON('1234', {created: [], modified: [], deleted: []});
expect(jxon).to.eql({
osmChange: {
@@ -152,7 +146,7 @@ describe('iD.Connection', function () {
w = iD.Way(),
r = iD.Relation(),
changes = {created: [r, w, n], modified: [], deleted: []},
jxon = c.osmChangeJXON('jfire', '1234', changes);
jxon = c.osmChangeJXON('1234', changes);
expect(d3.entries(jxon.osmChange['create'])).to.eql([
{key: 'node', value: [n.asJXON('1234').node]},
@@ -166,7 +160,7 @@ describe('iD.Connection', function () {
w = iD.Way(),
r = iD.Relation(),
changes = {created: [], modified: [r, w, n], deleted: []},
jxon = c.osmChangeJXON('jfire', '1234', changes);
jxon = c.osmChangeJXON('1234', changes);
expect(jxon.osmChange['modify']).to.eql({
node: [n.asJXON('1234').node],
@@ -180,7 +174,7 @@ describe('iD.Connection', function () {
w = iD.Way(),
r = iD.Relation(),
changes = {created: [], modified: [], deleted: [n, w, r]},
jxon = c.osmChangeJXON('jfire', '1234', changes);
jxon = c.osmChangeJXON('1234', changes);
expect(d3.entries(jxon.osmChange['delete'])).to.eql([
{key: 'relation', value: [r.asJXON('1234').relation]},