This commit is contained in:
arussac
2025-02-12 08:48:28 +01:00
parent 3d5612bf4a
commit a88678fc3f
5 changed files with 246 additions and 152 deletions

View File

@@ -83,9 +83,6 @@ document.addEventListener("DOMContentLoaded", async () => {
numeratorInput.required = false;
denominatorInput.required = false;
}
// Assuming you have some logic to handle the required attribute for one-by-one container
// For example, if you have input fields in the one-by-one container, you can set their required attribute here
}
function addSelectedNumber() {
@@ -119,20 +116,25 @@ document.addEventListener("DOMContentLoaded", async () => {
const data = await getDataProjectVideosFromApi(projectId);
const nameVideo = document.getElementById('name').value;
const videoDuration = durationInput.value;
const videoResolution = document.getElementById('resolution').value;
if (videoDuration <= 0) {
alert('La durée de la vidéo doit être supérieur à 0');
return 0;
}
if (checkVideoPath(data, nameVideo) && nameVideo.length>0) {
alert('Nouvelle vidéo enregistrée :\nNom : ' + nameVideo +
'\nRésolution : ' + document.getElementById('resolution').value +
'\nDurée : ' + videoDuration + ' secondes');
} else {
if (!checkVideoPath(data, nameVideo) || !nameVideo.length>0) {
alert('Le nom : " ' + nameVideo + ' " est déjà pris ou vide ! \n' +
'veuillez en trouver un autre');
return 0;
}
const choice = choiceSelect.value
const measurementIds = getMeasurermentsIdsFromForm(choice,firstInput,lastInput);
postNewVideo(projectId, measurementIds, nameVideo, videoResolution, videoDuration)
.then(()=>{
alert('Nouvelle vidéo enregistrée :\nNom : ' + nameVideo +
'\nRésolution : ' + videoResolution +
'\nDurée : ' + videoDuration + ' secondes');
})
}
function navigateToProjects() {
@@ -153,6 +155,7 @@ document.addEventListener("DOMContentLoaded", async () => {
function populateNumberBoard(length) {
numberBoard.innerHTML = '';
numberBoard.style.gridTemplateColumns = `repeat(auto-fill, minmax(50px, 1fr))`;
for (let i = 1; i <= length; i++) {
const numberButton = document.createElement('button');
numberButton.classList.add('number-button');
@@ -161,6 +164,7 @@ document.addEventListener("DOMContentLoaded", async () => {
numberBoard.appendChild(numberButton);
}
}
function highlightNumber(button) {
button.classList.toggle('highlight');
}
@@ -190,7 +194,6 @@ function populateImageTable(DataMetrics) {
let i = 0;
DataMetrics.forEach((measure) => {
let imageTD = document.createElement("td");
console.log(`${api_url}/images/${measure.project_id}/${measure.order_id}`)
imageTD.innerHTML = `<img id="${i}" src="${api_url}/images/${measure.project_id}/${measure.order_id}"/>`;
row.appendChild(imageTD);
@@ -232,7 +235,7 @@ async function generateViewMetric(projectId) {
} else {
samples=measurements.map(measurements => measurements.id);
}
tempoMeasure = filterAndSortMeasurementsByIds(measurements, samples);
tempoMeasure.forEach((measure) => {
datesMeasurement.push(measure.timestamp);
@@ -284,4 +287,4 @@ async function generateViewMetric(projectId) {
},
},
})
}
}

View File

@@ -72,16 +72,27 @@ async function getDataVideoFromApi(id) {
}
}
async function postNewVideo(project_id, measurements_id, name_video, resolution, duration){
async function postNewVideo(project_id, measurements_id, name_video, resolution, duration) {
try {
const response = await $.ajax({
url: api_url.concat(`/videos/`),
method: "POST",
dataType: "json",
contentType: "application/json", // Specify the content type as JSON
data: JSON.stringify({
project_id: project_id,
measurements_id: measurements_id,
name_video: name_video,
resolution: resolution,
duration: duration
})
});
// If the request is successful, store the data in the cache and return it
console.log("Video posted successfully:", response);
return response;
} catch (error) {
console.error("Error fetching data:", error);
console.error("Error posting video:", error);
throw error; // Re-throw the error to handle it outside the function if needed
}
}

View File

@@ -23,3 +23,22 @@ function checkVideoPath(videos, name) {
});
return res;
}
function getMeasurermentsIdsFromForm(choice, firstInput,lastInput) {
if (choice === 'oneByOne') {
const highlightedButtons = document.querySelectorAll('.number-button.highlight');
return Array.from(highlightedButtons).map(button => parseInt(button.textContent));
} else {
const first = parseInt(firstInput.value);
const last = parseInt(lastInput.value);
const numerator = parseInt(document.getElementById('numerator').value);
const denominator = parseInt(document.getElementById('denominator').value);
const fraction = numerator / denominator;
const measurementIds = [];
for (let i = first; i <= last; i += fraction) {
measurementIds.push(Math.round(i));
}
return measurementIds;
}
}