Ajout de la gestion des projets actifs pour la caméra : vérification avant de démarrer un nouveau timelapse, réinitialisation lors de l'arrêt de la caméra et validation lors de l'upload manuel.
All checks were successful
SSH Frontend Deploy / ssh-deploy (push) Successful in 2s
All checks were successful
SSH Frontend Deploy / ssh-deploy (push) Successful in 2s
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
// Global variables
|
// Global variables
|
||||||
let global_project_list;
|
let global_project_list;
|
||||||
let current_project = "";
|
let current_project = "";
|
||||||
|
let active_camera_project = null; // ID du projet actuellement utilisé par la caméra
|
||||||
|
|
||||||
function formatDate(isoString) {
|
function formatDate(isoString) {
|
||||||
const date = new Date(isoString);
|
const date = new Date(isoString);
|
||||||
@@ -184,6 +185,16 @@ async function renderVideo(id){
|
|||||||
|
|
||||||
async function start_timelapse(id,frequency,nbimages){
|
async function start_timelapse(id,frequency,nbimages){
|
||||||
try {
|
try {
|
||||||
|
// Vérifier si un autre projet est déjà actif avec la caméra
|
||||||
|
if (active_camera_project !== null && active_camera_project !== id) {
|
||||||
|
const confirmation = confirm(`Un autre projet (ID: ${active_camera_project}) est déjà en cours avec la caméra. Voulez-vous arrêter ce projet et configurer la caméra pour le projet actuel?`);
|
||||||
|
if (!confirmation) {
|
||||||
|
alert("Configuration annulée. La caméra reste configurée pour le projet précédent.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Si l'utilisateur confirme, on continue et on va redéfinir active_camera_project
|
||||||
|
}
|
||||||
|
|
||||||
// Utilisation de plusieurs formats possibles pour garantir que le backend reçoit l'ID
|
// Utilisation de plusieurs formats possibles pour garantir que le backend reçoit l'ID
|
||||||
const mydata = JSON.stringify({
|
const mydata = JSON.stringify({
|
||||||
project_id: id, // Format avec underscore (convention standard REST)
|
project_id: id, // Format avec underscore (convention standard REST)
|
||||||
@@ -203,6 +214,9 @@ async function start_timelapse(id,frequency,nbimages){
|
|||||||
data: mydata
|
data: mydata
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Définir ce projet comme le projet actif pour la caméra
|
||||||
|
active_camera_project = id;
|
||||||
|
|
||||||
alert("Configuration de la caméra réussie");
|
alert("Configuration de la caméra réussie");
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -225,6 +239,9 @@ async function stopCamera(id){
|
|||||||
data: mydata
|
data: mydata
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Réinitialiser le statut du projet actif sur la caméra
|
||||||
|
active_camera_project = null;
|
||||||
|
|
||||||
alert("La caméra a été arrêtée avec succès");
|
alert("La caméra a été arrêtée avec succès");
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -235,6 +252,17 @@ async function stopCamera(id){
|
|||||||
|
|
||||||
async function manualUpload(imageFile, projectId, timestamp, temperature, humidity) {
|
async function manualUpload(imageFile, projectId, timestamp, temperature, humidity) {
|
||||||
try {
|
try {
|
||||||
|
// Vérifier que l'upload est fait pour le projet actif de la caméra
|
||||||
|
if (active_camera_project === null) {
|
||||||
|
alert("Aucun projet n'est actif avec la caméra. Veuillez configurer un projet avant d'effectuer un upload manuel.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (projectId !== active_camera_project) {
|
||||||
|
alert(`L'upload manuel n'est possible que pour le projet actif (ID: ${active_camera_project}). Vous essayez d'uploader pour le projet ${projectId}.`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Create FormData to send the file and metadata
|
// Create FormData to send the file and metadata
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('image', imageFile);
|
formData.append('image', imageFile);
|
||||||
@@ -251,10 +279,10 @@ async function manualUpload(imageFile, projectId, timestamp, temperature, humidi
|
|||||||
contentType: false, // Lets browser set the content type with boundary
|
contentType: false, // Lets browser set the content type with boundary
|
||||||
});
|
});
|
||||||
|
|
||||||
alert("Image uploaded successfully");
|
alert("Image téléchargée avec succès");
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert("Error uploading image: " + error);
|
alert("Erreur lors du téléchargement de l'image : " + error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user