75 lines
1.8 KiB
JavaScript
75 lines
1.8 KiB
JavaScript
// Global variables
|
|
let api_url = "https://timelapse.kerboul.me/api";
|
|
let global_project_list;
|
|
let current_project = "";
|
|
|
|
function formatDate(isoString) {
|
|
const date = new Date(isoString);
|
|
|
|
const options = {
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
hour: "numeric",
|
|
minute: "numeric",
|
|
second: "numeric",
|
|
timeZoneName: "short",
|
|
};
|
|
|
|
return date.toLocaleString("en-US", options);
|
|
}
|
|
// Function to get data from API
|
|
|
|
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
|
|
function sendDataFromApi(datas) {
|
|
return $.ajax({
|
|
url: api_url.concat("/projets"),
|
|
method: "POST",
|
|
data: JSON.stringify(datas),
|
|
contentType: "application/json",
|
|
success: function (datas) {
|
|
console.log("successful");
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
console.error(errorThrown);
|
|
},
|
|
});
|
|
}
|
|
|
|
function deleteDataFromApi(id) {
|
|
return $.ajax({
|
|
url: api_url.concat("/delete"),
|
|
method: "POST",
|
|
data: JSON.stringify({ id: id }),
|
|
contentType: "application/json",
|
|
success: function (datas) {
|
|
console.log("successful");
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
console.error(errorThrown);
|
|
},
|
|
});
|
|
}
|