mes trucs
This commit is contained in:
@@ -7,4 +7,4 @@ footer {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,24 +14,25 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="section">
|
<div id="section" class="container mt-5">
|
||||||
<div class="buttons-container">
|
<div>
|
||||||
<button id="projets" class="btn btn-primary">
|
<div class="buttons-container" style="float: left; width: 20%;">
|
||||||
<span> Mes projets </span>
|
<button id="projets" class="btn btn-primary">
|
||||||
</button>
|
<span> Home </span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<h3 id="name_project" class="text-black" style="float: left; width: 50%;"></h3>
|
||||||
</div>
|
</div>
|
||||||
<div id="datas">
|
<table class="table table-striped" id="table-metrics">
|
||||||
<h5>
|
<thead class="bg-blue-600 text-black">
|
||||||
Métriques
|
<tr>
|
||||||
</h5>
|
<th> Métriques </th>
|
||||||
<h6>
|
<th> Hygrométrie </th>
|
||||||
Hygrométrie
|
<th> température </th>
|
||||||
</h6>
|
</tr>
|
||||||
<h6>
|
</thead>
|
||||||
température
|
<tbody></tbody>
|
||||||
</h6>
|
</table>
|
||||||
</div>
|
|
||||||
<div id="video"></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
@@ -53,28 +54,8 @@
|
|||||||
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
|
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
></script>
|
></script>
|
||||||
<script>
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
<script src="../js/globals.js"></script>
|
||||||
document.getElementById("projets").addEventListener("click", () => {
|
<script src="../js/projet_detail.js"></script>
|
||||||
window.location.href = "projets.html";
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const iframeString = `<iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ?autoplay=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>`;
|
|
||||||
|
|
||||||
const tempContainer = document.createElement("div");
|
|
||||||
|
|
||||||
// Set the innerHTML of the temporary container to the iframe string
|
|
||||||
tempContainer.innerHTML = iframeString;
|
|
||||||
|
|
||||||
// Get the first child element of the temporary container (which should be the iframe element)
|
|
||||||
const iframe = tempContainer.firstChild;
|
|
||||||
|
|
||||||
// Add the iframe element to the DOM
|
|
||||||
document.body.appendChild(iframe);
|
|
||||||
|
|
||||||
// Add the video element to the DOM
|
|
||||||
document.body.appendChild(video);
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
document.getElementById("projets").addEventListener('click', () => {
|
document.getElementById("projets").addEventListener('click', () => {
|
||||||
window.location.href = 'projets.html';
|
window.location.href = '../index.html';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
<thead class="bg-blue-600 text-white">
|
<thead class="bg-blue-600 text-white">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Status</th>
|
<th>Images</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -35,15 +35,16 @@
|
|||||||
</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/projets.js"></script>
|
<script src="../js/globals.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
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
document.getElementById("video").addEventListener('click', () => {
|
document.getElementById("video").addEventListener('click', () => {
|
||||||
window.location.href = 'videos.html';
|
window.location.href = 'html/videos.html';
|
||||||
});
|
});
|
||||||
document.getElementById("projet").addEventListener('click', () => {
|
document.getElementById("projet").addEventListener('click', () => {
|
||||||
window.location.href = 'projet_detail.html';
|
window.location.href = 'html/projet_detail.html';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
56
js/globals.js
Normal file
56
js/globals.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// Global variables
|
||||||
|
let api_url = "https://timelapse.kerboul.me/api";
|
||||||
|
let global_project_list;
|
||||||
|
let current_project = "";
|
||||||
|
|
||||||
|
// Function to get data from API
|
||||||
|
|
||||||
|
function getDataFromApi() {
|
||||||
|
const cachedData = localStorage.getItem("project_list");
|
||||||
|
if (cachedData) {
|
||||||
|
// If the data is in the cache, parse it and return it
|
||||||
|
return Promise.resolve(JSON.parse(cachedData));
|
||||||
|
} else {
|
||||||
|
// If the data is not in the cache, make the API request
|
||||||
|
return $.ajax({
|
||||||
|
url: api_url.concat("/itemsdb"),
|
||||||
|
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 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);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
41
js/index.js
Normal file
41
js/index.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
// Function to display projects in a table
|
||||||
|
function display_projects() {
|
||||||
|
// Get data from API and then generate HTML code to display the data in a table
|
||||||
|
const table = document.getElementById("table-projects");
|
||||||
|
let datas = `<tr>
|
||||||
|
<th>Id</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr> `;
|
||||||
|
for (let i = 0; i < global_project_list.rows.length; i++) {
|
||||||
|
datas += `<tr>
|
||||||
|
<th>${global_project_list.rows[i].id}</th>
|
||||||
|
<th>${global_project_list.rows[i].name}</th>
|
||||||
|
<th><button class="project_detail btn btn-primary">détails de ${global_project_list.rows[i].name}</button></th>
|
||||||
|
</tr>`;
|
||||||
|
}
|
||||||
|
table.innerHTML = datas;
|
||||||
|
|
||||||
|
// Select all the buttons with the class button_project
|
||||||
|
const buttons = document.getElementsByClassName("project_detail");
|
||||||
|
// Add an event listener to each button
|
||||||
|
for (let i = 0; i < buttons.length; i++) {
|
||||||
|
buttons[i].addEventListener("click", (event) => {
|
||||||
|
// Send data to API and then navigate to projet_detail.html page
|
||||||
|
window.location.href = `html/projet_detail.html?id=${global_project_list.rows[i].id}`;
|
||||||
|
});
|
||||||
|
buttons[i].addEventListener("onclick", (event) => {
|
||||||
|
// Send data to API and then navigate to projet_detail.html page
|
||||||
|
current_project=change_current_project(i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getDataFromApi()
|
||||||
|
.then(project_list => {
|
||||||
|
global_project_list = project_list;
|
||||||
|
// Call the next function here
|
||||||
|
display_projects();
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
12
js/projet_detail.js
Normal file
12
js/projet_detail.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const projectId = urlParams.get("id");
|
||||||
|
|
||||||
|
document.getElementById("projets").addEventListener("click", () => {
|
||||||
|
window.location.href = "../index.html";
|
||||||
|
current_project="";
|
||||||
|
});
|
||||||
|
global_project_list=JSON.parse(localStorage.getItem("project_list"));
|
||||||
|
document.getElementById("name_project").innerHTML=global_project_list.rows[projectId-1].name;
|
||||||
|
});
|
||||||
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
// Global variable for the API URL
|
|
||||||
let api_url = "https://timelapse.kerboul.me/api";
|
|
||||||
|
|
||||||
// Function to display projects in a table
|
|
||||||
function display_projects() {
|
|
||||||
// Get data from API and then generate HTML code to display the data in a table
|
|
||||||
getDataFromApi().then(function (project_list) {
|
|
||||||
const table = document.getElementById("table-projects");
|
|
||||||
let datas = `<tr>
|
|
||||||
<th>Id</th>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Actions</th>
|
|
||||||
</tr> `;
|
|
||||||
for (let i = 0; i < project_list.rows.length; i++) {
|
|
||||||
datas += `<tr>
|
|
||||||
<th>${project_list.rows[i].id}</th>
|
|
||||||
<th>${project_list.rows[i].name}</th>
|
|
||||||
<th><button class="project_detail btn btn-primary">détails de ${project_list.rows[i].name}</button></th>
|
|
||||||
</tr>`;
|
|
||||||
}
|
|
||||||
table.innerHTML = datas;
|
|
||||||
|
|
||||||
// Select all the buttons with the class button_project
|
|
||||||
const buttons = document.getElementsByClassName("project_detail");
|
|
||||||
// Add an event listener to each button
|
|
||||||
for (let i = 0; i < buttons.length; i++) {
|
|
||||||
buttons[i].addEventListener("click", (event) => {
|
|
||||||
// Send data to API and then navigate to projet_detail.html page
|
|
||||||
deleteDataFromApi(4)
|
|
||||||
window.location.href = "projet_detail.html";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to get data from API
|
|
||||||
function getDataFromApi() {
|
|
||||||
return $.ajax({
|
|
||||||
url: api_url.concat("/itemsdb"), // replace with your API URL
|
|
||||||
method: "GET", // or 'POST', 'PUT', 'DELETE', etc.
|
|
||||||
dataType: "json", // expected data type
|
|
||||||
success: function (data) {
|
|
||||||
// This function is called if the request is successful
|
|
||||||
return data; // log the data to the console
|
|
||||||
},
|
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
|
||||||
// This function is called if the request fails
|
|
||||||
console.error("Error:", textStatus, errorThrown);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Call display_projects() function to display projects
|
|
||||||
display_projects();
|
|
||||||
31
js/videos.js
Normal file
31
js/videos.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
// Fetch data from the API
|
||||||
|
fetch("https://timelapse.kerboul.me/api/itemsdb")
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
// Get the table body element
|
||||||
|
const tableBody = document.querySelector("#table-metrics tbody");
|
||||||
|
|
||||||
|
// Loop through the data and create a new row for each item
|
||||||
|
data.forEach(item => {
|
||||||
|
const row = document.createElement("tr");
|
||||||
|
|
||||||
|
// Create a new cell for each property (metrics, hygrometry, temperature)
|
||||||
|
const metricsCell = document.createElement("td");
|
||||||
|
metricsCell.textContent = item.metrics;
|
||||||
|
row.appendChild(metricsCell);
|
||||||
|
|
||||||
|
const hygrometryCell = document.createElement("td");
|
||||||
|
hygrometryCell.textContent = item.hygrometry;
|
||||||
|
row.appendChild(hygrometryCell);
|
||||||
|
|
||||||
|
const temperatureCell = document.createElement("td");
|
||||||
|
temperatureCell.textContent = item.temperature;
|
||||||
|
row.appendChild(temperatureCell);
|
||||||
|
|
||||||
|
// Append the row to the table body
|
||||||
|
tableBody.appendChild(row);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => console.error(error));
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user