diff --git a/website/app/history/history.py b/website/app/history/history.py index 2339395..2bb613d 100644 --- a/website/app/history/history.py +++ b/website/app/history/history.py @@ -50,4 +50,30 @@ def get_history_tree(): histories = HistoryModel.get_history_tree() if histories: return histories - return {} \ No newline at end of file + return {} + +@history_blueprint.route("/get_history_tree/", 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/", 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/", 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/", methods=["GET"]) +def remove_node_tree(sid): + HistoryModel.remove_node_tree(sid) + return {"message": "Node deleted", "toast_class": "success-subtle"} \ No newline at end of file diff --git a/website/app/history/history_core.py b/website/app/history/history_core.py index 153504f..595fe34 100644 --- a/website/app/history/history_core.py +++ b/website/app/history/history_core.py @@ -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 diff --git a/website/app/static/js/history_view.js b/website/app/static/js/history_view.js index be79456..77270b0 100644 --- a/website/app/static/js/history_view.js +++ b/website/app/static/js/history_view.js @@ -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: `
-
@@ -57,7 +92,7 @@ export default {
  • diff --git a/website/app/templates/history_session.html b/website/app/templates/history_session.html index 3541f61..ec595de 100644 --- a/website/app/templates/history_session.html +++ b/website/app/templates/history_session.html @@ -63,8 +63,8 @@
    • -