diff --git a/js/globals.js b/js/globals.js
index 2b81abe..4795d66 100644
--- a/js/globals.js
+++ b/js/globals.js
@@ -3,7 +3,6 @@ let api_url = "https://timelapse.kerboul.me/api";
let global_project_list;
let current_project = "";
-
function formatDate(isoString) {
const date = new Date(isoString);
@@ -14,32 +13,33 @@ function formatDate(isoString) {
hour: "numeric",
minute: "numeric",
second: "numeric",
- timeZoneName: "short"
+ timeZoneName: "short",
};
return date.toLocaleString("en-US", options);
}
-const readableString = date.toLocaleString("en-US", options);
-console.log(readableString);
// Function to get data from API
-function getDataFromApi() {
- // const cachedData = localStorage.getItem("project_list");
- // if (cachedData) {
- // // If the data is in the cache, parse it and return it
- // return Promise.resolve(JSON.parse(cachedData));
- // } else {
- // If the data is not in the cache, make the API request
- return $.ajax({
- url: api_url.concat("/itemsdb"),
- method: "GET",
- dataType: "json",
- }).then(data => {
- // If the request is successful, store the data in the cache and return it
- localStorage.setItem("project_list", JSON.stringify(data));
- return data;
- });
- // }
+function getDataProjectFromApi() {
+ return $.ajax({
+ url: api_url.concat("/itemsdb"),
+ method: "GET",
+ dataType: "json",
+ }).then((data) => {
+ // If the request is successful, store the data in the cache and return it
+ localStorage.setItem("project_list", JSON.stringify(data));
+ return data;
+ });
+}
+function getDataProjectMetricsFromApi(id) {
+ return $.ajax({
+ url: api_url.concat(`/metric/${id}`),
+ method: "GET",
+ dataType: "json",
+ }).then((data) => {
+ // If the request is successful, store the data in the cache and return it
+ return data;
+ });
}
// Function to send data to API
diff --git a/js/index.js b/js/index.js
index 7e89bdd..a2bed3d 100644
--- a/js/index.js
+++ b/js/index.js
@@ -9,13 +9,13 @@ function display_projects() {
Status
Actions
`;
- for (let i = 0; i < global_project_list.rows.length; i++) {
+ for (let i = 0; i < global_project_list.length; i++) {
datas += `
`;
}
table.innerHTML = datas;
@@ -26,7 +26,7 @@ function display_projects() {
for (let i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", (event) => {
// Send data to API and then navigate to projet_detail.html page
- window.location.href = `html/projet_detail.html?id=${global_project_list.rows[i].id}`;
+ window.location.href = `html/projet_detail.html?id=${global_project_list[i].id}`;
});
buttons[i].addEventListener("onclick", (event) => {
// Send data to API and then navigate to projet_detail.html page
@@ -34,7 +34,7 @@ function display_projects() {
});
}
}
-getDataFromApi()
+getDataProjectFromApi()
.then(project_list => {
global_project_list = project_list;
// Call the next function here
diff --git a/js/projet_detail.js b/js/projet_detail.js
index 5ad57cd..0648e5c 100644
--- a/js/projet_detail.js
+++ b/js/projet_detail.js
@@ -1,12 +1,37 @@
+function display_metrics(metrics_datas) {
+ // Get data from API and then generate HTML code to display the data in a table
+ const table = document.getElementById("table-metrics");
+ let datas = `
+
Date
+
Température
+
Hygrométrie
+
`;
+ for (let i = 0; i < metrics_datas.length; i++) {
+ datas += `