à demain
This commit is contained in:
@@ -17,37 +17,45 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
const oneByOneContainer = document.getElementById('one-by-one-container');
|
||||
const firstLastContainer = document.getElementById('first-last-container');
|
||||
const addNumberButton = document.getElementById('add-number-button');
|
||||
const formContainer = document.getElementById('form-container');
|
||||
const formContainerProject = document.getElementById('form-container-project');
|
||||
const formContainerCamera = document.getElementById('form-container-camera');
|
||||
const durationInput = document.getElementById('duration');
|
||||
const tableImage = document.getElementById("content1");
|
||||
const numberBoard = document.getElementById('number-board');
|
||||
// Add event listeners for the "Début" and "Fin" input fields
|
||||
const firstInput = document.getElementById('first');
|
||||
const lastInput = document.getElementById('last');
|
||||
const start_timelapse = document.getElementById('start-timelapse')
|
||||
|
||||
|
||||
let selectedNumbers = [];
|
||||
|
||||
populateTimelapseLogic(start_timelapse, projectId).then( () => {
|
||||
document.getElementById('show-form-button-camera').addEventListener('click', showFormCamera)
|
||||
document.getElementById('close-form-button-camera').addEventListener('click', hideFormCamera)
|
||||
}
|
||||
)
|
||||
|
||||
choiceSelect.addEventListener('change', toggleContainers);
|
||||
|
||||
if (addNumberButton) {
|
||||
addNumberButton.addEventListener('click', addSelectedNumber);
|
||||
}
|
||||
videoSelector.addEventListener("change", () => generateViewMetric(projectId));
|
||||
document.getElementById('show-form-button').addEventListener('click', showForm);
|
||||
document.getElementById('close-form-button').addEventListener('click', hideForm);
|
||||
document.getElementById('show-form-button-camera').addEventListener('click', showFormProject);
|
||||
document.getElementById('close-form-button-project').addEventListener('click', hideFormProject);
|
||||
|
||||
document.getElementById('increment-button').addEventListener('click', incrementDuration);
|
||||
document.getElementById('decrement-button').addEventListener('click', decrementDuration);
|
||||
document.getElementById('submit').addEventListener('click', handleFormSubmit);
|
||||
document.getElementById("projets").addEventListener("click", navigateToProjects);
|
||||
document.getElementById("toggle-view").addEventListener("click", toggleView);
|
||||
|
||||
|
||||
firstInput.addEventListener('input', updateRange);
|
||||
lastInput.addEventListener('input', updateRange);
|
||||
|
||||
generateViewMetric(projectId);
|
||||
PopulateSelect(videoSelector, projectId);
|
||||
|
||||
|
||||
function toggleContainers() {
|
||||
if (choiceSelect.value === 'oneByOne') {
|
||||
@@ -91,12 +99,19 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
}
|
||||
}
|
||||
|
||||
function showForm() {
|
||||
formContainer.style.display = 'flex';
|
||||
function showFormCamera() {
|
||||
formContainerCamera.style.display = 'flex';
|
||||
}
|
||||
|
||||
function hideForm() {
|
||||
formContainer.style.display = 'none';
|
||||
function hideFormCamera() {
|
||||
formContainerCamera.style.display = 'none';
|
||||
}
|
||||
function showFormProject() {
|
||||
formContainerProject.style.display = 'flex';
|
||||
}
|
||||
|
||||
function hideFormProject() {
|
||||
formContainerProject.style.display = 'none';
|
||||
}
|
||||
function incrementDuration() {
|
||||
durationInput.value = parseInt(durationInput.value) + 1;
|
||||
@@ -131,7 +146,13 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
alert('Nouvelle vidéo enregistrée :\nNom : ' + nameVideo +
|
||||
'\nRésolution : ' + videoResolution +
|
||||
'\nDurée : ' + videoDuration + ' secondes');
|
||||
}).then(()=>{
|
||||
getDataProjectVideosFromApi(projectId).then((data)=>{
|
||||
console.log(data)
|
||||
renderVideo(idVideo)
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function navigateToProjects() {
|
||||
@@ -227,7 +248,7 @@ async function generateViewMetric(projectId) {
|
||||
});
|
||||
|
||||
const videoId = document.getElementById("video_selector").value;
|
||||
|
||||
|
||||
measurements = await getDataMetrics(projectId);
|
||||
let samples;
|
||||
if(videoId!=-1){
|
||||
@@ -317,4 +338,96 @@ function showConfirmationAlert(videoId) {
|
||||
cancelBtn.onclick = function() {
|
||||
customAlert.style.display = 'none';
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function convertStringToArray(string) {
|
||||
const numberStrings = string.replace(/[{}]/g, '').split(',');
|
||||
|
||||
// Trim whitespace and convert the string numbers to integers
|
||||
const numberArray = numberStrings.map(num => parseInt(num.trim(), 10));
|
||||
|
||||
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));
|
||||
}
|
||||
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;
|
||||
videos.forEach(video => {
|
||||
const videoName = video.name;
|
||||
if(videoName==name)
|
||||
res=false;
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
function getMeasurementsIdsFromForm(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 denominator = parseInt(document.getElementById('denominator').value);
|
||||
|
||||
const measurementIds = new Set();
|
||||
measurementIds.add(first); // Always include the first image
|
||||
// Iterate through the range, adding the step size
|
||||
for (let i = first + denominator; i <= last; i += denominator) {
|
||||
measurementIds.add(i);
|
||||
}
|
||||
|
||||
measurementIds.add(last); // Always include the last image
|
||||
|
||||
// Convert the Set back to an array and sort it
|
||||
return Array.from(measurementIds).sort((a, b) => a - b);
|
||||
}
|
||||
}
|
||||
|
||||
async function populateTimelapseLogic(placeholder,id) {
|
||||
const data = await getSingleProject(id);
|
||||
if(data.status == 0){
|
||||
placeholder.innerHTML = `<button class="btn btn-primary" id="show-form-button-camera">
|
||||
<span> Configurer la caméra </span>
|
||||
</button>`
|
||||
} else {
|
||||
placeholder.innerHTML = ``
|
||||
}
|
||||
}
|
||||
|
||||
function increment(id) {
|
||||
const input = document.getElementById(id);
|
||||
input.value = parseInt(input.value) + 1;
|
||||
updateFrequencyText()
|
||||
}
|
||||
|
||||
function decrement(id) {
|
||||
const input = document.getElementById(id);
|
||||
if (parseInt(input.value) > 0) {
|
||||
input.value = parseInt(input.value) - 1;
|
||||
}
|
||||
updateFrequencyText()
|
||||
}
|
||||
|
||||
function updateFrequencyText() {
|
||||
const days = document.getElementById('days').value;
|
||||
const hours = document.getElementById('hours').value;
|
||||
const minutes = document.getElementById('minutes').value;
|
||||
const seconds = document.getElementById('seconds').value;
|
||||
|
||||
const frequencyText = `une image sera prise toutes les ${days} jours ${hours} heures ${minutes} minutes ${seconds} secondes`;
|
||||
document.getElementById('frequency-text').innerHTML = frequencyText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,16 @@ function getAllProject() {
|
||||
});
|
||||
}
|
||||
|
||||
function getSingleProject(id) {
|
||||
return $.ajax({
|
||||
url: api_url.concat("/projects/"+id),
|
||||
method: "GET",
|
||||
dataType: "json"
|
||||
}).then((data) => {
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
function getDataMetrics(projectId){
|
||||
return $.ajax({
|
||||
url: api_url.concat(`/projects/${projectId}/measurements`),
|
||||
@@ -146,4 +156,24 @@ async function deleteVideo(id){
|
||||
console.error("Error deleting video, video id :"+ id+"\n error :"+error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function renderVideo(id){
|
||||
try {
|
||||
const mydata = JSON.stringify({
|
||||
info:"none"
|
||||
});
|
||||
const response = await $.ajax({
|
||||
url: api_url.concat(`/videos/render/`+id),
|
||||
method: "POST",
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
data: mydata
|
||||
});
|
||||
|
||||
console.log("Video rendered successfully:", response);
|
||||
} catch (error) {
|
||||
console.error("Error rendering video:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -53,4 +53,4 @@ function getMeasurementsIdsFromForm(choice, firstInput, lastInput) {
|
||||
// Convert the Set back to an array and sort it
|
||||
return Array.from(measurementIds).sort((a, b) => a - b);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user