From 769f7454e2f0d9818e7697628ea3aa3ad5dbbd2e Mon Sep 17 00:00:00 2001 From: David Cruciani Date: Thu, 22 Feb 2024 14:03:48 +0100 Subject: [PATCH] chg: [website] delete first node of history tree --- website/app/history/history_core.py | 34 +++++++++++--------- website/app/templates/history_session.html | 36 ++++++++++++++++++---- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/website/app/history/history_core.py b/website/app/history/history_core.py index 1d92438..78c42a8 100644 --- a/website/app/history/history_core.py +++ b/website/app/history/history_core.py @@ -134,13 +134,15 @@ def get_history_tree(): def get_history_tree_uuid(history_uuid): history_tree = History_Tree.query.filter_by(session_uuid=history_uuid).first() - tree = json.loads(history_tree.tree) - loc_session = get_session(history_tree.session_uuid) - loc_json = loc_session.history_json() - loc_json["children"] = list() - for child in tree[history_tree.session_uuid]: - loc_json["children"].append(util_get_history_tree(child)) - return loc_json + if history_tree: + tree = json.loads(history_tree.tree) + loc_session = get_session(history_tree.session_uuid) + loc_json = loc_session.history_json() + loc_json["children"] = list() + for child in tree[history_tree.session_uuid]: + loc_json["children"].append(util_get_history_tree(child)) + return loc_json + return {} def util_remove_node_session(node_uuid, parent, parent_path): @@ -153,14 +155,19 @@ def util_remove_node_session(node_uuid, parent, parent_path): return util_remove_node_session(node_uuid, child, parent_path["children"][i]) def remove_node_session(node_uuid): - for q in sess: - if isUUID(q): - q_value = sess.get(q) + keys_list = list(sess.keys()) + loc = None + for i in range(0, len(keys_list)): + if isUUID(keys_list[i]): + q_value = sess.get(keys_list[i]) if q_value["uuid"] == node_uuid: - del sess[q] + loc = i + break else: if q_value["children"]: - return util_remove_node_session(node_uuid, q_value, sess[q]) + return util_remove_node_session(node_uuid, q_value, sess[keys_list[i]]) + if loc: + del sess[keys_list[i]] @@ -181,8 +188,7 @@ def remove_node_tree(node_uuid): tree = json.loads(history_tree.tree) for e in tree: if e == node_uuid: - del tree[e] - history_tree.tree = json.dumps(tree) + db.session.delete(history_tree) db.session.commit() return else: diff --git a/website/app/templates/history_session.html b/website/app/templates/history_session.html index a8acd69..d6f14fe 100644 --- a/website/app/templates/history_session.html +++ b/website/app/templates/history_session.html @@ -36,6 +36,10 @@ +
+ + +
@@ -111,17 +115,35 @@ display_toast(res) } + async function remove_node(history_loc, key){ + const res = await fetch('/history/remove_node_session/' + history_loc.uuid) + display_toast(res) + await change_tree(history_loc, key) + } + async function remove_node_tree(history_loc, key){ + const res = await fetch('/history/remove_node_tree/' + history_loc.uuid) + display_toast(res) + await change_tree(history_loc, key) + } + async function change_tree(history_loc, key){ - if(!tree_view){ + if(!tree_view.value){ const res = await fetch("/get_history_session/"+history_loc.uuid) let loc = await res.json() - history.value[key] = loc + if(!Object.keys(loc).length){ + history.value.splice(key, key+1) + }else{ + history.value[key] = loc + } }else{ const res = await fetch("/get_history_tree/"+history_loc.uuid) let loc = await res.json() - history.value[key] = loc - } - + if(!Object.keys(loc).length){ + history.value.splice(key, key+1) + }else{ + history.value[key] = loc + } + } } onMounted(() => { @@ -142,7 +164,9 @@ history, tree_view, save_history, - change_tree + change_tree, + remove_node, + remove_node_tree } } }).mount('.container-fluid')