Files
iD/modules/ui/account.js
Bryan Housel 99a3741b0c Better isolation of services, to avoid hitting network during test runs
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
2017-08-09 22:04:09 -04:00

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);
}
};
}