unnecessary templating
This commit is contained in:
parent
6591ca67d3
commit
e1be864988
@ -2,7 +2,6 @@ package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@ -18,9 +17,7 @@ type GinAdapter struct {
|
||||
}
|
||||
|
||||
func (g *GinAdapter) IndexHandler(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "page_index", gin.H{
|
||||
"title": "TH7",
|
||||
})
|
||||
c.File("./static/index.html")
|
||||
}
|
||||
|
||||
func NewGinAdapter(corePort ports.CorePort, cfg config.Config) *GinAdapter {
|
||||
@ -35,23 +32,23 @@ func NewGinAdapter(corePort ports.CorePort, cfg config.Config) *GinAdapter {
|
||||
adapter.router = gin.New()
|
||||
|
||||
// API
|
||||
adapter.router.GET("/data/channel/:id", adapter.GetChannelByIDHandler)
|
||||
adapter.router.GET("/data/channels", adapter.GetChannelsHandler)
|
||||
adapter.router.GET("/data/ratio", adapter.GetRatioHandler)
|
||||
adapter.router.GET("/data", adapter.GetDataHandler)
|
||||
adapter.router.GET("/v1/data/channel/:id", adapter.GetChannelByIDHandler)
|
||||
adapter.router.GET("/v1/data/channels", adapter.GetChannelsHandler)
|
||||
adapter.router.GET("/v1/data/ratio", adapter.GetRatioHandler)
|
||||
adapter.router.GET("/v1/data", adapter.GetDataHandler)
|
||||
|
||||
adapter.router.GET("/config/channel/:id", adapter.GetConfigChannelByIdHandler)
|
||||
adapter.router.GET("/config/channels", adapter.GetConfigChannelsHandler)
|
||||
adapter.router.GET("/config/device", adapter.GetConfigDeviceHandler)
|
||||
adapter.router.GET("/config/db", adapter.GetConfigDBHandler)
|
||||
adapter.router.GET("/v1/config/channel/:id", adapter.GetConfigChannelByIdHandler)
|
||||
adapter.router.GET("/v1/config/channels", adapter.GetConfigChannelsHandler)
|
||||
adapter.router.GET("/v1/config/device", adapter.GetConfigDeviceHandler)
|
||||
adapter.router.GET("/v1/config/db", adapter.GetConfigDBHandler)
|
||||
|
||||
adapter.router.POST("/config/device", adapter.SetConfigDeviceHandler)
|
||||
adapter.router.POST("/config/channel/:id", adapter.SetConfigChannelByIdHandler)
|
||||
adapter.router.POST("/config/db", adapter.SetConfigDBHandler)
|
||||
adapter.router.POST("/v1/config/device", adapter.SetConfigDeviceHandler)
|
||||
adapter.router.POST("/v1/config/channel/:id", adapter.SetConfigChannelByIdHandler)
|
||||
adapter.router.POST("/v1/config/db", adapter.SetConfigDBHandler)
|
||||
|
||||
adapter.router.LoadHTMLGlob("./templates/*.tmpl")
|
||||
adapter.router.Static("/assets", "./static")
|
||||
// TH7 demo code. html file and javascript
|
||||
adapter.router.GET("/", adapter.IndexHandler)
|
||||
adapter.router.Static("/assets", "./static")
|
||||
|
||||
return &adapter
|
||||
}
|
||||
|
@ -74,18 +74,18 @@ function updateOthers(data) {
|
||||
}
|
||||
|
||||
async function updateRead() {
|
||||
const data = await fetchData("/data");
|
||||
const data = await fetchData("/v1/data");
|
||||
updateTable(data, "read", readOldChannelCount, updateReadTable);
|
||||
updateOthers(data);
|
||||
}
|
||||
|
||||
async function updateConfig() {
|
||||
const data = await fetchData("/config");
|
||||
updateTable(data.config, "config", configOldChannelCount, updateConfigTable);
|
||||
const data = await fetchData("/v1/config/channels");
|
||||
updateTable(data, "config", configOldChannelCount, updateConfigTable);
|
||||
}
|
||||
|
||||
updateRead();
|
||||
updateConfig();
|
||||
|
||||
setInterval(updateRead, 1000);
|
||||
setInterval(updateConfig, 5000);
|
||||
setInterval(updateConfig, 10000);
|
||||
|
94
static/index.html
Normal file
94
static/index.html
Normal file
@ -0,0 +1,94 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>TH7 demo</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Arial", sans-serif;
|
||||
margin: 20px;
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #4caf50;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#vdd,
|
||||
#vref,
|
||||
#vadj,
|
||||
#timestamp {
|
||||
margin-top: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
#thermocouple {
|
||||
margin-top: 20px;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
#thermocouple td {
|
||||
min-width: 6rem;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>TH7</h1>
|
||||
|
||||
<table id="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Channel</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<p id="vdd">V<sub>DD</sub>:</p>
|
||||
<p id="vref">V<sub>REF</sub>:</p>
|
||||
<p id="vadj">V<sub>ADJ</sub>:</p>
|
||||
<p id="timestamp">Last updated:</p>
|
||||
|
||||
<h2>Thermocouple config</h2>
|
||||
|
||||
<table id="thermocouple">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Channel</th>
|
||||
<th>Type</th>
|
||||
<th>Gain</th>
|
||||
<th>Offset</th>
|
||||
<th>Filter size</th>
|
||||
<th>Filter type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<script src="/assets/data-updater.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,92 +0,0 @@
|
||||
{{ define "page_index" }}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{.title}}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Arial', sans-serif;
|
||||
margin: 20px;
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
th, td {
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #4CAF50;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#vdd, #vref, #vadj, #timestamp {
|
||||
margin-top: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
#thermocouple {
|
||||
margin-top: 20px;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
#thermocouple td {
|
||||
min-width: 6rem;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>TH7</h1>
|
||||
|
||||
<table id="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Channel</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<p id="vdd">V<sub>DD</sub>:</p>
|
||||
<p id="vref">V<sub>REF</sub>:</p>
|
||||
<p id="vadj">V<sub>ADJ</sub>:</p>
|
||||
<p id="timestamp">Last updated:</p>
|
||||
|
||||
<h2>Thermocouple config</h2>
|
||||
|
||||
<table id="thermocouple">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Channel</th>
|
||||
<th>Type</th>
|
||||
<th>Gain</th>
|
||||
<th>Offset</th>
|
||||
<th>Filter size</th>
|
||||
<th>Filter type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<script src="/assets/data-updater.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
{{ end }}
|
Loading…
Reference in New Issue
Block a user