Skip to content

Commit 5ec64a2

Browse files
committed
Merge branch 'main' of github.com:Aiky30/shed-pi into feature/historic-data-migration-package
2 parents 26b5517 + d28170b commit 5ec64a2

14 files changed

Lines changed: 738 additions & 206 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.bi {
2+
display: inline-block;
3+
width: 1rem;
4+
height: 1rem;
5+
}
6+
7+
/*
8+
* Sidebar
9+
*/
10+
11+
@media (min-width: 768px) {
12+
.sidebar .offcanvas-lg {
13+
position: -webkit-sticky;
14+
position: sticky;
15+
top: 48px;
16+
}
17+
18+
.navbar-search {
19+
display: block;
20+
}
21+
}
22+
23+
.sidebar .nav-link {
24+
font-size: .875rem;
25+
font-weight: 500;
26+
}
27+
28+
.sidebar .nav-link.active {
29+
color: #2470dc;
30+
}
31+
32+
.sidebar-heading {
33+
font-size: .75rem;
34+
}
35+
36+
/*
37+
* Navbar
38+
*/
39+
40+
.navbar-brand {
41+
padding-top: .75rem;
42+
padding-bottom: .75rem;
43+
background-color: rgba(0, 0, 0, .25);
44+
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
45+
}
46+
47+
.navbar .form-control {
48+
padding: .75rem 1rem;
49+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import {LineChart} from "./modules/chart.js";
2+
3+
const widgetTypeLineChart = "lineChart"
4+
5+
class Widget {
6+
constructor(config) {
7+
this.config = config
8+
const container = document.getElementById(this.config.id);
9+
10+
this.chart;
11+
if (this.config.chartType == widgetTypeLineChart) {
12+
this.chart = new LineChart(container)
13+
}
14+
}
15+
16+
async getDeviceData() {
17+
let data;
18+
const urlDeviceModule = "/api/v1/device-module/" + this.config.deviceModuleId
19+
let endpointDeviceModule = new Request(urlDeviceModule);
20+
21+
await fetch(endpointDeviceModule)
22+
.then((response) => {
23+
if (!response.ok) {
24+
throw new Error(`HTTP error! Status: ${response.status}`);
25+
}
26+
27+
return response.json();
28+
})
29+
.then((response) => {
30+
data = response
31+
32+
return response
33+
});
34+
return data
35+
}
36+
37+
async getDeviceReadings() {
38+
let data;
39+
40+
// const url = section.getAttribute("data-json-feed")
41+
const url = window.location.origin + "/api/v1/device-module-readings/"
42+
const endpoint = new URL(url);
43+
endpoint.searchParams.append("device_module", this.config.deviceModuleId);
44+
endpoint.searchParams.append("format", "json");
45+
endpoint.searchParams.append("start", this.config.startDate);
46+
endpoint.searchParams.append("end", this.config.endDate);
47+
48+
let endpointDeviceModuleReading = new Request(endpoint);
49+
50+
await fetch(endpointDeviceModuleReading)
51+
.then((response) => {
52+
if (!response.ok) {
53+
throw new Error(`HTTP error! Status: ${response.status}`);
54+
}
55+
56+
return response.json();
57+
})
58+
.then((response) => {
59+
data = response
60+
61+
return response
62+
});
63+
return data
64+
}
65+
66+
async render() {
67+
const deviceData = await this.getDeviceData()
68+
const deviceReadings = await this.getDeviceReadings()
69+
70+
this.chart.draw(deviceReadings, deviceData.schema)
71+
}
72+
}
73+
74+
75+
// TODO: DB Entry that controls this config, the page will then spit them out onto the page via backend,
76+
// we then loop through each class with config embedded
77+
const widgetConfigs = [
78+
{
79+
"id": "chartContainer1",
80+
"chartType": widgetTypeLineChart,
81+
"deviceModuleId": "c2f30e74-4708-4dff-9347-466563e353c8",
82+
"startDate": "2024-01-25",
83+
"endDate": "2024-02-24"
84+
},
85+
{
86+
"id": "chartContainer2",
87+
"chartType": widgetTypeLineChart,
88+
"deviceModuleId": "a62408c2-bc89-48e2-8c23-9494bbf33cb7",
89+
"startDate": "2024-01-25",
90+
"endDate": "2024-02-24"
91+
}
92+
];
93+
94+
widgetConfigs.forEach((widgetConfig) => {
95+
const widget = new Widget(widgetConfig)
96+
widget.render()
97+
});

shedpi_hub_dashboard/static/shedpi_hub_dashboard/js/index.js

Lines changed: 0 additions & 179 deletions
This file was deleted.

0 commit comments

Comments
 (0)