@@ -2,16 +2,16 @@ package fms
22
33import (
44 "context"
5+ "embed"
56 "fmt"
67 "io/fs"
78 nhttp "net/http"
89 "os"
910 "strings"
1011 "sync"
1112 "time"
12- "embed"
1313
14- "github.com/flosch/pongo2/v5 "
14+ "github.com/flosch/pongo2/v6 "
1515 "github.com/go-chi/chi/v5"
1616 "github.com/hashicorp/go-hclog"
1717
@@ -62,6 +62,8 @@ func New(opts ...Option) (*FMS, error) {
6262 }
6363
6464 pongo2 .RegisterFilter ("valueok" , x .filterValueOK )
65+ pongo2 .RegisterFilter ("split" , x .filterSplit )
66+ pongo2 .RegisterFilter ("teamName" , x .filterTeamName )
6567
6668 sfs , _ := fs .Sub (uifs , "ui" )
6769 r .Handle ("/static/*" , nhttp .FileServer (nhttp .FS (sfs )))
@@ -83,6 +85,32 @@ func New(opts ...Option) (*FMS, error) {
8385 hr .Get ("/" , x .fieldHUD )
8486 })
8587 })
88+
89+ r .Route ("/api" , func (r chi.Router ) {
90+ r .Route ("/field" , func (r chi.Router ) {
91+ r .Get ("/configured-quads" , x .configuredQuads )
92+ })
93+ r .Route ("/map" , func (r chi.Router ) {
94+ r .Get ("/current" , x .apiGetCurrentMap )
95+ r .Get ("/stage" , x .apiGetStageMap )
96+ r .Post ("/stage" , x .apiUpdateStageMap )
97+ r .Post ("/commit-stage" , x .apiCommitStageMap )
98+ })
99+ })
100+
101+ r .Route ("/ui" , func (r chi.Router ) {
102+ r .Route ("/admin" , func (r chi.Router ) {
103+ r .Get ("/" , x .uiViewAdminLanding )
104+
105+ r .Route ("/map" , func (r chi.Router ) {
106+ r .Get ("/current" , x .uiViewCurrentMap )
107+ r .Get ("/stage" , x .uiViewStageMap )
108+ r .Post ("/stage" , x .uiViewUpdateStageMap )
109+ r .Post ("/commit-stage" , x .uiViewCommitStageMap )
110+ })
111+ })
112+ })
113+
86114 r .Get ("/metrics-sd" , x .promSD )
87115
88116 x .s .Mount ("/" , r )
@@ -123,7 +151,7 @@ func (f *FMS) doTemplate(w nhttp.ResponseWriter, r *nhttp.Request, tmpl string,
123151 }
124152}
125153
126- func (f * FMS ) filterValueOK (in * pongo2. Value , param * pongo2.Value ) (* pongo2.Value , * pongo2.Error ) {
154+ func (f * FMS ) filterValueOK (in , param * pongo2.Value ) (* pongo2.Value , * pongo2.Error ) {
127155 list := strings .Split (param .String (), "," )
128156 for _ , val := range list {
129157 if strings .TrimSpace (in .String ()) == strings .TrimSpace (val ) {
@@ -133,6 +161,20 @@ func (f *FMS) filterValueOK(in *pongo2.Value, param *pongo2.Value) (*pongo2.Valu
133161 return pongo2 .AsValue (false ), nil
134162}
135163
164+ func (f * FMS ) filterSplit (in , param * pongo2.Value ) (* pongo2.Value , * pongo2.Error ) {
165+ list := strings .Split (in .String (), param .String ())
166+ return pongo2 .AsValue (list ), nil
167+ }
168+
169+ func (f * FMS ) filterTeamName (in , param * pongo2.Value ) (* pongo2.Value , * pongo2.Error ) {
170+ t , ok := in .Interface ().(* Team )
171+ if ! ok {
172+ f .l .Error ("Something that wasn't a team got passed to the teamName filter" , "in" , in .Interface ())
173+ return pongo2 .AsValue ("" ), & pongo2.Error {Sender : "filter:teamName" }
174+ }
175+ return pongo2 .AsValue (t .Name ), nil
176+ }
177+
136178func (f * FMS ) populateHUDVersions () {
137179 fw := os .Getenv ("GIZMO_HUD_FWVERSIONS" )
138180 if fw != "" {
0 commit comments