mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 17:52:55 +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
52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
import * as d3 from 'd3';
|
|
import { t } from '../util/locale';
|
|
import { svgIcon } from '../svg/index';
|
|
|
|
|
|
export function uiStatus(context) {
|
|
var osm = context.connection();
|
|
|
|
|
|
return function(selection) {
|
|
if (!osm) return;
|
|
|
|
function update() {
|
|
osm.status(function(err, apiStatus) {
|
|
selection.html('');
|
|
|
|
if (err) {
|
|
if (apiStatus === 'rateLimited') {
|
|
selection
|
|
.text(t('status.rateLimit'))
|
|
.append('a')
|
|
.attr('class', 'api-status-login')
|
|
.attr('target', '_blank')
|
|
.call(svgIcon('#icon-out-link', 'inline'))
|
|
.append('span')
|
|
.text(t('login'))
|
|
.on('click.login', function() {
|
|
d3.event.preventDefault();
|
|
osm.authenticate();
|
|
});
|
|
} else {
|
|
// TODO: nice messages for different error types
|
|
selection.text(t('status.error'));
|
|
}
|
|
|
|
} else if (apiStatus === 'readonly') {
|
|
selection.text(t('status.readonly'));
|
|
} else if (apiStatus === 'offline') {
|
|
selection.text(t('status.offline'));
|
|
}
|
|
|
|
selection.attr('class', 'api-status ' + (err ? 'error' : apiStatus));
|
|
});
|
|
}
|
|
|
|
osm.on('change', function() { update(selection); });
|
|
|
|
window.setInterval(update, 90000);
|
|
update(selection);
|
|
};
|
|
}
|