starting to remove Countries from UI

This commit is contained in:
frankknoll
2023-04-02 20:14:47 +02:00
parent 578651052a
commit 3e553b9324
5 changed files with 103 additions and 130 deletions

View File

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

View File

@@ -1,5 +1,6 @@
class HistoDescrsProvider { class HistoDescrsProvider {
// FK-TODO: remove country
static getHistoDescrs(country, batchcode) { static getHistoDescrs(country, batchcode) {
return fetch(`data/histograms/${country}/${batchcode}.json`) return fetch(`data/histograms/${country}/${batchcode}.json`)
.then(response => response.json()) .then(response => response.json())

View File

@@ -6,6 +6,7 @@ class HistogramView {
this.#uiContainer = uiContainer this.#uiContainer = uiContainer
} }
// FK-TODO: remove country
displayHistogramView(country, batchcode) { displayHistogramView(country, batchcode) {
this this
.#loadHistoDescrs(country, batchcode) .#loadHistoDescrs(country, batchcode)

File diff suppressed because one or more lines are too long

View File

@@ -1,30 +1,21 @@
class BatchCodeTableInitializer { class BatchCodeTableInitializer {
#heading;
#countrySelect;
#batchCodeTableElement; #batchCodeTableElement;
#batchCodeTable; #batchCodeTable;
#columnSearch; #columnSearch;
constructor({ heading, countrySelect, batchCodeTableElement }) { constructor(batchCodeTableElement) {
this.#heading = heading;
this.#countrySelect = countrySelect;
this.#batchCodeTableElement = batchCodeTableElement; this.#batchCodeTableElement = batchCodeTableElement;
} }
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()); this.#display();
this.#displayCountry();
this.#initializeHistogramView(); this.#initializeHistogramView();
this.#trackSearchWithGoogleAnalytics(); this.#trackSearchWithGoogleAnalytics();
} }
#getCountry() {
return UIUtils.getSelectedOption(this.#countrySelect).value;
}
#createEmptyBatchCodeTable() { #createEmptyBatchCodeTable() {
return this.#batchCodeTableElement.DataTable( return this.#batchCodeTableElement.DataTable(
{ {
@@ -58,14 +49,13 @@ class BatchCodeTableInitializer {
this.#getColumnIndex('Deaths'), this.#getColumnIndex('Deaths'),
this.#getColumnIndex('Disabilities'), this.#getColumnIndex('Disabilities'),
this.#getColumnIndex('Life Threatening Illnesses'), this.#getColumnIndex('Life Threatening Illnesses'),
this.#getColumnIndex('Countries'),
this.#getColumnIndex('Severe reports'), this.#getColumnIndex('Severe reports'),
this.#getColumnIndex('Lethality') this.#getColumnIndex('Lethality')
] ]
}, },
{ {
orderable: false, orderable: false,
targets: [this.#getColumnIndex('Countries'), this.#getColumnIndex('Company')] targets: [this.#getColumnIndex('Company')]
}, },
{ {
render: (data, type, row) => { render: (data, type, row) => {
@@ -94,19 +84,16 @@ class BatchCodeTableInitializer {
return 5; return 5;
case 'Company': case 'Company':
return 6; return 6;
case 'Countries':
return 7;
case 'Severe reports': case 'Severe reports':
return 8; return 7;
case 'Lethality': case 'Lethality':
return 9; return 8;
} }
} }
#displayCountry() { #display() {
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/${this.#getCountry()}.json`) fetch(`data/batchCodeTables/Global.json`)
.then(response => response.json()) .then(response => response.json())
.then(json => { .then(json => {
this.#_addEmptyControlColumn(json); this.#_addEmptyControlColumn(json);
@@ -117,7 +104,6 @@ class BatchCodeTableInitializer {
this.#columnSearch.columnContentUpdated(); this.#columnSearch.columnContentUpdated();
this.#selectInput(); this.#selectInput();
}); });
GoogleAnalytics.countrySelected(this.#getCountry());
} }
#_addEmptyControlColumn(json) { #_addEmptyControlColumn(json) {
@@ -155,7 +141,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).displayHistogramView(thisClassInstance.#getCountry(), batchcode); new HistogramView(uiContainer).displayHistogramView('Global', batchcode);
GoogleAnalytics.click_batchcode(batchcode); GoogleAnalytics.click_batchcode(batchcode);
} }
}); });