track new item

This commit is contained in:
2024-01-31 01:06:26 +01:00
parent 4894eae14f
commit 7b1bef3695
5 changed files with 119 additions and 26 deletions

View File

@ -1,16 +1,25 @@
<!DOCTYPE html>
<meta charset="utf-8">
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Aliexpress price tracker</title>
</head>
<body>
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v6.js"></script>
<!-- Create a div where the graphs will take place -->
<div id="graphs"></div>
<!--banner-->
<div class="banner">
<p>Lorem ipsum dolor sit amet</p>
<input id="additemid" type="text" placeholder="item id" pattern="[0-9]*">
<input id="addattributes" type="text" placeholder="attributes (comma separated)" pattern="[0-9a-zA-Z, ]*">
<button id="addbutton" type="button">Add</button>
</div>
<!-- <script src="http://127.0.0.1/app.js"></script> -->
<script>
let currenturl = (window.location);
var s = document.createElement( 'script' );
s.setAttribute( 'src', `${currenturl}/app.js` );
document.body.appendChild( s );
</script>
<!-- div where graphs will take place -->
<div class="content" id="graphs"></div>
<script src="app.js"></script>

View File

@ -23,13 +23,16 @@ async function fetch_history() {
try {
const response = await fetch(`${currentUrl}app/datahistory`);
const rawData = await response.json();
var dateFormat = d3.timeParse("%a, %d %b %Y %H:%M:%S GMT");
console.log(rawData)
// SELECT uuid, quantity, discount_percentage, price, currency, h_timestamp
let historyData = rawData.map(d => ({
uuid: d[0],
value: parseFloat(d[3].replace('$', '')),
currency: d[4],
date: new Date(d[5].replace(' ', 'T')),
date: dateFormat(d[5]),
}));
console.log(historyData)
return historyData;
} catch (error) {
console.error('Error fetching data history: ', error);
@ -281,3 +284,38 @@ fetch_history().then(async function(data) {
});
})
// add item
document.getElementById("addbutton").addEventListener("click", addItem);
async function addItem() {
const apiUrl = `${currentUrl}app/add`;
const postData = {
itemid: document.getElementById("additemid").value,
attributes: document.getElementById("addattributes").value
};
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);
} else {
throw new Error('Error in server response');
}
}

18
web/style.css Normal file
View File

@ -0,0 +1,18 @@
body {
margin: 0;
padding: 0;
}
.banner {
background-color: #177013; /* background color */
color: #fff; /* text color */
padding: 10px;
position: fixed;
top: 0;
width: 100%;
}
.content {
margin-top: 100px;
padding: 0px;
}