Skip to content

Commit

Permalink
Added missing notifiers in file handler. Implemented functions to rep…
Browse files Browse the repository at this point in the history
…lace commas with dots in latitude and longitude values from metadata, with an alert message for potential display issues.
  • Loading branch information
aldelucaizs committed Nov 13, 2024
1 parent 5d35695 commit 99b676b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 13 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ <h3 class="card-title" data-i18n-key="legend">Legend</h3>
<div class="footer-info">
<div class="info">
<p><span data-i18n-key="cookies_notice">Questa applicazione non utilizza cookies.</span></p>
<p><span data-i18n-key="last_updated_on">Last updated on</span> <span class="last-update-date">2024-11-11</span></p>
<p><span data-i18n-key="last_updated_on">Last updated on</span> <span class="last-update-date">__LAST_UPDATE__</span></p>
<p class="copyright">&copy; <span class="copyright-year"></span> IZSAM 'G. Caporale'</p>
</div>
</div>
Expand Down
71 changes: 60 additions & 11 deletions js/file-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,26 @@ gtiz_file_handler.Meta2GeoJSON = {

addNewPoint: function (geoJson, h) { // id,x,y
if (h == undefined || h.id == undefined || h.id.length == 0) {
return
};
return;
}
if (h.x.includes(',')) {
h.x = h.x.replace(',', '.');
if (!this.lonCommaAlert) {
this.lonCommaAlert = true;
}
}
if (h.y.includes(',')) {
h.y = h.y.replace(',', '.');
if (!this.latCommaAlert) {
this.latCommaAlert = true;
}
}
h.x = Number.parseFloat(h.x);
h.y = Number.parseFloat(h.y);
if (Number.isNaN(h.x) || Number.isNaN(h.y)) {
console.log('Meta2GeoJSON.addNewPoint: lat lon not a number. lon:' + h.x + ' lat:' + h.y);
return
};
return;
}
geoJson.features.push(this.newPoint(h));
},

Expand Down Expand Up @@ -252,7 +264,6 @@ gtiz_file_handler.getData = async function (url) {
return obj;
} else {
let text = gtiz_locales.current.fetch_error + " Status: " + response.status + ". Url: " + "<span class=\"notifier-response-url\">" + url + "</span>";
console.log(text);
let obj = {
text: text,
error: true,
Expand Down Expand Up @@ -392,7 +403,15 @@ gtiz_file_handler.parseMetadata = function(msg, lines, header_index) {
options[header] = header;
}
} else {
console.log('WARNING! Header index not defined.');
console.log(gtiz_locales.current.header_index_warning);
let title = '<i class="iconic iconic-warning-triangle"></i> ' + gtiz_locales.current.oops;
let contents = [];
let content = document.createElement('p');
content.innerHTML = gtiz_locales.current.metadata_file_generic_problem;
contents.push(content);
let feedback = '<p>' + gtiz_locales.current.header_index_warning + '</p>';
let f_type = 'warning';
gtiz_modal.buildNotifier(title, contents, feedback, f_type);
}
if (lines && typeof lines == 'object') {
lines.forEach((line) => {
Expand Down Expand Up @@ -420,9 +439,27 @@ gtiz_file_handler.parseMetadata = function(msg, lines, header_index) {
if (gtiz_file_handler.Meta2GeoJSON.checkMeta4geo(options) ) { //options = hash of metadata titles
let geoJ = gtiz_file_handler.Meta2GeoJSON.meta2GeoJson(meta);
gtiz_map.setMetaGeoJSON(geoJ);
if (gtiz_file_handler.Meta2GeoJSON.latCommaAlert || gtiz_file_handler.Meta2GeoJSON.lonCommaAlert) {
let title = '<i class="iconic iconic-information"></i> ' + gtiz_locales.current.please_note;
let contents = [];
let content = document.createElement('p');
content.innerHTML = gtiz_locales.current.lon_lat_comma_alert;
contents.push(content);
let feedback = '<p>' + gtiz_locales.current.lon_lat_comma_alert_feedback + '</p>';
let f_type = 'info';
gtiz_modal.buildNotifier(title, contents, feedback, f_type);
}
} else {
let message = '(GEO)WARNING: titles not found in metadata:' + gtiz_file_handler.Meta2GeoJSON.xName +', '+ gtiz_file_handler.Meta2GeoJSON.yName;
console.log(message);
let title = '<i class="iconic iconic-warning-triangle"></i> ' + gtiz_locales.current.oops;
let contents = [];
let content = document.createElement('p');
content.innerHTML = gtiz_locales.current.metadata_file_generic_problem;
contents.push(content);
let feedback = '<p>' + message + '</p>';
let f_type = 'warning';
gtiz_modal.buildNotifier(title, contents, feedback, f_type);
}
gtiz_tree.tree.changeCategory(category);
gtiz_tree.tree.setNodeText(category);
Expand Down Expand Up @@ -671,10 +708,16 @@ gtiz_file_handler.dropFiles = function(div) {
}

gtiz_file_handler.loadFailed = function(msg) {
// open modal to show loadFailed
console.log('-------------------------');
console.log('Load failed:');
console.log(msg);
// open modal to show loadFailed message
console.log(gtiz_locales.current.load_failed + ': '+ msg);
let title = '<i class="iconic iconic-warning-triangle"></i> ' + gtiz_locales.current.oops;
let contents = [];
let content = document.createElement('p');
content.innerHTML = gtiz_locales.current.load_failed;
contents.push(content);
let feedback = '<p>' + msg + '</p>';
let f_type = 'info';
gtiz_modal.buildNotifier(title, contents, feedback, f_type);
}

/**
Expand Down Expand Up @@ -906,7 +949,13 @@ gtiz_file_handler.saveGrapeTreeAsJson = function() {
feedback.classList.add('show');
}
} else {
console.log('Oops! I was unable to get SPREAD as object.');
console.log(gtiz_locales.current.unable_to_get_spread);
let title = '<i class="iconic iconic-warning-triangle"></i> ' + gtiz_locales.current.oops;
let contents = [];
let content = document.createElement('p');
content.innerHTML = gtiz_locales.current.unable_to_get_spread;
contents.push(content);
gtiz_modal.buildNotifier(title, contents);
}
}

Expand Down
6 changes: 6 additions & 0 deletions js/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ gtiz_languages.en = {
"grapetree": "GrapeTree",
"grapetree_tools": "GrapeTree tools",
"group_order": "Group order",
"header_index_warning": "WARNING! Header index not defined.",
"heat_map_mode": "Heatmap mode",
"help": "Help",
"helps": {
Expand Down Expand Up @@ -129,10 +130,13 @@ gtiz_languages.en = {
"list_view": "List view",
"load_cluster": "Load cluster",
"load_cluster_in_new_tab": "Load in new tab",
"load_failed": "Load failed",
"load_grapetree": "Load GrapeTree",
"load_spread": "Load SPREAD",
"load_tree": "Load tree",
"log_scale" : "Log scale",
"lon_lat_comma_alert": "Some latitude and/or longitude values provided in the metadata contain a comma instead of a dot and have been corrected.",
"lon_lat_comma_alert_feedback": "This change may cause issues with map display.",
"m_upload_file_label": "Upload .json, .nwk or .tsv file...",
"malformed_metadata_file_msg": "It seems metatada file is malformed.",
"map": "Map",
Expand Down Expand Up @@ -171,6 +175,7 @@ gtiz_languages.en = {
"oops_forbidden_http": "Oops! Permission denied.",
"original_tree": "Original tree",
"pie_chart_mode": "Pie Chart mode",
"please_note": "Please note",
"possible_performance_issues_message" : "Possible performance issues, I suggest to set link distances value to <strong>{0}</strong>.",
"publications": "Publications",
"quick_gradient": "Quick gradient",
Expand Down Expand Up @@ -239,6 +244,7 @@ gtiz_languages.en = {
"thresholds_not_found_in_metadata" : "Thresholds not found in metadata.",
"tree_layout": "Tree layout",
"tree_tools": "Tree tools",
"unable_to_get_spread": "I was unable to get SPREAD as object.",
"unreal_branch_length" : "Unreal branch length",
"upload": "Upload",
"use_current_settings": "Use current settings",
Expand Down
6 changes: 6 additions & 0 deletions js/i18n/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ gtiz_languages.it = {
"grapetree": "GrapeTree",
"grapetree_tools": "Strumenti GrapeTree",
"group_order": "Ordine gruppo",
"header_index_warning": "Attenzione! Indice in intestazione non definito.",
"heat_map_mode": "Modalità heatmap",
"help": "Aiuto",
"helps": {
Expand Down Expand Up @@ -129,10 +130,13 @@ gtiz_languages.it = {
"list_view": "Modalità lista",
"load_cluster": "Carica cluster",
"load_cluster_in_new_tab": "Apri in nuova scheda",
"load_failed": "Caricamento fallito",
"load_grapetree": "Carica GrapeTree",
"load_spread": "Carica SPREAD",
"load_tree": "Carica albero",
"log_scale" : "Scala logaritmica",
"lon_lat_comma_alert": "Alcuni valori di latitudine e/o longitudine forniti con i metadati contengono una virgola anziché un punto e sono stati corretti.",
"lon_lat_comma_alert_feedback": "Questa modifica potrebbe causare problemi nella visualizzazione della mappa.",
"m_upload_file_label": "Carica un file .json, .nwk o .tsv..",
"malformed_metadata_file_msg": "Sembra che il file dei metadati non sia ben formato.",
"map": "Mappa",
Expand Down Expand Up @@ -171,6 +175,7 @@ gtiz_languages.it = {
"oops_forbidden_http": "Ops! Permesso negato.",
"original_tree": "Tree iniziale",
"pie_chart_mode": "Modalità diagramma",
"please_note": "Nota bene",
"possible_performance_issues_message" : "Potresti avere problemi di performance visualizzando il tree esteso. Suggerisco di impostare la distanza dei collegamenti su <strong>{0}</strong>.",
"publications": "Pubblicazioni",
"quick_gradient": "Gradiente veloce",
Expand Down Expand Up @@ -239,6 +244,7 @@ gtiz_languages.it = {
"thresholds_not_found_in_metadata" : "Soglie non trovate nei metadati.",
"tree_layout": "Tree layout",
"tree_tools": "Strumenti albero",
"unable_to_get_spread": "Non sono stato in grado di ottenere SPREAD come oggetto.",
"unreal_branch_length" : "Lunghezza branch non reale",
"upload": "Carica",
"use_current_settings": "Usa impostazioni correnti",
Expand Down
6 changes: 6 additions & 0 deletions js/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ gtiz_languages.en = {
"grapetree": "GrapeTree",
"grapetree_tools": "GrapeTree tools",
"group_order": "Group order",
"header_index_warning": "WARNING! Header index not defined.",
"heat_map_mode": "Heatmap mode",
"help": "Help",
"helps": {
Expand Down Expand Up @@ -134,6 +135,7 @@ gtiz_languages.en = {
"list_view": "List view",
"load_cluster": "Load cluster",
"load_cluster_in_new_tab": "Load in new tab",
"load_failed": "Load failed",
"load_grapetree": "Load GrapeTree",
"load_spread": "Load SPREAD",
"load_tree": "Load tree",
Expand Down Expand Up @@ -244,6 +246,7 @@ gtiz_languages.en = {
"thresholds_not_found_in_metadata" : "Thresholds not found in metadata.",
"tree_layout": "Tree layout",
"tree_tools": "Tree tools",
"unable_to_get_spread": "I was unable to get SPREAD as object.",
"unreal_branch_length" : "Unreal branch length",
"upload": "Upload",
"use_current_settings": "Use current settings",
Expand Down Expand Up @@ -348,6 +351,7 @@ gtiz_languages.it = {
"grapetree": "GrapeTree",
"grapetree_tools": "Strumenti GrapeTree",
"group_order": "Ordine gruppo",
"header_index_warning": "Attenzione! Indice in intestazione non definito.",
"heat_map_mode": "Modalità heatmap",
"help": "Aiuto",
"helps": {
Expand Down Expand Up @@ -398,6 +402,7 @@ gtiz_languages.it = {
"list_view": "Modalità lista",
"load_cluster": "Carica cluster",
"load_cluster_in_new_tab": "Apri in nuova scheda",
"load_failed": "Caricamento fallito",
"load_grapetree": "Carica GrapeTree",
"load_spread": "Carica SPREAD",
"load_tree": "Carica albero",
Expand Down Expand Up @@ -508,6 +513,7 @@ gtiz_languages.it = {
"thresholds_not_found_in_metadata" : "Soglie non trovate nei metadati.",
"tree_layout": "Tree layout",
"tree_tools": "Strumenti albero",
"unable_to_get_spread": "Non sono stato in grado di ottenere SPREAD come oggetto.",
"unreal_branch_length" : "Lunghezza branch non reale",
"upload": "Carica",
"use_current_settings": "Usa impostazioni correnti",
Expand Down
2 changes: 1 addition & 1 deletion js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ gtiz_modal.buildComponentNotifier = function(component, id, title, contents, act
* @param {String} title Modal title
* @param {Array} contents Array of html modal contents
* @param {DOM Node} feedback System feedback for users
* @param {String} f_type Feedback type to assign as class `info` | to be defined
* @param {String} f_type Feedback type to assign as class `info` || `warning` || to be defined
*/
gtiz_modal.buildNotifier = function(title, contents, feedback, f_type) {
let notifier = document.querySelector('.notifier');
Expand Down

0 comments on commit 99b676b

Please sign in to comment.