This commit is contained in:
anto
2025-01-09 10:12:17 +01:00
parent 2de78999f7
commit 648460a967
9 changed files with 208 additions and 184 deletions

View File

@@ -1,6 +1,6 @@
async function PopulateSelect(mySelect,id){
let data=[]
if(mySelect.name=="metriques" && id!=null){
if(mySelect.name=="videos" && id!=null){
data=await getDataProjectVideosFromApi(id);
for(let i = 0 ; i < data.length ; i++){
const selectObj=document.createElement("option")
@@ -25,5 +25,20 @@ async function getDataProjectVideosFromApi(id) {
throw error; // Re-throw the error to handle it outside the function if needed
}
}
async function getDataVideoFromApi(id) {
try {
const response = await $.ajax({
url: api_url.concat(`/videos/${id}`),
method: "GET",
dataType: "json",
});
// If the request is successful, store the data in the cache and return it
return response;
} catch (error) {
console.error("Error fetching data:", error);
throw error; // Re-throw the error to handle it outside the function if needed
}
}

44
js/utilities/routes.js Normal file
View File

@@ -0,0 +1,44 @@
// Global variables
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 getAllProject() {
return $.ajax({
url: api_url.concat("/projects"),
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 getDataMetrics(projectId){
return $.ajax({
url: api_url.concat("/projects/"+projectId+"/measurements"),
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;
});
}

15
js/utilities/tools.js Normal file
View File

@@ -0,0 +1,15 @@
function convertStringToArray(inputString) {
// Split the string by the delimiter '/'
const stringArray = inputString.split(",");
// Convert each element to a number
const numberArray = stringArray.map(Number);
return numberArray;
}
function filterAndSortMeasurementsByIds(measurements, ids) {
return measurements
.filter((measurement) => ids.includes(measurement.id))
.sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
}