delete item interactivity
This commit is contained in:
parent
8761a6c5ad
commit
550848b4ff
@ -45,6 +45,14 @@ def add_item():
|
|||||||
# item not valid or can't be parsed
|
# item not valid or can't be parsed
|
||||||
return jsonify({'status': 1}), 400
|
return jsonify({'status': 1}), 400
|
||||||
|
|
||||||
|
@app.route('/delete', methods=['POST'])
|
||||||
|
def del_item():
|
||||||
|
print("deleting item")
|
||||||
|
data = request.get_json()
|
||||||
|
uuid = data.get('uuid')
|
||||||
|
delete_item(uuid)
|
||||||
|
return jsonify({'deleted': uuid}), 200
|
||||||
|
|
||||||
@app.route('/datahistory',methods = ['GET'])
|
@app.route('/datahistory',methods = ['GET'])
|
||||||
def data_history_request():
|
def data_history_request():
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
20
src/db.py
20
src/db.py
@ -122,6 +122,26 @@ def check_exist(itemid, skuid):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def delete_item(uuid):
|
||||||
|
'''
|
||||||
|
delete item and its history from database
|
||||||
|
'''
|
||||||
|
connection = connect_db()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
DELETE
|
||||||
|
FROM history
|
||||||
|
WHERE uuid = %s
|
||||||
|
""", (uuid,))
|
||||||
|
cursor.execute("""
|
||||||
|
DELETE
|
||||||
|
FROM history
|
||||||
|
WHERE uuid = %s
|
||||||
|
""", (uuid,))
|
||||||
|
cursor.close()
|
||||||
|
connection.commit()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
def export_csv():
|
def export_csv():
|
||||||
'''join item and history data from database and export it in ./output.csv'''
|
'''join item and history data from database and export it in ./output.csv'''
|
||||||
|
35
web/app.js
35
web/app.js
@ -319,9 +319,7 @@ fetch_history().then(async function(data) {
|
|||||||
document.getElementById("addbutton").addEventListener("click", addItem);
|
document.getElementById("addbutton").addEventListener("click", addItem);
|
||||||
|
|
||||||
async function addItem() {
|
async function addItem() {
|
||||||
|
|
||||||
const apiUrl = `${currentUrl}app/add`;
|
const apiUrl = `${currentUrl}app/add`;
|
||||||
|
|
||||||
const postData = {
|
const postData = {
|
||||||
itemid: document.getElementById("additemid").value,
|
itemid: document.getElementById("additemid").value,
|
||||||
attributes: document.getElementById("addattributes").value
|
attributes: document.getElementById("addattributes").value
|
||||||
@ -344,16 +342,41 @@ async function addItem() {
|
|||||||
console.error('Error during POST request:', error);
|
console.error('Error during POST request:', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
// reload window to display new item
|
// reload window to display new item
|
||||||
location.reload();
|
location.reload();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Error in server response');
|
throw new Error('Error in server response');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function delItem(uuid) {
|
||||||
|
const apiUrl = `${currentUrl}app/delete`;
|
||||||
|
const postData = {
|
||||||
|
uuid: uuid
|
||||||
|
};
|
||||||
|
|
||||||
|
const requestOptions = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(postData)
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(apiUrl, requestOptions)
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error during POST request:', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
console.log(response);
|
||||||
|
// reload window to stop displaying deleted item
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
throw new Error('Error in server response');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -363,13 +386,11 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
const noBtn = document.getElementById('noBtn');
|
const noBtn = document.getElementById('noBtn');
|
||||||
yesBtn.addEventListener('click', function () {
|
yesBtn.addEventListener('click', function () {
|
||||||
// Add your function to execute on 'Yes' click
|
// Add your function to execute on 'Yes' click
|
||||||
console.log('Yes clicked');
|
delItem(del_key);
|
||||||
console.log(del_key);
|
|
||||||
confirmationPopup.style.display = 'none';
|
confirmationPopup.style.display = 'none';
|
||||||
});
|
});
|
||||||
noBtn.addEventListener('click', function () {
|
noBtn.addEventListener('click', function () {
|
||||||
// Add your function to execute on 'No' click
|
// Add your function to execute on 'No' click
|
||||||
console.log('No clicked');
|
|
||||||
confirmationPopup.style.display = 'none';
|
confirmationPopup.style.display = 'none';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user