Skip to content

Commit

Permalink
chg: [website] delete first node of history tree
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCruciani committed Feb 22, 2024
1 parent 01decb1 commit 769f745
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
34 changes: 20 additions & 14 deletions website/app/history/history_core.py
Expand Up @@ -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):
Expand All @@ -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]]



Expand All @@ -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:
Expand Down
36 changes: 30 additions & 6 deletions website/app/templates/history_session.html
Expand Up @@ -36,6 +36,10 @@ <h5 style="color: brown"><u>Modules</u></h5>
</li>
</ul>
</a>
<div style="display: flex; align-items: center; margin-left: 3px">
<button v-if="!tree_view" class="btn btn-danger btn-sm" title="Remove this node" @click="remove_node(his, key)"><i class="fa-solid fa-trash"></i></button>
<button v-else class="btn btn-danger btn-sm" title="Remove this node" @click="remove_node_tree(his, key)"><i class="fa-solid fa-trash"></i></button>
</div>
</div>
<div>
<div class="collapse" :id="'collapse'+his.uuid" style="width: 70%; margin-left:30px">
Expand Down Expand Up @@ -111,17 +115,35 @@ <h5 class="mb-1">[[his.query]]</h5>
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(() => {
Expand All @@ -142,7 +164,9 @@ <h5 class="mb-1">[[his.query]]</h5>
history,
tree_view,
save_history,
change_tree
change_tree,
remove_node,
remove_node_tree
}
}
}).mount('.container-fluid')
Expand Down

0 comments on commit 769f745

Please sign in to comment.