This commit is contained in:
anto
2025-01-08 16:44:39 +01:00
parent e60f704518
commit 2de78999f7
8 changed files with 77 additions and 20 deletions

View File

@@ -35,8 +35,6 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<select name="metriques" id="metric_selector"> <select name="metriques" id="metric_selector">
<option value="hygrometry">hygrométrie</option>
<option value="temperature">Température</option>
</select> </select>
<div id="metric_viewer_placeholder"> <div id="metric_viewer_placeholder">
<canvas id="metric_viewer"></canvas> <canvas id="metric_viewer"></canvas>
@@ -78,6 +76,8 @@
</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>
<script src="../js/utilities/constVariables.js"></script>
<script src="../js/utilities/populate.js"></script>
<script src="../js/globals.js"></script> <script src="../js/globals.js"></script>
<script src="../js/projet_detail.js"></script> <script src="../js/projet_detail.js"></script>
</body> </body>

View File

@@ -33,6 +33,7 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js" <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"> integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous">
</script> </script>
<script src="../js/utilities/constVariables.js"></script>
<script> <script>
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
document.getElementById("projets").addEventListener('click', () => { document.getElementById("projets").addEventListener('click', () => {

View File

@@ -35,6 +35,7 @@
</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/globals.js"></script> <script src="../js/globals.js"></script>
<script src="../js/index.js"></script> <script src="../js/index.js"></script>
<script> <script>

View File

@@ -1,5 +1,4 @@
// Global variables // Global variables
let api_url = "https://timelapse.kerboul.me/api";
let global_project_list; let global_project_list;
let current_project = ""; let current_project = "";
@@ -22,7 +21,7 @@ function formatDate(isoString) {
function getDataProjectFromApi() { function getDataProjectFromApi() {
return $.ajax({ return $.ajax({
url: api_url.concat("/itemsdb"), url: api_url.concat("/projects"),
method: "GET", method: "GET",
dataType: "json", dataType: "json",
}).then((data) => { }).then((data) => {

View File

@@ -12,8 +12,8 @@ function display_projects() {
for (let i = 0; i < global_project_list.length; i++) { for (let i = 0; i < global_project_list.length; i++) {
datas += `<tr> datas += `<tr>
<th>${global_project_list[i].id}</th> <th>${global_project_list[i].id}</th>
<th>${global_project_list[i].titre}</th> <th>${global_project_list[i].name}</th>
<th>${formatDate(global_project_list[i].creation)}</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].titre}</button></th>
</tr>`; </tr>`;

View File

@@ -1,12 +1,24 @@
let myChart; // Declare a global variable to hold the chart instance let myChart; // Declare a global variable to hold the chart instance
function display_metrics() {
// Implementation for display_metrics function
}
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
// Objects / variables
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
generateViewMetric();
PopulateSelect(metric_selector,projectId);
metric_selector.addEventListener("change", () => {
generateViewMetric();
});
// getDataProjectMetricsFromApi(projectId) // getDataProjectMetricsFromApi(projectId)
// .then((project_metrics) => { // .then((project_metrics) => {
// display_metrics(project_metrics); // display_metrics(project_metrics);
@@ -22,11 +34,6 @@ document.addEventListener("DOMContentLoaded", () => {
document.getElementById("name_project").innerHTML = document.getElementById("name_project").innerHTML =
global_project_list[projectId - 1].titre; global_project_list[projectId - 1].titre;
generateViewMetric();
document.getElementById("metric_selector").addEventListener("change", () => {
generateViewMetric();
});
fetch("https://timelapse.kerboul.me/api/smile") fetch("https://timelapse.kerboul.me/api/smile")
.then((response) => response.blob()) .then((response) => response.blob())
@@ -77,14 +84,25 @@ function generateViewMetric() {
// Create a new chart instance // Create a new chart instance
myChart = new Chart(ctx, { myChart = new Chart(ctx, {
type: "bar", type: "line",
data: { data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [ datasets: [
{ {
label: "# of Votes", label: "Température (F°)",
data: [12, 19, 3, 5, 2, 3], data: [65, 59, 80, 81, 56, 55, 40],
borderWidth: 1, fill: false,
borderColor: "rgba(75, 192, 192, 1)",
tension: 0.1,
yAxisID: "y", // Use the default y-axis
},
{
label: "Hygrometrie (%)",
data: [28, 48, 40, 19, 86, 27, 90],
fill: false,
borderColor: "rgba(153, 102, 255, 1)",
tension: 0.1,
yAxisID: "y1", // Use the second y-axis
}, },
], ],
}, },
@@ -92,6 +110,14 @@ function generateViewMetric() {
scales: { scales: {
y: { y: {
beginAtZero: true, beginAtZero: true,
position: "left",
},
y1: {
beginAtZero: true,
position: "right",
grid: {
drawOnChartArea: false, // Only want the grid lines for one axis to show up
},
}, },
}, },
}, },

View File

@@ -0,0 +1 @@
const api_url = "https://timelapse.kerboul.me/api";

29
js/utilities/populate.js Normal file
View File

@@ -0,0 +1,29 @@
async function PopulateSelect(mySelect,id){
let data=[]
if(mySelect.name=="metriques" && id!=null){
data=await getDataProjectVideosFromApi(id);
for(let i = 0 ; i < data.length ; i++){
const selectObj=document.createElement("option")
selectObj.value=data[i].id
selectObj.innerHTML=data[i].name
mySelect.appendChild(selectObj)
}
}
}
async function getDataProjectVideosFromApi(id) {
try {
const response = await $.ajax({
url: api_url.concat(`/projects/${id}/videos`),
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
}
}