From 77599c7abda78f7fae40e364d0e1b73c74f88d4c Mon Sep 17 00:00:00 2001 From: arussac Date: Wed, 12 Feb 2025 11:22:55 +0100 Subject: [PATCH] anto --- index.html | 17 +++++++++++++++++ js/index.js | 4 ++++ js/projet_detail.js | 9 ++++----- js/utilities/populate.js | 1 - js/utilities/routes.js | 2 +- js/utilities/tools.js | 8 +++++++- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index d9145ce..a0f48b1 100644 --- a/index.html +++ b/index.html @@ -12,10 +12,27 @@ +
+
diff --git a/js/index.js b/js/index.js index 512838e..e1c80bf 100644 --- a/js/index.js +++ b/js/index.js @@ -2,6 +2,10 @@ function display_projects() { // Get data from API and then generate HTML code to display the data in a table const table = document.getElementById("table-projects"); + const form = document.getElementById("add-project") + form.addEventListener('click', () => { + console.log("test") + }); let datas = ` diff --git a/js/projet_detail.js b/js/projet_detail.js index 96bbbd0..592ebdb 100644 --- a/js/projet_detail.js +++ b/js/projet_detail.js @@ -125,7 +125,6 @@ document.addEventListener("DOMContentLoaded", async () => { } const choice = choiceSelect.value const measurementIds = getMeasurementsIdsFromForm(choice,firstInput,lastInput); - console.log(measurementIds) postNewVideo(projectId, measurementIds, nameVideo, videoResolution, videoDuration) .then(()=>{ alert('Nouvelle vidéo enregistrée :\nNom : ' + nameVideo + @@ -231,17 +230,17 @@ async function generateViewMetric(projectId) { let samples; if(videoId!=-1){ currentVideoDatas = await getDataVideoFromApi(videoId); - const pathToVideo = await getVideoFromApi(videoId) - samples = currentVideoDatas[0]["measurement_ids"]; + samples = JSON.parse(currentVideoDatas[0]["measurement_ids"]); videoPlaceHolder.innerHTML=` ` + tempoMeasure=filterAndSortMeasurementsByNumber(measurements, samples) } else { samples=measurements.map(measurements => measurements.id); + tempoMeasure = filterAndSortMeasurementsByIds(measurements, samples); } - tempoMeasure = filterAndSortMeasurementsByIds(measurements, samples); tempoMeasure.forEach((measure) => { datesMeasurement.push(measure.timestamp); Temperature.push(measure.temperature); diff --git a/js/utilities/populate.js b/js/utilities/populate.js index c2501b7..fbd8541 100644 --- a/js/utilities/populate.js +++ b/js/utilities/populate.js @@ -2,7 +2,6 @@ async function PopulateSelect(mySelect, id) { let data = []; if (mySelect.name == "videos" && id != null) { data = await getDataProjectVideosFromApi(id); - console.log(data) const selectObjDefault = document.createElement("option"); selectObjDefault.value = -1; selectObjDefault.innerHTML = "Default"; diff --git a/js/utilities/routes.js b/js/utilities/routes.js index 7a77232..d18bdc9 100644 --- a/js/utilities/routes.js +++ b/js/utilities/routes.js @@ -102,7 +102,7 @@ async function postNewVideo(project_id, measurements_id, name_video, resolution, async function getVideoFromApi(id) { try { const response = await $.ajax({ - url: api_url.concat(`/videos/${id}`), + url: api_url.concat(`/cat/`), method: "GET", dataType: "json", }); diff --git a/js/utilities/tools.js b/js/utilities/tools.js index 1e494db..40104f8 100644 --- a/js/utilities/tools.js +++ b/js/utilities/tools.js @@ -1,5 +1,4 @@ function convertStringToArray(string) { - console.log(string) const numberStrings = string.replace(/[{}]/g, '').split(','); // Trim whitespace and convert the string numbers to integers @@ -13,6 +12,13 @@ function filterAndSortMeasurementsByIds(measurements, ids) { .filter((measurement) => ids.includes(measurement.id)) .sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp)); } +function filterAndSortMeasurementsByNumber(measurements, Numbers) { + // Filter measurements based on their position in the Numbers array + const filteredMeasurements = Numbers.map(index => measurements[index - 1]).filter(measurement => measurement !== undefined); + + // Sort the filtered measurements by their timestamp + return filteredMeasurements.sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp)); +} function checkVideoPath(videos, name) { let res = true;
Id Name