Skip to content

Commit

Permalink
Added the ability to edit the contents of the metadata component tabl…
Browse files Browse the repository at this point in the history
…e along with the ability to export in .tsv format. Added a link to publications in the disclaimer.
  • Loading branch information
aldelucaizs committed May 9, 2024
1 parent ca3e5ac commit 9f07f9e
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,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-05-07</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
7 changes: 5 additions & 2 deletions js/file-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ gtiz_file_handler.parseMetadata = function(msg, lines, header_index) {
}
let meta = {};
let id_name = '';
let category = 'nothing';
let tree = gtiz_tree.tree;
let category = tree.display_category ? tree.display_category : 'nothing';
let options = {};
if (header_index) {
if (header_index.find(function(d) {return d == "ID"})) {
Expand All @@ -379,7 +380,9 @@ gtiz_file_handler.parseMetadata = function(msg, lines, header_index) {
id_name = header_index[0];
}
gtiz_file_handler.samples_column = id_name;
category = header_index.length > 1 ? header_index[1] : header_index[0];
if (category == 'nothing') {
category = header_index.length > 1 ? header_index[1] : header_index[0];
}
for (let i in header_index) {
let header = header_index[i];
options[header] = header;
Expand Down
1 change: 1 addition & 0 deletions js/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ gtiz_languages.en = {
"original_tree": "Original tree",
"pie_chart_mode": "Pie Chart mode",
"possible_performance_issues_message" : "Possible performance issues, I suggest to set link distances value to <strong>{0}</strong>.",
"publications": "Publications",
"quick_gradient": "Quick gradient",
"radius_size": "Radius size (%)",
"real_branch_length" : "Real branch length",
Expand Down
1 change: 1 addition & 0 deletions js/i18n/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ gtiz_languages.it = {
"original_tree": "Tree iniziale",
"pie_chart_mode": "Modalità diagramma",
"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",
"radius_size": "Dimensione raggio (%)",
"real_branch_length" : "Lunghezza branch reale",
Expand Down
4 changes: 3 additions & 1 deletion js/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ gtiz_languages.en = {
"original_tree": "Original tree",
"pie_chart_mode": "Pie Chart mode",
"possible_performance_issues_message" : "Possible performance issues, I suggest to set link distances value to <strong>{0}</strong>.",
"publications": "Publications",
"quick_gradient": "Quick gradient",
"radius_size": "Radius size (%)",
"real_branch_length" : "Real branch length",
Expand Down Expand Up @@ -284,7 +285,7 @@ gtiz_languages.it = {
"export_newick" : "Esporta newick",
"fetch_error" : "La richiesta di caricamento del file non è riuscita.",
"font_size" : "Dimensione carattere",
"footer_disclaimer" : "Questo progetto fa parte dell'European Joint Programme One Health EJP. Il progetto ha ricevuto finanziamenti dal programma di ricerca e innovazione Horizon 2020 dell'Unione europea nell'ambito del Grant Agreement No 773830.",
"footer_disclaimer" : "Questo progetto fa parte dell'European Joint Programme One Health EJP. Il progetto ha ricevuto finanziamenti dal programma di ricerca e innovazione Horizon 2020 dell'Unione Europea nell'ambito del Grant Agreement No 773830.",
"for_branches_longer_than" : "Per collegamenti più lunghi di:",
"forbidden_net_geojson_alert" : "Sembra che tu non abbia i permessi per accedere al GeoJson indicato nella URL. Prova a fare la login su <a href='{0}' target='_blank'>{1}</a> ed aggiorna la pagina.",
"forbidden_net_metadata_alert" : "Sembra che tu non abbia i permessi per accedere ai Metadata indicati nella URL. Prova a fare la login su <a href='{0}' target='_blank'>{1}</a> ed aggiorna la pagina.",
Expand Down Expand Up @@ -389,6 +390,7 @@ gtiz_languages.it = {
"original_tree": "Tree iniziale",
"pie_chart_mode": "Modalità diagramma",
"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",
"radius_size": "Dimensione raggio (%)",
"real_branch_length" : "Lunghezza branch reale",
Expand Down
85 changes: 81 additions & 4 deletions js/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ gtiz_metadata.context_menu = [{
function : () => {
gtiz_metadata.downloadCsv();
}
}, {
type : 'button',
label : () => {
return gtiz_locales.current.download_table + ' (.tsv)';
},
icon : 'iconic-file-text',
function : () => {
gtiz_metadata.downloadTsv();
}
}];


Expand Down Expand Up @@ -285,6 +294,33 @@ gtiz_metadata.getColorByOptions = function() {
return colors;
}

/**
* Export table as tsv
*
*
*/
gtiz_metadata.downloadTsv = function() {
let nodes = gtiz_metadata.options.api.getRenderedNodes();
let array = [];
nodes.forEach(element => {
if (element.data.nothing) {
delete element.data.nothing;
}
array.push(element.data);
});
let keys = Object.keys(array[0]);
// Create the header row
let tsv = keys.join('\t') + '\n';
// Create the data rows
for (let obj of array) {
let values = Object.values(obj);
tsv += values.join('\t') + '\n';
}
let timestamp = Date.now();
let name = "metadata" + timestamp + ".tsv";
gtiz_file_handler.saveTextAsFile(tsv, name);
}

/**
* Export table as csv
*
Expand All @@ -295,8 +331,11 @@ gtiz_metadata.downloadCsv = function() {
let columns = gtiz_metadata.options.columnApi.getColumns();
// we are removing first column dedicated to checkbox
columns.shift();
let timestamp = Date.now();
let name = "metadata" + timestamp + ".csv";
gtiz_metadata.options.api.exportDataAsCsv({
columnKeys: columns
columnKeys: columns,
fileName: name
});
}

Expand Down Expand Up @@ -467,6 +506,44 @@ gtiz_metadata.options = {
doesExternalFilterPass: (node) => {
let filtered = gtiz_metadata.doesExternalFilterPass(node);
return filtered;
},
onCellValueChanged: (event) => {
console.log(event);

let nodes = gtiz_metadata.options.api.getRenderedNodes();
let array = [];
nodes.forEach(element => {
if (element.data.nothing) {
delete element.data.nothing;
}
array.push(element.data);
});
let keys = Object.keys(array[0]);
// Create the header row
let tsv = keys.join('\t') + '\n';
// Create the data rows
for (let obj of array) {
let values = Object.values(obj);
tsv += values.join('\t') + '\n';
}

gtiz_tree.current_metadata_file = tsv;
if (gtiz_tree.tree) {
let l_action = 'add';
let l_components = ['tree', 'map', 'legend'];
gtiz_layout.uiLoadingManager(l_components, l_action);
gtiz_file_handler.loadMetadataText(tsv);
gtiz_map.init();
} else {
let title = gtiz_locales.current.oops;
let contents = [];
let body = document.createElement('div');
body.innerHTML = gtiz_locales.current.missing_tree_alert;
contents.push(body);
gtiz_modal.buildModal(title, contents);
console.log(gtiz_locales.current.missing_tree_alert);
}

}
};

Expand Down Expand Up @@ -494,15 +571,15 @@ gtiz_metadata.setGrid = function() {
columns.push(check);
Object.keys(fields).forEach((key, index) => {
if (fields[key] != 'nothing') {
let check = fields[key] == 'ID' ? true : false;
let obj = {};
if (check) {
if (fields[key] == 'ID' || fields[key] == gtiz_file_handler.samples_column) {
obj = {
field : fields[key]
}
} else {
obj = {
field : fields[key]
field : fields[key],
editable: true
}
}
columns.push(obj);
Expand Down
1 change: 1 addition & 0 deletions themes/cohesive/html/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div class="useful useful-links">
<h6 data-i18n-key="useful_links">Useful links</h6>
<ul>
<li><a href="https://github.com/genpat-it/spread/wiki/Publications" target="_blank" data-i18n-key="publications">Publications</a></li>
<li><a href="https://onehealthejp.eu/">One Heakth EJP</a></li>
<li><a href="https://www.izs.it/IZS/Eccellenza/Centri_nazionali/CRN_-_Sequenze_Genomiche" target="_blank"><span data-i18n-key="crn_genome_sequencing">CRN Genome Sequencing</span></a></li>
<li><a href="https://github.com/achtman-lab/GrapeTree" target="_blank">GrapeTree Github</a></li>
Expand Down
1 change: 1 addition & 0 deletions themes/default/html/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<div class="useful useful-links">
<h6 data-i18n-key="useful_links">Useful links</h6>
<ul>
<li><a href="https://github.com/genpat-it/spread/wiki/Publications" target="_blank" data-i18n-key="publications">Publications</a></li>
<li><a href="https://github.com/achtman-lab/GrapeTree" target="_blank">GrapeTree Github</a></li>
<li><a href="https://www.izs.it/IZS/Eccellenza/Centri_nazionali/CRN_-_Sequenze_Genomiche" target="_blank"><span data-i18n-key="crn_genome_sequencing">CRN Genome Sequencing</span></a></li>
<li><a href="https://www.izs.it/IZS/" target="_blank">IZSAM 'G. Caporale'</a></li>
Expand Down
1 change: 1 addition & 0 deletions themes/genpat/html/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<div class="useful useful-links">
<h6 data-i18n-key="useful_links">Useful links</h6>
<ul>
<li><a href="https://github.com/genpat-it/spread/wiki/Publications" target="_blank" data-i18n-key="publications">Publications</a></li>
<li><a href="https://github.com/achtman-lab/GrapeTree" target="_blank">GrapeTree Github</a></li>
<li><a href="https://www.izs.it/IZS/Eccellenza/Centri_nazionali/CRN_-_Sequenze_Genomiche" target="_blank"><span data-i18n-key="crn_genome_sequencing">CRN Genome Sequencing</span></a></li>
<li><a href="https://www.izs.it/IZS/" target="_blank">IZSAM "G. Caporale"</a></li>
Expand Down

0 comments on commit 9f07f9e

Please sign in to comment.