also switched to json.Marshal at backend for watchAreas on stream page
This commit is contained in:
parent
5978e560f0
commit
82031fbce9
3 changed files with 18 additions and 10 deletions
4
main.go
4
main.go
|
|
@ -41,6 +41,8 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
streamTemplate, err := template.ParseFiles(streamHTML, baseHTML)
|
||||
|
||||
watchAreasJSON, _ := json.Marshal(stream.WatchAreas)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
|
|
@ -48,9 +50,11 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
|||
streamTemplate.Execute(w, struct {
|
||||
Streams map[string]*Stream
|
||||
Stream *Stream
|
||||
WatchAreasJSON string
|
||||
}{
|
||||
server.Streams,
|
||||
stream,
|
||||
string(watchAreasJSON[:]),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ let watchArea = new WatchArea(
|
|||
let watchAreas = [];
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(){
|
||||
loadWatchAreas();
|
||||
canvas = document.getElementById("canvas");
|
||||
ctx = canvas.getContext("2d");
|
||||
src = document.getElementById("current_color_stream");
|
||||
|
|
|
|||
|
|
@ -83,14 +83,17 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
{{range $watchArea := .Stream.WatchAreas}}
|
||||
let _watchAreas = {{.WatchAreasJSON}};
|
||||
function loadWatchAreas(){
|
||||
_watchAreas.forEach(watchArea => {
|
||||
watchAreas.push(new WatchArea(
|
||||
'{{ $watchArea.Name }}',
|
||||
{{ $watchArea.Area.Min.X }}, {{ $watchArea.Area.Min.Y }},
|
||||
{{ $watchArea.Area.Max.X }}, {{ $watchArea.Area.Max.Y }},
|
||||
{{ $watchArea.Color.R }}, {{ $watchArea.Color.G }}, {{ $watchArea.Color.B }}
|
||||
watchArea.name,
|
||||
watchArea.area.Min.X, watchArea.area.Min.Y,
|
||||
watchArea.area.Max.X, watchArea.area.Max.Y,
|
||||
watchArea.color.R, watchArea.color.G, watchArea.color.B
|
||||
));
|
||||
{{end}}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
{{end}}
|
||||
Loading…
Add table
Reference in a new issue