diff options
| -rw-r--r-- | dashboard/app/main.go | 12 | ||||
| -rw-r--r-- | dashboard/app/public_json_api.go | 33 |
2 files changed, 45 insertions, 0 deletions
diff --git a/dashboard/app/main.go b/dashboard/app/main.go index 4c9c8c253..6fd406b6e 100644 --- a/dashboard/app/main.go +++ b/dashboard/app/main.go @@ -462,6 +462,12 @@ func handleMain(c context.Context, w http.ResponseWriter, r *http.Request) error Managers: makeManagerList(managers, hdr.Namespace), BugFilter: makeUIBugFilter(c, filter), } + + if isJSONRequested(r) { + w.Header().Set("Content-Type", "application/json") + return writeJSONVersionOf(w, data) + } + return serveTemplate(w, "main.html", data) } @@ -597,6 +603,12 @@ func handleTerminalBugList(c context.Context, w http.ResponseWriter, r *http.Req Stats: stats, BugFilter: makeUIBugFilter(c, typ.Filter), } + + if isJSONRequested(r) { + w.Header().Set("Content-Type", "application/json") + return writeJSONVersionOf(w, data) + } + return serveTemplate(w, "terminal.html", data) } diff --git a/dashboard/app/public_json_api.go b/dashboard/app/public_json_api.go index a4b630257..2adc1f7e7 100644 --- a/dashboard/app/public_json_api.go +++ b/dashboard/app/public_json_api.go @@ -52,11 +52,44 @@ func getExtAPIDescrForBugPage(bugPage *uiBugPage) *publicAPIBugDescription { } } +type publicAPIBugGroup struct { + Version int `json:"version"` + Bugs []publicAPIBug +} + +type publicAPIBug struct { + Title string `json:"title,omitempty"` + Link string `json:"link"` + LastUpdated string `json:"last-updated,omitempty"` +} + +func getExtAPIDescrForBugGroups(bugGroups []*uiBugGroup) *publicAPIBugGroup { + return &publicAPIBugGroup{ + Version: 1, + Bugs: func() []publicAPIBug { + var res []publicAPIBug + for _, group := range bugGroups { + for _, bug := range group.Bugs { + res = append(res, publicAPIBug{ + Title: bug.Title, + Link: bug.Link, + }) + } + } + return res + }(), + } +} + func GetJSONDescrFor(page interface{}) ([]byte, error) { var res interface{} switch i := page.(type) { case *uiBugPage: res = getExtAPIDescrForBugPage(i) + case *uiTerminalPage: + res = getExtAPIDescrForBugGroups([]*uiBugGroup{i.Bugs}) + case *uiMainPage: + res = getExtAPIDescrForBugGroups(i.Groups) default: return nil, ErrClientNotFound } |
