displaying histograms for each country and batchcode

This commit is contained in:
frankknoll
2023-02-12 18:34:13 +01:00
parent 21118a4f35
commit baaac31f1c
4 changed files with 205 additions and 86 deletions

View File

@@ -1,7 +1,7 @@
class HistoDescrsProvider {
static getHistoDescrsForBatchcode(batchcode) {
return fetch(`data/histograms/global/${batchcode}.json`)
static getHistoDescrs(country, batchcode) {
return fetch(`data/histograms/${country}/${batchcode}.json`)
.then(response => response.json())
.then(histoDescrs => {
histoDescrs.histograms.sort((histoDescr1, histoDescr2) => histoDescr1.batchcodes.length - histoDescr2.batchcodes.length);

View File

@@ -6,17 +6,17 @@ class HistogramView {
this.#uiContainer = uiContainer
}
displayHistogramViewForBatchcode(batchcode) {
displayHistogramView(country, batchcode) {
this
.#loadHistoDescrsForBatchcode(batchcode)
.#loadHistoDescrs(country, batchcode)
.then(histoDescrs => this.#displayHistogramViewForHistoDescrs(histoDescrs));
}
#loadHistoDescrsForBatchcode(batchcode) {
#loadHistoDescrs(country, batchcode) {
const loadingText = document.createTextNode('Loading...');
this.#uiContainer.appendChild(loadingText);
return HistoDescrsProvider
.getHistoDescrsForBatchcode(batchcode)
.getHistoDescrs(country, batchcode)
.then(histoDescrs => {
loadingText.remove();
return histoDescrs;

File diff suppressed because one or more lines are too long

View File

@@ -15,11 +15,15 @@ class BatchCodeTableInitializer {
initialize() {
this.#batchCodeTable = this.#createEmptyBatchCodeTable();
this.#columnSearch = new ColumnSearch(this.#batchCodeTable.column(this.#getColumnIndex('Company')));
this.#countrySelect.addEventListener('change', event => this.#displayCountry(event.target.value));
this.#displayCountry('Global');
this.#countrySelect.addEventListener('change', event => this.#displayCountry());
this.#displayCountry();
this.#initializeHistogramView();
}
#getCountry() {
return UIUtils.getSelectedOption(this.#countrySelect).value;
}
#createEmptyBatchCodeTable() {
return this.#batchCodeTableElement.DataTable(
{
@@ -95,10 +99,10 @@ class BatchCodeTableInitializer {
}
}
#displayCountry(country) {
this.#heading.textContent = country == 'Global' ? 'Global Batch Codes' : `Batch Codes for ${country}`;
#displayCountry() {
this.#heading.textContent = this.#getCountry() == 'Global' ? 'Global Batch Codes' : `Batch Codes for ${this.#getCountry()}`;
// FK-TODO: show "Loading.." message or spinning wheel.
fetch(`data/batchCodeTables/${country}.json`)
fetch(`data/batchCodeTables/${this.#getCountry()}.json`)
.then(response => response.json())
.then(json => {
this.#_addEmptyControlColumn(json);
@@ -108,7 +112,6 @@ class BatchCodeTableInitializer {
this.#setTableRows(json.data);
this.#columnSearch.columnContentUpdated();
this.#selectInput();
this.#displayControlColumn(country == 'Global');
});
}
@@ -130,10 +133,6 @@ class BatchCodeTableInitializer {
input.select();
}
#displayControlColumn(isVisible) {
this.#batchCodeTable.column(this.#getColumnIndex('control')).visible(isVisible);
}
#initializeHistogramView() {
const thisClassInstance = this;
$(`#${this.#batchCodeTableElement[0].id} tbody`).on(
@@ -150,7 +149,7 @@ class BatchCodeTableInitializer {
row.child(uiContainer).show();
tr.addClass('shown');
const batchcode = row.data()[thisClassInstance.#getColumnIndex('Batch')];
new HistogramView(uiContainer).displayHistogramViewForBatchcode(batchcode);
new HistogramView(uiContainer).displayHistogramView(thisClassInstance.#getCountry(), batchcode);
}
});
}