From 4f069bfb2019aeaed80fe774e5455025ff900006 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Sat, 2 Mar 2024 15:46:44 +0100 Subject: [PATCH] restore/export data popup, TODO: backend for restore data --- src/app.py | 8 ++++++++ src/db.py | 11 ++++++++++ web/app.html | 26 +++++++++++++++++++++-- web/csv.js | 13 +++++++----- web/popups.js | 5 +++++ web/restore.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 web/restore.js diff --git a/src/app.py b/src/app.py index fca6747..024f83c 100644 --- a/src/app.py +++ b/src/app.py @@ -144,6 +144,14 @@ def changeListContent(): except: return str('error changing content'), 400 +@app.route('/app/restore', methods=['POST']) +def restore(): + data = request.get_json() + d = data.get('data') + # print(d) + restore_db(d) + return '1' + @app.route('/app/datahistory',methods = ['GET']) def data_history_request(): if request.method == 'GET': diff --git a/src/db.py b/src/db.py index 7d05fb9..bd4ed55 100644 --- a/src/db.py +++ b/src/db.py @@ -383,6 +383,17 @@ def fetch_all(): connection.close() return results +def restore_db(data): + tables_with_uuid = ["item", "itemlist"] + tables = ["item", "itemlist", "listcontent", "history"] + connection = connect_db() + cursor = connection.cursor() + for elem in data["item"]: + print(elem) + for table in tables: + for elem in data[table]: + print(elem) + def export_csv(): '''join item and history data from database and export it in ./output.csv''' connection = connect_db() diff --git a/web/app.html b/web/app.html index dada21f..6582290 100644 --- a/web/app.html +++ b/web/app.html @@ -39,8 +39,8 @@
-
- +
+
@@ -97,6 +97,27 @@ + + +