mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
1. All services are disabled in testing now to prevent network accesses 2. Only services are enabled when needed to test something 3. Many changes throughout code to allow iD to run with services disabled (e.g. check for osm service instead of assuming context.connection() will work) 4. Actually export the services so we can disable and enable them
78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
import * as d3 from 'd3';
|
|
import { t } from '../util/locale';
|
|
import { svgIcon } from '../svg/index';
|
|
|
|
|
|
export function uiAccount(context) {
|
|
var osm = context.connection();
|
|
|
|
|
|
function update(selection) {
|
|
if (!osm) return;
|
|
|
|
if (!osm.authenticated()) {
|
|
selection.selectAll('#userLink, #logoutLink')
|
|
.classed('hide', true);
|
|
return;
|
|
}
|
|
|
|
osm.userDetails(function(err, details) {
|
|
var userLink = selection.select('#userLink'),
|
|
logoutLink = selection.select('#logoutLink');
|
|
|
|
userLink.html('');
|
|
logoutLink.html('');
|
|
|
|
if (err) return;
|
|
|
|
selection.selectAll('#userLink, #logoutLink')
|
|
.classed('hide', false);
|
|
|
|
// Link
|
|
userLink.append('a')
|
|
.attr('href', osm.userURL(details.display_name))
|
|
.attr('target', '_blank');
|
|
|
|
// Add thumbnail or dont
|
|
if (details.image_url) {
|
|
userLink.append('img')
|
|
.attr('class', 'icon pre-text user-icon')
|
|
.attr('src', details.image_url);
|
|
} else {
|
|
userLink
|
|
.call(svgIcon('#icon-avatar', 'pre-text light'));
|
|
}
|
|
|
|
// Add user name
|
|
userLink.append('span')
|
|
.attr('class', 'label')
|
|
.text(details.display_name);
|
|
|
|
logoutLink.append('a')
|
|
.attr('class', 'logout')
|
|
.attr('href', '#')
|
|
.text(t('logout'))
|
|
.on('click.logout', function() {
|
|
d3.event.preventDefault();
|
|
osm.logout();
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
return function(selection) {
|
|
selection.append('li')
|
|
.attr('id', 'logoutLink')
|
|
.classed('hide', true);
|
|
|
|
selection.append('li')
|
|
.attr('id', 'userLink')
|
|
.classed('hide', true);
|
|
|
|
if (osm) {
|
|
osm.on('change.account', function() { update(selection); });
|
|
update(selection);
|
|
}
|
|
};
|
|
}
|