This commit is contained in:
arussac
2025-02-12 10:50:28 +01:00
parent 522e5db91e
commit bd4b1ddd2e
5 changed files with 46 additions and 22 deletions

View File

@@ -116,6 +116,7 @@
<div id="metric_viewer_placeholder"> <div id="metric_viewer_placeholder">
<canvas id="metric_viewer"></canvas> <canvas id="metric_viewer"></canvas>
</div> </div>
<div id="video-container"><span>Pas de vidéos pour le projet par défaut</span></div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div id="content1" class="hiddenTable"> <div id="content1" class="hiddenTable">
@@ -125,12 +126,10 @@
> >
<thead> <thead>
<tr> <tr>
<th> <th colspan="3">
<button class="btn btn-primary" id="toggle-view"> <button class="btn btn-primary" id="toggle-view">
See all images See all images
</button> </button>
</th>
<th>
<button class="btn btn-primary">export images</button> <button class="btn btn-primary">export images</button>
</th> </th>
</tr> </tr>

View File

@@ -21,7 +21,6 @@ document.addEventListener("DOMContentLoaded", async () => {
const durationInput = document.getElementById('duration'); const durationInput = document.getElementById('duration');
const tableImage = document.getElementById("content1"); const tableImage = document.getElementById("content1");
const numberBoard = document.getElementById('number-board'); const numberBoard = document.getElementById('number-board');
let selectedNumbers = []; let selectedNumbers = [];
choiceSelect.addEventListener('change', toggleContainers); choiceSelect.addEventListener('change', toggleContainers);
@@ -208,6 +207,8 @@ function populateImageTable(DataMetrics) {
async function generateViewMetric(projectId) { async function generateViewMetric(projectId) {
const ctx = document.getElementById("metric_viewer").getContext("2d"); const ctx = document.getElementById("metric_viewer").getContext("2d");
const videoPlaceHolder = document.getElementById('video-container')
let Hygrometrie = []; let Hygrometrie = [];
let Temperature = []; let Temperature = [];
let datesMeasurement = []; let datesMeasurement = [];
@@ -225,15 +226,21 @@ async function generateViewMetric(projectId) {
}); });
const videoId = document.getElementById("video_selector").value; const videoId = document.getElementById("video_selector").value;
measurements = await getDataMetrics(projectId); measurements = await getDataMetrics(projectId);
let samples; let samples;
if(videoId!=-1){ if(videoId!=-1){
currentVideoDatas = await getDataVideoFromApi(videoId); currentVideoDatas = await getDataVideoFromApi(videoId);
samples = convertStringToArray(currentVideoDatas[0]["measurement_ids"]); const pathToVideo = await getVideoFromApi(videoId)
samples = currentVideoDatas[0]["measurement_ids"];
videoPlaceHolder.innerHTML=`
<video width="600" controls>
<source src="path/to/your/video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>`
} else { } else {
samples=measurements.map(measurements => measurements.id); samples=measurements.map(measurements => measurements.id);
} }
tempoMeasure = filterAndSortMeasurementsByIds(measurements, samples); tempoMeasure = filterAndSortMeasurementsByIds(measurements, samples);
tempoMeasure.forEach((measure) => { tempoMeasure.forEach((measure) => {
datesMeasurement.push(measure.timestamp); datesMeasurement.push(measure.timestamp);

View File

@@ -2,6 +2,7 @@ async function PopulateSelect(mySelect, id) {
let data = []; let data = [];
if (mySelect.name == "videos" && id != null) { if (mySelect.name == "videos" && id != null) {
data = await getDataProjectVideosFromApi(id); data = await getDataProjectVideosFromApi(id);
console.log(data)
const selectObjDefault = document.createElement("option"); const selectObjDefault = document.createElement("option");
selectObjDefault.value = -1; selectObjDefault.value = -1;
selectObjDefault.innerHTML = "Default"; selectObjDefault.innerHTML = "Default";

View File

@@ -74,25 +74,42 @@ 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 { try {
const measures = JSON.stringify(measurements_id);
const mydata = JSON.stringify({
project_id: project_id,
measurement_ids: measures, // Ensure this matches the expected field name
name: name_video,
resolution: resolution,
duration: duration
});
console.log(mydata);
const response = await $.ajax({ const response = await $.ajax({
url: api_url.concat(`/videos/`), url: api_url.concat(`/videos/`),
method: "POST", method: "POST",
dataType: "json", dataType: "json",
contentType: "application/json", // Specify the content type as JSON contentType: "application/json",
data: JSON.stringify({ data: mydata
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); console.log("Video posted successfully:", response);
return response;
} catch (error) { } catch (error) {
console.error("Error posting video:", error); console.error("Error posting video:", error);
throw error; // Re-throw the error to handle it outside the function if needed throw error;
} }
} }
async function getVideoFromApi(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
}
}

View File

@@ -1,9 +1,9 @@
function convertStringToArray(inputString) { function convertStringToArray(string) {
// Split the string by the delimiter '/' console.log(string)
const stringArray = inputString.split(","); const numberStrings = string.replace(/[{}]/g, '').split(',');
// Convert each element to a number // Trim whitespace and convert the string numbers to integers
const numberArray = stringArray.map(Number); const numberArray = numberStrings.map(num => parseInt(num.trim(), 10));
return numberArray; return numberArray;
} }