diff --git a/src/app.py b/src/app.py
index dd03d13..fca6747 100644
--- a/src/app.py
+++ b/src/app.py
@@ -144,8 +144,6 @@ def changeListContent():
except:
return str('error changing content'), 400
-
-
@app.route('/app/datahistory',methods = ['GET'])
def data_history_request():
if request.method == 'GET':
@@ -191,6 +189,9 @@ def data_list_request():
details = get_list(list_uuid)
return jsonify(details), 200
+@app.route('/app/data-all', methods = ['GET'])
+def data_request_all():
+ return jsonify(fetch_all()), 200
if __name__ == '__main__':
app.run(debug = True)
diff --git a/src/db.py b/src/db.py
index 841de49..7d05fb9 100644
--- a/src/db.py
+++ b/src/db.py
@@ -369,6 +369,20 @@ def change_list_description(uuid, description):
connection.commit()
connection.close()
+def fetch_all():
+ tables = ["item", "itemlist", "listcontent", "history"]
+ results = []
+ connection = connect_db()
+ cursor = connection.cursor()
+ for table in tables:
+ query = f'SELECT * FROM {str(table)};'
+ cursor.execute(query)
+ results.append(cursor.fetchall())
+ cursor.close()
+ connection.commit()
+ 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 153ac81..dada21f 100644
--- a/web/app.html
+++ b/web/app.html
@@ -39,6 +39,9 @@
+
+
+
@@ -112,4 +115,5 @@
+
diff --git a/web/app.js b/web/app.js
index 8245a7d..ed4fc29 100644
--- a/web/app.js
+++ b/web/app.js
@@ -227,3 +227,27 @@ function getCheckedCheckboxIds(classname) {
});
return checkedIds;
}
+
+
+// export data
+async function downloadCSV() {
+ const all_data = await fetch_all();
+ var export_data = '';
+ for (const [key, value] of Object.entries(all_data)) {
+ const csvContent = objectToCsv(value);
+ export_data += `#####${key}\n`;
+ export_data += csvContent;
+ export_data += '\n';
+ }
+ export_blob = new Blob([export_data], {type: "text/plain;charset=utf-8"});
+ const url = window.URL.createObjectURL(export_blob);
+ const a = document.createElement('a');
+ a.setAttribute('href', url);
+ a.setAttribute('download', 'data.csv');
+ a.style.display = 'none';
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+}
+
+document.getElementById('export_data_button').addEventListener('click', downloadCSV);
diff --git a/web/fetch.js b/web/fetch.js
index dedbc6d..45df947 100644
--- a/web/fetch.js
+++ b/web/fetch.js
@@ -218,3 +218,46 @@ async function get_list_details(list_uuid) {
throw error;
}
}
+
+async function fetch_all() {
+ try {
+ const response = await fetch(`${currentUrl}app/data-all`);
+ const rawData = await response.json();
+ // tables = ['item', 'itemlist', 'listcontent', 'history']
+ let data = Object();
+ // uuid, itemid, skuid, choice, attributes, image, show
+ data.item = rawData[0].map(d => ({
+ uuid: d[0],
+ itemid: d[1],
+ skuid: d[2],
+ choice: d[3],
+ attributes: d[4],
+ image: d[5],
+ show: d[6],
+ }));
+ // uuid, name, description
+ data.itemlist = rawData[1].map(d => ({
+ uuid: d[0],
+ name: d[1],
+ description: d[2],
+ }));
+ // list_uuid, item_uuid
+ data.listcontent = rawData[2].map(d => ({
+ list_uuid: d[0],
+ item_uuid: d[1],
+ }));
+ // uuid, quantity, discount_percentage, price, currency, h_timestamp
+ data.history = rawData[3].map(d => ({
+ uuid: d[0],
+ quantity: d[1],
+ discount_percentage: d[2],
+ price: d[3],
+ currency: d[4],
+ h_timestamp: d[5],
+ }));
+ return data;
+ } catch (error) {
+ console.error('Error fetching data history: ', error);
+ throw error;
+ }
+}
diff --git a/web/filters_checkboxes.js b/web/filters_checkboxes.js
index a3a47eb..ede8c78 100644
--- a/web/filters_checkboxes.js
+++ b/web/filters_checkboxes.js
@@ -1,5 +1,4 @@
function filters_checkboxes() {
- console.log("refresh filters");
fetch_list().then(function(data){
{
const node = document.getElementById("filters_checkboxes");