From ffc5acbd14bc358cb0d00c1a8eead805f9fa1b93 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Fri, 16 Feb 2024 19:16:46 +0100 Subject: [PATCH] itemlist manipulation functions + bootstrap button bar, TODO: interactivity --- src/app.py | 6 ++++++ src/db.py | 41 +++++++++++++++++++++++++++++++++++++++++ web/app.html | 41 ++++++++++++++++++++++++++++++++++++----- web/fetch.js | 17 +++++++++++++++++ web/popups.js | 8 ++++++++ web/style.css | 5 ----- 6 files changed, 108 insertions(+), 10 deletions(-) diff --git a/src/app.py b/src/app.py index 58b1fcd..e8e0d27 100644 --- a/src/app.py +++ b/src/app.py @@ -119,5 +119,11 @@ def data_item_request(): print("fetching data item") return jsonify(get_item()) +@app.route('/app/datalist',methods = ['GET']) +def data_list_request(): + if request.method == 'GET': + print("fetching data item") + return jsonify(get_lists()) + if __name__ == '__main__': app.run(debug = True) diff --git a/src/db.py b/src/db.py index b83623a..b836f97 100644 --- a/src/db.py +++ b/src/db.py @@ -91,6 +91,35 @@ def get_item(): connection.close() return results +def get_item_filtered(lists_uuid): + ''' + return items in a every specified lists (list of itemlist uuid) + every items if filter is empty + ''' + n_filters = len(lists_uuid) + if n_filters > 0: + sql_request = """ + SELECT uuid, itemid, skuid, choice, attributes, image, show + FROM item i + """ + for i in range(n_filters): + sql_request += f', content c{str(i)}' + sql_request += ' WHERE ' + for i,uuid in enumerate(lists_uuid): + sql_request += f' i.uuid = c{str(i)}.item_uuid and c{str(i)}.list_uuid = {str(uuid)} and' + + sql_request = sql_request[:-3] # remove last 'and' + + connection = connect_db() + cursor = connection.cursor() + cursor.execute(sql_request) + results = cursor.fetchall() + cursor.close() + connection.close() + else: + results = get_item() + return results + def get_item_keys(): '''return items id and attributes from database''' connection = connect_db() @@ -246,6 +275,18 @@ def remove_from_list(list_uuid, item_uuid): connection.commit() connection.close() +def get_lists(): + connection = connect_db() + cursor = connection.cursor() + cursor.execute(""" + SELECT uuid, name, description + FROM itemlist + """) + results = cursor.fetchall() + cursor.close() + connection.close() + return results + 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 7b7d96b..6ec76fd 100644 --- a/web/app.html +++ b/web/app.html @@ -11,15 +11,46 @@ + + + + + + + + diff --git a/web/fetch.js b/web/fetch.js index 3159562..3820ff5 100644 --- a/web/fetch.js +++ b/web/fetch.js @@ -60,3 +60,20 @@ async function get_data() { // console.log(history_data) return Array(items_data, history_data); } + +async function fetch_list() { + try { + const response = await fetch(`${currentUrl}app/datalist`); + const rawData = await response.json(); + // SELECT uuid, name, description + let listData = rawData.map(d => ({ + uuid: d[0], + name: d[1], + description: d[2], + })); + return listData; + } catch (error) { + console.error('Error fetching data history: ', error); + throw error; + } +} diff --git a/web/popups.js b/web/popups.js index a35be99..4d6bfd4 100644 --- a/web/popups.js +++ b/web/popups.js @@ -7,6 +7,11 @@ document.addEventListener("keydown", (event) => { } }); +// manage list +document.getElementById("manage_list").addEventListener("click", function () { + manageListPopup.style.display = 'flex'; + }); + // create new list document.getElementById("create_list").addEventListener("click", function () { // remove div content @@ -45,6 +50,9 @@ document.getElementById("create_list_cancel").addEventListener("click", function createListPopup.style.display = 'none'; }); +// modify list + + // delete item, pop-up confirm document.addEventListener('DOMContentLoaded', function () { diff --git a/web/style.css b/web/style.css index ec2fe7b..f753294 100644 --- a/web/style.css +++ b/web/style.css @@ -23,11 +23,6 @@ body { text-align: center; } -.global_toggleshow { - float: right; - margin-right: 20px; -} - .graph-container-hidden { background: rgba(0, 0, 0, 0.25); }