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

View File

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

File diff suppressed because one or more lines are too long

View File

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