Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
Use "location" directly instead of window.location and so on (since it
is the same).

Remove async from a function that did not need it (set_query_string_values).

Use async and await in a function that was doing it but not
idiomatically (reset_node_count, now named store_node_count). Changed
its name too for clarity (and a closer analogy to
store_node_properties).

Added some comments and removed the hardcoded "sample trees" that we
would not let modify for a user connecting remotely.
  • Loading branch information
jordibc committed Jan 15, 2025
1 parent 7993eb4 commit 6877da4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
30 changes: 15 additions & 15 deletions ete4/smartview/static/js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const view = {
key: "(dy, dx, name)",
reverse: false,
},
upload: () => window.location.href = "upload.html",
upload: () => location = "upload.html",
download: {
newick: () => download_newick(),
svg: () => download_svg(),
Expand Down Expand Up @@ -156,7 +156,7 @@ async function main() {

await init_trees();

await set_query_string_values();
set_query_string_values();

init_menus(Object.keys(trees));

Expand All @@ -166,10 +166,10 @@ async function main() {

await set_consistent_values();

reset_node_count();

init_events();

store_node_count();

store_node_properties();

draw_minimap();
Expand All @@ -179,9 +179,9 @@ async function main() {

update();

const sample_trees = [];
// NOTE: We could add here trees like "GTDB_bact_r95" to have a public
// server showing the trees but not letting modifications on them.
const sample_trees = [];
view.allow_modifications = !sample_trees.includes(view.tree);
}
catch (ex) {
Expand Down Expand Up @@ -404,15 +404,15 @@ async function on_tree_change() {
remove_tags();
view.tree_size = await api(`/trees/${get_tid()}/size`);
await set_tree_style();
reset_node_count();
store_node_count();
store_node_properties();
reset_zoom();
reset_position();
await populate_layouts();
draw_minimap();
update();

const sample_trees = ["ncbi", "GTDB_bact_r95"]; // hardcoded for the moment
const sample_trees = []; // see main()
view.allow_modifications = !sample_trees.includes(view.tree);
}

Expand Down Expand Up @@ -450,9 +450,10 @@ function reset_view() {


// Set values that have been given with the query string.
async function set_query_string_values() {
// For example, http://[...]/draw?x=1 -> view.tl.x = 1
function set_query_string_values() {
const unknown_params = [];
const params = new URLSearchParams(location.search);
const params = new URLSearchParams(location.search); // "?x=1" -> {x: 1}

for (const [param, value] of params) {
if (param === "tree")
Expand Down Expand Up @@ -514,11 +515,10 @@ function show_minimap(show) {
}


function reset_node_count() {
api(`/trees/${get_tid()}/nodecount`).then(n => {
view.nnodes = n.nnodes;
view.nleaves = n.nleaves;
});
async function store_node_count() {
const count = await api(`/trees/${get_tid()}/nodecount`);
view.nnodes = count.nnodes;
view.nleaves = count.nleaves;
}


Expand Down Expand Up @@ -577,7 +577,7 @@ function get_url_view(x, y, w, h) {
x: x, y: y, w: w, h: h,
tree: view.tree, subtree: view.subtree, shape: view.shape,
}).toString();
return window.location.origin + window.location.pathname + "?" + qs;
return location.origin + location.pathname + "?" + qs;
}


Expand Down
3 changes: 1 addition & 2 deletions ete4/smartview/static/js/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ function show_uploaded_trees(resp) {
showCancelButton: true,
}).then(result => {
if (result.isConfirmed)
window.location.href =
"gui.html?tree=" + encodeURIComponent(names[0]);
location = "gui.html?tree=" + encodeURIComponent(names[0]);
});
else
Swal.fire({html: "Could not find any tree in file.", icon: "warning"});
Expand Down

0 comments on commit 6877da4

Please sign in to comment.