add: [website] delete node history tree

main v2.4.185
David Cruciani 2024-02-16 15:47:53 +01:00
parent 814e0ffbc3
commit 8932741c90
No known key found for this signature in database
GPG Key ID: 8690CDE1E3994B9B
4 changed files with 158 additions and 10 deletions

View File

@ -50,4 +50,30 @@ def get_history_tree():
histories = HistoryModel.get_history_tree()
if histories:
return histories
return {}
return {}
@history_blueprint.route("/get_history_tree/<sid>", methods=["GET"])
def get_history_tree_uuid(sid):
"""Get all history"""
histories = HistoryModel.get_history_tree_uuid(sid)
if histories:
return histories
return {}
@history_blueprint.route("/get_history_session/<sid>", methods=["GET"])
def get_history_session_uuid(sid):
"""Get all history"""
histories = HistoryModel.get_history_session_uuid(sid)
if histories:
return histories
return {}
@history_blueprint.route("/history/remove_node_session/<sid>", methods=["GET"])
def remove_node_session(sid):
HistoryModel.remove_node_session(sid)
return {"message": "Node deleted", "toast_class": "success-subtle"}
@history_blueprint.route("/history/remove_node_tree/<sid>", methods=["GET"])
def remove_node_tree(sid):
HistoryModel.remove_node_tree(sid)
return {"message": "Node deleted", "toast_class": "success-subtle"}

View File

@ -44,6 +44,17 @@ def get_history_session():
return loc_list
def get_history_session_uuid(history_uuid):
for q in sess:
if isUUID(q):
# If query have no children then don't display it
q_value = sess.get(q)
if q == history_uuid:
return q_value
return {}
def util_save_history(session):
@ -110,3 +121,65 @@ def get_history_tree():
loc_json["children"].append(util_get_history_tree(child))
loc_dict.append(loc_json)
return loc_dict
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
def util_remove_node_session(node_uuid, parent, parent_path):
for i in range(0, len(parent["children"])):
child = parent["children"][i]
if child["uuid"] == node_uuid:
del parent_path["children"][i]
return
elif child["children"]:
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)
if q_value["uuid"] == node_uuid:
del sess[q]
else:
if q_value["children"]:
return util_remove_node_session(node_uuid, q_value, sess[q])
def util_remove_node_tree(node_uuid, parent, parent_path):
for i in range(0, len(parent)):
child = parent[i]
for key in child:
if key == node_uuid:
del parent_path[i]
return
elif parent[i][key]:
return util_remove_node_tree(node_uuid, parent[i][key], parent[i][key])
def remove_node_tree(node_uuid):
histories_tree = History_Tree.query.order_by(desc(History_Tree.id))
for history_tree in histories_tree:
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.commit()
return
else:
if tree[e]:
util_remove_node_tree(node_uuid, tree[e], tree[e])
history_tree.tree = json.dumps(tree)
db.session.commit()
return

View File

@ -1,20 +1,51 @@
import {display_toast} from './toaster.js'
export default {
name: "History_view",
delimiters: ['[[', ']]'],
props: {
history: Object,
key_loop: Number
key_loop: Number,
tree_view: Boolean
},
emits: ['delete_node'],
setup(props, {emit}) {
async function remove_node(history_uuid){
const res = await fetch('/history/remove_node_session/' + history_uuid)
display_toast(res)
emit('delete_node', true)
}
async function remove_node_tree(history_uuid){
const res = await fetch('/history/remove_node_tree/' + history_uuid)
display_toast(res)
emit('delete_node', true)
}
return {
remove_node,
remove_node_tree,
emit
}
},
template: `
<div style="display: flex;">
<div style="list-style-type: none; padding: 10px; font-size: large; margin-left: 13px" >
<a v-if="'children' in history && history['children'].length" data-bs-toggle="collapse" style="color: black;" :href="'#collapseChild-'+history.uuid" role="button" aria-expanded="true" :aria-controls="'collapseChild-'+history.uuid">
<div style="list-style-type: none; padding: 10px; font-size: large; margin-left: 13px">
<a v-if="'children' in history && history['children'].length"
data-bs-toggle="collapse" style="color: black;"
:href="'#collapseChild-'+history.uuid"
role="button" aria-expanded="true"
:aria-controls="'collapseChild-'+history.uuid">
<i class="fa-solid fa-caret-down"></i>
</a>
</div>
<a style="text-decoration: none; color: black;" data-bs-toggle="collapse" :href="'#collapse'+history.uuid" role="button" aria-expanded="false" :aria-controls="'collapse'+history.uuid">
<a style="text-decoration: none; color: black;"
data-bs-toggle="collapse"
:href="'#collapse'+history.uuid"
role="button"
aria-expanded="false"
:aria-controls="'collapse'+history.uuid">
<ul class="list-group list-group-horizontal" style="padding-top: 5px;">
<li class="list-group-item">
<h5>[[history.query]]</h5>
@ -27,8 +58,12 @@ export default {
<h5 style="color: brown"><u>Modules</u></h5>
<template v-for="module in history.modules">[[module]],</template>
</li>
</ul
</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(history.uuid)"><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(history.uuid)"><i class="fa-solid fa-trash"></i></button>
</div>
</div>
<div>
<div class="collapse" :id="'collapse'+history.uuid" style="width: 70%; margin-left: 30px">
@ -57,7 +92,7 @@ export default {
<li>
<div class="card-body">
<template v-for="h, key in history['children']">
<history_view :history="h" :key_loop="key" />
<history_view :history="h" :key_loop="key" :tree_view="tree_view" @delete_node="(msg) => emit('delete_node', msg)"/>
</template>
</div>
</li>

View File

@ -63,8 +63,8 @@
<ul style="list-style-type: none;">
<li>
<div class="card-body">
<template v-for="h, key in his['children']">
<history_view :history="h" :key_loop="key" />
<template v-for="h, key_loop in his['children']">
<history_view :history="h" :key_loop="key_loop" :tree_view="tree_view" @delete_node="(msg) => change_tree(his, key)"/>
</template>
</div>
</li>
@ -111,6 +111,19 @@
display_toast(res)
}
async function change_tree(history_loc, key){
if(!tree_view){
const res = await fetch("/get_history_session/"+history_loc.uuid)
let loc = await res.json()
history.value[key] = loc
}else{
const res = await fetch("/get_history_tree/"+history_loc.uuid)
let loc = await res.json()
history.value[key] = loc
}
}
onMounted(() => {
tree_view.value = $("#tree_view").val()
if(tree_view.value == "True"){
@ -129,6 +142,7 @@
history,
tree_view,
save_history,
change_tree
}
}
}).mount('.container')