chg: [website] delete first node of history tree

pull/592/merge
David Cruciani 2024-02-22 14:03:48 +01:00
parent 01decb1d44
commit 769f7454e2
No known key found for this signature in database
GPG Key ID: 8690CDE1E3994B9B
2 changed files with 50 additions and 20 deletions

View File

@ -134,13 +134,15 @@ def get_history_tree():
def get_history_tree_uuid(history_uuid): def get_history_tree_uuid(history_uuid):
history_tree = History_Tree.query.filter_by(session_uuid=history_uuid).first() history_tree = History_Tree.query.filter_by(session_uuid=history_uuid).first()
tree = json.loads(history_tree.tree) if history_tree:
loc_session = get_session(history_tree.session_uuid) tree = json.loads(history_tree.tree)
loc_json = loc_session.history_json() loc_session = get_session(history_tree.session_uuid)
loc_json["children"] = list() loc_json = loc_session.history_json()
for child in tree[history_tree.session_uuid]: loc_json["children"] = list()
loc_json["children"].append(util_get_history_tree(child)) for child in tree[history_tree.session_uuid]:
return loc_json loc_json["children"].append(util_get_history_tree(child))
return loc_json
return {}
def util_remove_node_session(node_uuid, parent, parent_path): 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]) return util_remove_node_session(node_uuid, child, parent_path["children"][i])
def remove_node_session(node_uuid): def remove_node_session(node_uuid):
for q in sess: keys_list = list(sess.keys())
if isUUID(q): loc = None
q_value = sess.get(q) 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: if q_value["uuid"] == node_uuid:
del sess[q] loc = i
break
else: else:
if q_value["children"]: 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) tree = json.loads(history_tree.tree)
for e in tree: for e in tree:
if e == node_uuid: if e == node_uuid:
del tree[e] db.session.delete(history_tree)
history_tree.tree = json.dumps(tree)
db.session.commit() db.session.commit()
return return
else: else:

View File

@ -36,6 +36,10 @@
</li> </li>
</ul> </ul>
</a> </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> <div>
<div class="collapse" :id="'collapse'+his.uuid" style="width: 70%; margin-left:30px"> <div class="collapse" :id="'collapse'+his.uuid" style="width: 70%; margin-left:30px">
@ -111,17 +115,35 @@
display_toast(res) 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){ async function change_tree(history_loc, key){
if(!tree_view){ if(!tree_view.value){
const res = await fetch("/get_history_session/"+history_loc.uuid) const res = await fetch("/get_history_session/"+history_loc.uuid)
let loc = await res.json() 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{ }else{
const res = await fetch("/get_history_tree/"+history_loc.uuid) const res = await fetch("/get_history_tree/"+history_loc.uuid)
let loc = await res.json() 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(() => { onMounted(() => {
@ -142,7 +164,9 @@
history, history,
tree_view, tree_view,
save_history, save_history,
change_tree change_tree,
remove_node,
remove_node_tree
} }
} }
}).mount('.container-fluid') }).mount('.container-fluid')