Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Plant Data Table</title>
- <style>
- table {
- border-collapse: collapse;
- width: 100%;
- margin: auto;
- }
- th, td {
- padding: 8px;
- text-align: left;
- border-bottom: 1px solid #ddd;
- }
- th {
- background-color: #f2f2f2;
- }
- .dot {
- height: 10px;
- width: 10px;
- border-radius: 50%;
- display: inline-block;
- margin-right: 5px;
- }
- .gray {
- background-color: gray;
- }
- .green {
- background-color: green;
- }
- .yellow {
- background-color: yellow;
- }
- .orange {
- background-color: orange;
- }
- .red {
- background-color: red;
- }
- </style>
- </head>
- <body>
- <table>
- <thead>
- <tr>
- <th>Plant Name</th>
- <th>Today</th>
- <th>Night</th>
- <th>Tomorrow</th>
- </tr>
- </thead>
- <tbody id="plant-table-body">
- </tbody>
- <tfoot>
- <tr>
- <td colspan="4" style="text-align: right;">Date: <span id="current-date"></span></td>
- </tr>
- </tfoot>
- </table>
- <script>
- Promise.all([
- fetch('pylenie_today.json').then(response => response.json()),
- fetch('pylenie_night.json').then(response => response.json()),
- fetch('pylenie_tomorrow.json').then(response => response.json())
- ]).then(([plantDataToday, plantDataNight, plantDataTomorrow]) => {
- const plantTableBody = document.getElementById("plant-table-body");
- for (const plantName in plantDataToday) {
- const todayValue = plantDataToday[plantName];
- const nightValue = plantDataNight[plantName] || 0;
- const tomorrowValue = plantDataTomorrow[plantName] || 0;
- const row = document.createElement("tr");
- const nameCell = document.createElement("td");
- const todayValueCell = document.createElement("td");
- const nightValueCell = document.createElement("td");
- const tomorrowValueCell = document.createElement("td");
- nameCell.innerText = plantName;
- // for (let i = 0; i < todayValue; i++) {
- // todayValueCell.appendChild(getValueDot(todayValue));
- // }
- if (todayValue === 0) {
- for (let i = 0; i < 4; i++) {
- todayValueCell.appendChild(getValueDot(0));
- }
- } else {
- for (let i = 0; i < todayValue; i++) {
- todayValueCell.appendChild(getValueDot(todayValue));
- }
- }
- if (nightValue === 0) {
- for (let i = 0; i < 4; i++) {
- nightValueCell.appendChild(getValueDot(0));
- }
- } else {
- for (let i = 0; i < nightValue; i++) {
- nightValueCell.appendChild(getValueDot(nightValue));
- }
- }
- if (tomorrowValue === 0) {
- for (let i = 0; i < 4; i++) {
- tomorrowValueCell.appendChild(getValueDot(0));
- }
- } else {
- for (let i = 0; i < tomorrowValue; i++) {
- tomorrowValueCell.appendChild(getValueDot(tomorrowValue));
- }
- }
- row.appendChild(nameCell);
- row.appendChild(todayValueCell);
- row.appendChild(nightValueCell);
- row.appendChild(tomorrowValueCell);
- plantTableBody.appendChild(row);
- }
- const currentDate = new Date();
- const currentDateElement = document.getElementById("current-date");
- currentDateElement.innerText = currentDate.toLocaleDateString();
- })
- .catch(error => console.error(error));
- function getValueDot(value) {
- const dot = document.createElement("div");
- dot.classList.add("dot");
- switch (value) {
- case 0:
- dot.classList.add("gray");
- break;
- case 1:
- dot.classList.add("green");
- break;
- case 2:
- dot.classList.add("yellow");
- break;
- case 3:
- dot.classList.add("orange");
- break;
- case 4:
- dot.classList.add("red");
- break;
- default:
- break;
- }
- return dot;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement