Merge branch 'remove-countries-from-UI' into pages

This commit is contained in:
frankknoll
2023-04-03 01:21:20 +02:00
21 changed files with 160 additions and 369 deletions

View File

@@ -1,34 +1,22 @@
class GoogleAnalytics {
static click_batchcode(batchcode) {
gtag(
'event',
'click_batchcode',
{
'batchcode': batchcode
});
// FK-TODO: uncomment
// gtag(
// 'event',
// 'click_batchcode',
// {
// 'batchcode': batchcode
// });
}
static view_search_results(search_term) {
gtag(
'event',
'view_search_results',
{
'search_term': search_term
});
}
static countrySelected(country) {
gtag(
"event",
"select_item",
{
item_list_id: "countrySelect",
items: [
{
item_id: country,
}
]
});
// FK-TODO: uncomment
// gtag(
// 'event',
// 'view_search_results',
// {
// 'search_term': search_term
// });
}
}

View File

@@ -1,7 +1,7 @@
class HistoDescrsProvider {
static getHistoDescrs(country, batchcode) {
return fetch(`data/histograms/${country}/${batchcode}.json`)
static getHistoDescrs(batchcode) {
return fetch(`data/histograms/Global/${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
}
displayHistogramView(country, batchcode) {
displayHistogramView(batchcode) {
this
.#loadHistoDescrs(country, batchcode)
.#loadHistoDescrs(batchcode)
.then(histoDescrs => this.#displayHistogramViewForHistoDescrs(histoDescrs));
}
#loadHistoDescrs(country, batchcode) {
#loadHistoDescrs(batchcode) {
const loadingText = document.createTextNode('Loading...');
this.#uiContainer.appendChild(loadingText);
return HistoDescrsProvider
.getHistoDescrs(country, batchcode)
.getHistoDescrs(batchcode)
.then(histoDescrs => {
loadingText.remove();
return histoDescrs;

File diff suppressed because one or more lines are too long

View File

@@ -1,30 +1,21 @@
class BatchCodeTableInitializer {
#heading;
#countrySelect;
#batchCodeTableElement;
#batchCodeTable;
#columnSearch;
constructor({ heading, countrySelect, batchCodeTableElement }) {
this.#heading = heading;
this.#countrySelect = countrySelect;
constructor(batchCodeTableElement) {
this.#batchCodeTableElement = batchCodeTableElement;
}
initialize() {
this.#batchCodeTable = this.#createEmptyBatchCodeTable();
this.#columnSearch = new ColumnSearch(this.#batchCodeTable.column(this.#getColumnIndex('Company')));
this.#countrySelect.addEventListener('change', event => this.#displayCountry());
this.#displayCountry();
this.#display();
this.#initializeHistogramView();
this.#trackSearchWithGoogleAnalytics();
}
#getCountry() {
return UIUtils.getSelectedOption(this.#countrySelect).value;
}
#createEmptyBatchCodeTable() {
return this.#batchCodeTableElement.DataTable(
{
@@ -58,14 +49,13 @@ class BatchCodeTableInitializer {
this.#getColumnIndex('Deaths'),
this.#getColumnIndex('Disabilities'),
this.#getColumnIndex('Life Threatening Illnesses'),
this.#getColumnIndex('Countries'),
this.#getColumnIndex('Severe reports'),
this.#getColumnIndex('Lethality')
]
},
{
orderable: false,
targets: [this.#getColumnIndex('Countries'), this.#getColumnIndex('Company')]
targets: [this.#getColumnIndex('Company')]
},
{
render: (data, type, row) => {
@@ -94,19 +84,16 @@ class BatchCodeTableInitializer {
return 5;
case 'Company':
return 6;
case 'Countries':
return 7;
case 'Severe reports':
return 8;
return 7;
case 'Lethality':
return 9;
return 8;
}
}
#displayCountry() {
this.#heading.textContent = this.#getCountry() == 'Global' ? 'Global Batch Codes' : `Batch Codes for ${this.#getCountry()}`;
#display() {
// FK-TODO: show "Loading.." message or spinning wheel.
fetch(`data/batchCodeTables/${this.#getCountry()}.json`)
fetch(`data/batchCodeTables/Global.json`)
.then(response => response.json())
.then(json => {
this.#_addEmptyControlColumn(json);
@@ -117,7 +104,6 @@ class BatchCodeTableInitializer {
this.#columnSearch.columnContentUpdated();
this.#selectInput();
});
GoogleAnalytics.countrySelected(this.#getCountry());
}
#_addEmptyControlColumn(json) {
@@ -155,7 +141,7 @@ class BatchCodeTableInitializer {
row.child(uiContainer).show();
tr.addClass('shown');
const batchcode = row.data()[thisClassInstance.#getColumnIndex('Batch')];
new HistogramView(uiContainer).displayHistogramView(thisClassInstance.#getCountry(), batchcode);
new HistogramView(uiContainer).displayHistogramView(batchcode);
GoogleAnalytics.click_batchcode(batchcode);
}
});

File diff suppressed because one or more lines are too long