maj
This commit is contained in:
@@ -38,3 +38,6 @@ footer {
|
|||||||
top: 0;
|
top: 0;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
#addVideoHandler{
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@
|
|||||||
href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"
|
href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
/>
|
/>
|
||||||
|
<!-- Select2 CSS -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0/dist/css/select2.min.css" rel="stylesheet" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="section" class="container mt-5">
|
<div id="section" class="container mt-5">
|
||||||
@@ -34,8 +36,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<select name="metriques" id="metric_selector">
|
<div id="addVideoHandler">
|
||||||
|
<select name="videos" id="video_selector" class="select2">
|
||||||
</select>
|
</select>
|
||||||
|
<div class="buttons-container">
|
||||||
|
<button class="btn btn-primary" id="projets">
|
||||||
|
<span> + </span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div id="metric_viewer_placeholder">
|
<div id="metric_viewer_placeholder">
|
||||||
<canvas id="metric_viewer"></canvas>
|
<canvas id="metric_viewer"></canvas>
|
||||||
</div>
|
</div>
|
||||||
@@ -76,9 +85,12 @@
|
|||||||
</footer>
|
</footer>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<!-- Select2 JS -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0/dist/js/select2.min.js"></script>
|
||||||
<script src="../js/utilities/constVariables.js"></script>
|
<script src="../js/utilities/constVariables.js"></script>
|
||||||
<script src="../js/utilities/populate.js"></script>
|
<script src="../js/utilities/populate.js"></script>
|
||||||
<script src="../js/globals.js"></script>
|
<script src="../js/utilities/routes.js"></script>
|
||||||
|
<script src="../js/utilities/tools.js"></script>
|
||||||
<script src="../js/projet_detail.js"></script>
|
<script src="../js/projet_detail.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -35,8 +35,9 @@
|
|||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
|
||||||
<script src="../js/utilities/constVariables.js"></script>
|
<script src="../js/utilities/constVariables.js"></script>
|
||||||
<script src="../js/globals.js"></script>
|
<script src="../js/utilities/routes.js"></script>
|
||||||
<script src="../js/index.js"></script>
|
<script src="../js/index.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// Redirect to videos.php when the "Mes vidéos" button is clicked
|
// Redirect to videos.php when the "Mes vidéos" button is clicked
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
// Global variables
|
|
||||||
let global_project_list;
|
|
||||||
let current_project = "";
|
|
||||||
|
|
||||||
function formatDate(isoString) {
|
|
||||||
const date = new Date(isoString);
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
year: "numeric",
|
|
||||||
month: "long",
|
|
||||||
day: "numeric",
|
|
||||||
hour: "numeric",
|
|
||||||
minute: "numeric",
|
|
||||||
second: "numeric",
|
|
||||||
timeZoneName: "short",
|
|
||||||
};
|
|
||||||
|
|
||||||
return date.toLocaleString("en-US", options);
|
|
||||||
}
|
|
||||||
// Function to get data from API
|
|
||||||
|
|
||||||
function getDataProjectFromApi() {
|
|
||||||
return $.ajax({
|
|
||||||
url: api_url.concat("/projects"),
|
|
||||||
method: "GET",
|
|
||||||
dataType: "json",
|
|
||||||
}).then((data) => {
|
|
||||||
// If the request is successful, store the data in the cache and return it
|
|
||||||
localStorage.setItem("project_list", JSON.stringify(data));
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function getDataProjectMetricsFromApi(id) {
|
|
||||||
return $.ajax({
|
|
||||||
url: api_url.concat(`/metric/${id}`),
|
|
||||||
method: "GET",
|
|
||||||
dataType: "json",
|
|
||||||
}).then((data) => {
|
|
||||||
// If the request is successful, store the data in the cache and return it
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDataProjectImagesFromApi(id) {
|
|
||||||
return $.ajax({
|
|
||||||
url: api_url.concat(`/image/${id}`),
|
|
||||||
method: "GET",
|
|
||||||
dataType: "json",
|
|
||||||
}).then((data) => {
|
|
||||||
// If the request is successful, store the data in the cache and return it
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to send data to API
|
|
||||||
function sendDataFromApi(datas) {
|
|
||||||
return $.ajax({
|
|
||||||
url: api_url.concat("/projets"),
|
|
||||||
method: "POST",
|
|
||||||
data: JSON.stringify(datas),
|
|
||||||
contentType: "application/json",
|
|
||||||
success: function (datas) {
|
|
||||||
console.log("successful");
|
|
||||||
},
|
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
|
||||||
console.error(errorThrown);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteDataFromApi(id) {
|
|
||||||
return $.ajax({
|
|
||||||
url: api_url.concat("/delete"),
|
|
||||||
method: "POST",
|
|
||||||
data: JSON.stringify({ id: id }),
|
|
||||||
contentType: "application/json",
|
|
||||||
success: function (datas) {
|
|
||||||
console.log("successful");
|
|
||||||
},
|
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
|
||||||
console.error(errorThrown);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,7 @@ function display_projects() {
|
|||||||
<th>${global_project_list[i].name}</th>
|
<th>${global_project_list[i].name}</th>
|
||||||
<th>${formatDate(global_project_list[i].start_date)}</th>
|
<th>${formatDate(global_project_list[i].start_date)}</th>
|
||||||
<th>${global_project_list[i].status}</th>
|
<th>${global_project_list[i].status}</th>
|
||||||
<th><button class="project_detail btn btn-primary">détails de ${global_project_list[i].titre}</button></th>
|
<th><button class="project_detail btn btn-primary">détails de ${global_project_list[i].name}</button></th>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
}
|
}
|
||||||
table.innerHTML = datas;
|
table.innerHTML = datas;
|
||||||
@@ -34,7 +34,7 @@ function display_projects() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getDataProjectFromApi()
|
getAllProject()
|
||||||
.then(project_list => {
|
.then(project_list => {
|
||||||
global_project_list = project_list;
|
global_project_list = project_list;
|
||||||
// Call the next function here
|
// Call the next function here
|
||||||
|
|||||||
@@ -1,39 +1,28 @@
|
|||||||
let myChart; // Declare a global variable to hold the chart instance
|
let myChart; // Declare a global variable to hold the chart instance
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
|
||||||
// Objects / variables
|
// Objects / variables
|
||||||
|
const video_selector = document.getElementById("video_selector");
|
||||||
const metric_selector = document.getElementById("metric_selector")
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const projectId = urlParams.get("id");
|
const projectId = urlParams.get("id");
|
||||||
|
|
||||||
// Initialisation
|
// Initialisation
|
||||||
|
generateViewMetric(projectId);
|
||||||
|
|
||||||
generateViewMetric();
|
PopulateSelect(video_selector, projectId);
|
||||||
|
|
||||||
PopulateSelect(metric_selector,projectId);
|
video_selector.addEventListener("change", () => {
|
||||||
|
generateViewMetric(projectId);
|
||||||
metric_selector.addEventListener("change", () => {
|
|
||||||
generateViewMetric();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// getDataProjectMetricsFromApi(projectId)
|
|
||||||
// .then((project_metrics) => {
|
|
||||||
// display_metrics(project_metrics);
|
|
||||||
// })
|
|
||||||
// .catch((error) => {
|
|
||||||
// console.error(error);
|
|
||||||
// });
|
|
||||||
document.getElementById("projets").addEventListener("click", () => {
|
document.getElementById("projets").addEventListener("click", () => {
|
||||||
window.location.href = "../index.html";
|
window.location.href = "../index.html";
|
||||||
current_project = "";
|
current_project = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
global_project_list = JSON.parse(localStorage.getItem("project_list"));
|
global_project_list = JSON.parse(localStorage.getItem("project_list"));
|
||||||
document.getElementById("name_project").innerHTML =
|
document.getElementById("name_project").innerHTML =
|
||||||
global_project_list[projectId - 1].titre;
|
global_project_list[projectId - 1].name;
|
||||||
|
|
||||||
|
|
||||||
fetch("https://timelapse.kerboul.me/api/smile")
|
fetch("https://timelapse.kerboul.me/api/smile")
|
||||||
.then((response) => response.blob())
|
.then((response) => response.blob())
|
||||||
@@ -74,8 +63,37 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateViewMetric() {
|
async function generateViewMetric(projectId) {
|
||||||
const ctx = document.getElementById("metric_viewer").getContext("2d");
|
const ctx = document.getElementById("metric_viewer").getContext("2d");
|
||||||
|
let Hygrometrie = [];
|
||||||
|
let Temperature = [];
|
||||||
|
let datesMeasurement = [];
|
||||||
|
|
||||||
|
let measurements;
|
||||||
|
let current_video_datas;
|
||||||
|
|
||||||
|
// Wait for the video_selector to be populated
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
const checkExist = setInterval(() => {
|
||||||
|
if (document.getElementById("video_selector").options.length > 0) {
|
||||||
|
clearInterval(checkExist);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}, 100); // check every 100ms
|
||||||
|
});
|
||||||
|
|
||||||
|
const videoId = document.getElementById("video_selector").value;
|
||||||
|
|
||||||
|
measurements = await getDataMetrics(projectId);
|
||||||
|
current_video_datas = await getDataVideoFromApi(videoId);
|
||||||
|
|
||||||
|
let samples = convertStringToArray(current_video_datas[0]["measurement_ids"]);
|
||||||
|
tempoMeasure = filterAndSortMeasurementsByIds(measurements,samples)
|
||||||
|
tempoMeasure.forEach((measure) => {
|
||||||
|
datesMeasurement.push(measure.timestamp)
|
||||||
|
Temperature.push(measure.temperature)
|
||||||
|
Hygrometrie.push(measure.hydrometrie)
|
||||||
|
});
|
||||||
|
|
||||||
// Destroy the existing chart instance if it exists
|
// Destroy the existing chart instance if it exists
|
||||||
if (myChart) {
|
if (myChart) {
|
||||||
@@ -86,11 +104,11 @@ function generateViewMetric() {
|
|||||||
myChart = new Chart(ctx, {
|
myChart = new Chart(ctx, {
|
||||||
type: "line",
|
type: "line",
|
||||||
data: {
|
data: {
|
||||||
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
labels: datesMeasurement,
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: "Température (F°)",
|
label: "Température (F°)",
|
||||||
data: [65, 59, 80, 81, 56, 55, 40],
|
data: Temperature,
|
||||||
fill: false,
|
fill: false,
|
||||||
borderColor: "rgba(75, 192, 192, 1)",
|
borderColor: "rgba(75, 192, 192, 1)",
|
||||||
tension: 0.1,
|
tension: 0.1,
|
||||||
@@ -98,7 +116,7 @@ function generateViewMetric() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Hygrometrie (%)",
|
label: "Hygrometrie (%)",
|
||||||
data: [28, 48, 40, 19, 86, 27, 90],
|
data: Hygrometrie,
|
||||||
fill: false,
|
fill: false,
|
||||||
borderColor: "rgba(153, 102, 255, 1)",
|
borderColor: "rgba(153, 102, 255, 1)",
|
||||||
tension: 0.1,
|
tension: 0.1,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
async function PopulateSelect(mySelect,id){
|
async function PopulateSelect(mySelect,id){
|
||||||
let data=[]
|
let data=[]
|
||||||
if(mySelect.name=="metriques" && id!=null){
|
if(mySelect.name=="videos" && id!=null){
|
||||||
data=await getDataProjectVideosFromApi(id);
|
data=await getDataProjectVideosFromApi(id);
|
||||||
for(let i = 0 ; i < data.length ; i++){
|
for(let i = 0 ; i < data.length ; i++){
|
||||||
const selectObj=document.createElement("option")
|
const selectObj=document.createElement("option")
|
||||||
@@ -26,4 +26,19 @@ async function getDataProjectVideosFromApi(id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
44
js/utilities/routes.js
Normal file
44
js/utilities/routes.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// Global variables
|
||||||
|
let global_project_list;
|
||||||
|
let current_project = "";
|
||||||
|
|
||||||
|
function formatDate(isoString) {
|
||||||
|
const date = new Date(isoString);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
year: "numeric",
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "numeric",
|
||||||
|
second: "numeric",
|
||||||
|
timeZoneName: "short",
|
||||||
|
};
|
||||||
|
|
||||||
|
return date.toLocaleString("en-US", options);
|
||||||
|
}
|
||||||
|
// Function to get data from API
|
||||||
|
|
||||||
|
function getAllProject() {
|
||||||
|
return $.ajax({
|
||||||
|
url: api_url.concat("/projects"),
|
||||||
|
method: "GET",
|
||||||
|
dataType: "json",
|
||||||
|
}).then((data) => {
|
||||||
|
// If the request is successful, store the data in the cache and return it
|
||||||
|
localStorage.setItem("project_list", JSON.stringify(data));
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDataMetrics(projectId){
|
||||||
|
return $.ajax({
|
||||||
|
url: api_url.concat("/projects/"+projectId+"/measurements"),
|
||||||
|
method: "GET",
|
||||||
|
dataType: "json",
|
||||||
|
}).then((data) => {
|
||||||
|
// If the request is successful, store the data in the cache and return it
|
||||||
|
localStorage.setItem("project_list", JSON.stringify(data));
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
}
|
||||||
15
js/utilities/tools.js
Normal file
15
js/utilities/tools.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
function convertStringToArray(inputString) {
|
||||||
|
// Split the string by the delimiter '/'
|
||||||
|
const stringArray = inputString.split(",");
|
||||||
|
|
||||||
|
// Convert each element to a number
|
||||||
|
const numberArray = stringArray.map(Number);
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user