Files
HowBadIsMyBatch/docs/BatchcodeCombinationSelection.js
frankknoll 630a2879fa refactoring
2023-04-15 22:26:42 +02:00

30 lines
1.2 KiB
JavaScript

class BatchcodeCombinationSelection {
static configureSelectBatchcodeCombinationElement({ selectBatchcodeCombinationElement, histograms, onSelect }) {
const batchcodesSelect = selectBatchcodeCombinationElement.querySelector('#batchcodesSelect');
this.#setBatchcodeCombinationOptions(batchcodesSelect, histograms);
batchcodesSelect.addEventListener(
'change',
event => {
const histoDescr = histograms[event.target.value];
onSelect(histoDescr);
});
onSelect(histograms[0]);
}
static #setBatchcodeCombinationOptions(batchcodesSelect, histograms) {
UIUtils.clear(batchcodesSelect);
this.#getBatchcodeCombinationOptions(histograms).forEach(option => batchcodesSelect.add(option));
}
static #getBatchcodeCombinationOptions(histograms) {
return histograms.map(this.#getBatchcodeCombinationOption);
}
static #getBatchcodeCombinationOption(histoDescr, index) {
const option = document.createElement("option");
option.text = histoDescr.batchcodes.join(', ');
option.value = index;
return option;
}
}