Files
iD/modules/ui/improveOSM_header.js
SilentSpike 51efd5b714 Update and standardise QA implementations
- ES6ify (now using class syntax to define QAItem objects)
- Fix bug with KeepRight marker rendering not updating properly
- Use `qa-` prefix for the UI element classes to differentiate from iD
validation error related UI element classes
- Move away from "error" where possible in source
- Move away from snake_case naming where possible

Note that some function/method names have been untouched to make life
easier for v3 development. Have added note comments where appropriate.
2020-02-06 23:07:50 +00:00

83 lines
2.0 KiB
JavaScript

import { dataEn } from '../../data';
import { t } from '../util/locale';
export function uiImproveOsmHeader() {
let _qaItem;
function issueTitle(d) {
const unknown = t('inspector.unknown');
if (!d) return unknown;
const { issueKey } = d;
const et = dataEn.QA.improveOSM.error_types[issueKey];
if (et && et.title) {
return t(`QA.improveOSM.error_types.${issueKey}.title`);
} else {
return unknown;
}
}
function improveOsmHeader(selection) {
const header = selection.selectAll('.qa-header')
.data(
(_qaItem ? [_qaItem] : []),
d => `${d.id}-${d.status || 0}`
);
header.exit()
.remove();
const headerEnter = header.enter()
.append('div')
.attr('class', 'qa-header');
const svgEnter = headerEnter
.append('div')
.attr('class', 'qa-header-icon')
.classed('new', d => d.id < 0)
.append('svg')
.attr('width', '20px')
.attr('height', '30px')
.attr('viewbox', '0 0 20 30')
.attr('class', d => `preset-icon-28 qaItem ${d.service} itemId-${d.id} itemType-${d.itemType}`);
svgEnter
.append('polygon')
.attr('fill', 'currentColor')
.attr('class', 'qaItem-fill')
.attr('points', '16,3 4,3 1,6 1,17 4,20 7,20 10,27 13,20 16,20 19,17.033 19,6');
svgEnter
.append('use')
.attr('class', 'icon-annotation')
.attr('width', '11px')
.attr('height', '11px')
.attr('transform', 'translate(4.5, 7)')
.attr('xlink:href', d => {
const picon = d.icon;
if (!picon) {
return '';
} else {
const isMaki = /^maki-/.test(picon);
return `#${picon}${isMaki ? '-11' : ''}`;
}
});
headerEnter
.append('div')
.attr('class', 'qa-header-label')
.text(issueTitle);
}
improveOsmHeader.issue = function(val) {
if (!arguments.length) return _qaItem;
_qaItem = val;
return improveOsmHeader;
};
return improveOsmHeader;
}