iqair-apiserver/static/index_global_old.html

230 lines
8.3 KiB
HTML
Raw Normal View History

2024-01-04 04:56:08 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Air Quality Dashboard</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<script src="https://kit.fontawesome.com/34a5e0cdf4.js" crossorigin="anonymous"></script>
2024-01-04 06:16:36 +00:00
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
2024-01-04 04:56:08 +00:00
<script src="//code.iconify.design/1/1.0.6/iconify.min.js"></script>
<style>
body {
2024-01-04 06:16:36 +00:00
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
2024-01-04 04:56:08 +00:00
font-family: "Roboto", sans-serif;
}
.card_frame {
display: grid;
width: 750px;
height: 230px;
border-radius: 30px;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
}
.top_element {
display: grid;
grid-template-columns: 1fr 2fr 2fr;
background-color: #97FF55;
border-top-right-radius: 30px;
border-top-left-radius: 30px;
height: 190px;
}
.bottom_element {
display: grid;
grid-template-columns: 1fr 1fr;
background-color: #ffffff;
border-bottom-right-radius: 30px;
border-bottom-left-radius: 30px;
height: 40px;
}
.indoor_aqi_block {
display: flex;
grid-template-columns: 1fr 1fr;
justify-content: center;
justify-items: center;
align-items: center;
background-color: #ffffff;
border-bottom-left-radius: 30px;
height: 40px;
border-right: 1px solid #828282;
}
.outdoor_aqi_block {
display: flex;
grid-template-columns: 1fr 1fr;
justify-content: center;
justify-items: center;
align-items: center;
background-color: #ffffff;
border-bottom-right-radius: 30px;
height: 40px;
border-left: 1px solid #828282;
}
.aqi_text {
font-size: 20px;
font-weight: 500;
color: #000000;
margin-left: 10px;
2024-01-04 06:16:36 +00:00
font-family: "Roboto", sans-serif;
2024-01-04 04:56:08 +00:00
}
.health_icon_frame {
padding-top: 10px;
display: flex;
flex-direction: column;
justify-content: center;
justify-items: center;
align-items: center;
background-color: #7bdb3f;
border-top-left-radius: 30px;
font-size: 100px;
color: #fff;
}
.health_text {
font-size: 20px;
font-weight: 500;
color: #ffffff;
margin-left: 10px;
}
.pm25_frame {
display: flex;;
flex-direction: column;
justify-content: center;
justify-items: center;
align-items: center;
background-color: #ffffff;
border-radius: 30px;
font-size: 100px;
margin-bottom: 7px;
margin-left: 7px;
width: 270px;
color: #939393;
align-self: flex-end;
}
.pm25_text {
font-weight: 400;
color: #7a7a7a;
margin-left: 10px;
text-align: center;
font-size: 110px;
margin-top: 7px;
margin-bottom: 7px;
}
.pm25_location_text {
font-size: 20px;
font-weight: 400;
color: #000000;
margin-left: 10px;
margin-top: 7px;
margin-bottom: 7px;
}
.indoor_pm25_block .outdoor_pm25_block {
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<div class="card_frame">
<div class="top_element" id="top_element">
<div class="health_icon_frame" id="health_icon_frame">
<span class="iconify" data-icon="mdi-heart" id="health_icon"></span>
<p class="health_text", id="health_text">Healthy</p>
</div>
<div class="indoor_pm25_block">
<p class="pm25_text", id="indoor-pm25">N/A</p>
<div class="pm25_frame">
<p class="pm25_location_text">Indoor PM2.5</p>
</div>
</div>
<div class="outdoor_pm25_block">
<p class="pm25_text", id="outdoor-pm25">N/A</p>
<div class="pm25_frame">
<p class="pm25_location_text">Outdoor PM2.5</p>
</div>
</div>
</div>
<div class="bottom_element">
<div class="indoor_aqi_block">
<i class="fa-solid fa-house"></i>
<p class="aqi_text" id="indoor-aqi">Indoor AQI: N/A</p>
</div>
<div class="outdoor_aqi_block">
<i class="fa-solid fa-tree"></i>
<p class="aqi_text" id="outdoor-aqi">Outdoor AQI: N/A</p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Fetch data from API
function fetchData() {
var current_path = window.location.pathname;
// If current path end with index.html, remove it
if (current_path.endsWith("index.html")) {
current_path = current_path.replace("index.html", "");
}
$.get(current_path+"get_data", function(data) {
console.log(data);
// Update indoor AQI and PM2.5 values
$("#indoor-aqi").text("Indoor AQI: "+data.aqi_indoor);
$("#indoor-pm25").text(data.pm25_indoor);
// Update outdoor AQI and PM2.5 values
$("#outdoor-aqi").text("Outdoor AQI: "+data.aqi_outdoor);
$("#outdoor-pm25").text(data.pm25_outdoor);
// Is outdoor AQI healthy?
// If AQI is less than 50, it is healthy
// If AQI is between 50 and 100, it is unhealthy
// If AQI is more than 100, it is very unhealthy
var oldIcon = document.getElementById("health_icon");
oldIcon.parentNode.removeChild(oldIcon);
var newIcon = document.createElement("span");
newIcon.setAttribute("class", "iconify");
newIcon.setAttribute("data-inline", "false");
newIcon.id = "health_icon";
if (data.aqi_outdoor < 50) {
newIcon.setAttribute("data-icon", "mdi-heart");
Iconify.scanDOM();
$("#health_text").text("Healthy");
$("#top_element").css("background-color", "#97FF55");
$("#health_icon_frame").css("background-color", "#7bdb3f");
} else if (data.aqi_outdoor >= 50 && data.aqi_outdoor < 100) {
newIcon.setAttribute("data-icon", "mdi-smog");
Iconify.scanDOM();
$("#health_text").text("Moderate");
$("#top_element").css("background-color", "#FFD300");
$("#health_icon_frame").css("background-color", "#f9c300");
} else {
newIcon.setAttribute("data-icon", "mdi-skull-crossbones");
Iconify.scanDOM();
$("#health_text").text("Unhealthy");
$("#top_element").css("background-color", "#FF6969");
$("#health_icon_frame").css("background-color", "#A54444");
}
document.getElementById("health_icon_frame").appendChild(newIcon);
Iconify.scanDOM();
});
}
fetchData(); // Fetch data immediately when the page loads
setInterval(fetchData, 10000); // Fetch data every 10 seconds
});
</script>
</body>
</html>