diff options
| author | Taras Madan <tarasmadan@google.com> | 2023-06-16 12:29:10 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2023-06-19 16:42:56 +0200 |
| commit | 4b9f2f7e29d6f5c2e47ee1de4cd5d8f5c4e1d7e4 (patch) | |
| tree | 41f82050bbab36f739e6e6ae44811c136003429f | |
| parent | f1f9726ad56cc48e47cc0fdef249052883d7d7ee (diff) | |
dashboard/app: add bugGroup json reporting
| -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 } |
