From 09a392f78adfe7c5d88f90023c3d5a9ad0f32e86 Mon Sep 17 00:00:00 2001 From: anto Date: Sun, 12 Jan 2025 17:20:15 +0100 Subject: [PATCH] maj --- html/projet_detail.html | 19 +++++++++++++------ js/projet_detail.js | 19 +++++++++++++++++-- js/utilities/populate.js | 30 ------------------------------ js/utilities/routes.js | 35 +++++++++++++++++++++++++++++++++++ js/utilities/tools.js | 10 ++++++++++ 5 files changed, 75 insertions(+), 38 deletions(-) diff --git a/html/projet_detail.html b/html/projet_detail.html index 79c6b1d..e8eb867 100644 --- a/html/projet_detail.html +++ b/html/projet_detail.html @@ -20,13 +20,20 @@ -
-
-
+
+
+

Formulaire

+

- + + +

+
@@ -35,9 +42,9 @@

- -
+
+
diff --git a/js/projet_detail.js b/js/projet_detail.js index 8829a81..4e68e0c 100644 --- a/js/projet_detail.js +++ b/js/projet_detail.js @@ -36,9 +36,24 @@ document.getElementById('decrement-button').addEventListener('click', function() } }); -document.getElementById('my-form').addEventListener('submit', function(event) { +document.getElementById('my-form').addEventListener('submit', async function(event) { event.preventDefault(); - alert('Nouveau Projet enregistré :\nNom : ' + document.getElementById('name').value + '\nDurée : ' + document.getElementById('duration').value + ' secondes'); + const data=await getDataProjectVideosFromApi(projectId); + const name_video = document.getElementById('name').value + const video_duration = document.getElementById('duration').value + if(video_duration>0){ + if(checkVideoPath(data, name_video)){ + alert('Nouvelle vidéo enregistrée :\nNom : ' + name_video + + '\nRésolution : ' + document.getElementById('resolution').value + + '\nDurée : ' + video_duration + ' secondes'); + //project_id, measurement_ids, video_name, resolution, duration, fps, status + } else { + alert('Le nom : "'+ name_video + '" est déjà pris ! \n' + + 'veuillez en trouver un autre') + } + } else { + alert('La durée de la vidéo doit être suppérieur à 0') + } }); document.getElementById("projets").addEventListener("click", () => { diff --git a/js/utilities/populate.js b/js/utilities/populate.js index 2f96b73..3baebf2 100644 --- a/js/utilities/populate.js +++ b/js/utilities/populate.js @@ -10,35 +10,5 @@ async function PopulateSelect(mySelect,id){ } } } - -async function getDataProjectVideosFromApi(id) { - try { - const response = await $.ajax({ - url: api_url.concat(`/projects/${id}/videos`), - 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 - } - } - - 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 - } - } \ No newline at end of file diff --git a/js/utilities/routes.js b/js/utilities/routes.js index 110bab0..d547b34 100644 --- a/js/utilities/routes.js +++ b/js/utilities/routes.js @@ -42,3 +42,38 @@ function getDataMetrics(projectId){ return data; }); } + + +async function getDataProjectVideosFromApi(id) { + try { + const response = await $.ajax({ + url: api_url.concat(`/projects/${id}/videos`), + 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 + } +} + +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 + } +} + +function postNewVideo(project_id, measurements_id, name_video, resolution, duration, fps, status){ + +} diff --git a/js/utilities/tools.js b/js/utilities/tools.js index 66d4e92..06c9f07 100644 --- a/js/utilities/tools.js +++ b/js/utilities/tools.js @@ -13,3 +13,13 @@ function filterAndSortMeasurementsByIds(measurements, ids) { .filter((measurement) => ids.includes(measurement.id)) .sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp)); } + +function checkVideoPath(videos, name) { + let res = true; + videos.forEach(video => { + const videoName = video.name; + if(videoName==name) + res=false; + }); + return res; +}