Commit a9eb95e41b
Verified · cmc
Layout: unified · split
internal/httpd/labels.go +9 −1
| @@ -28,13 +28,21 @@ func (s *Server) labels(w http.ResponseWriter, r *http.Request) { | ||
| 28 | 28 | http.Error(w, "internal error", http.StatusInternalServerError) |
| 29 | 29 | return |
| 30 | 30 | } |
| 31 | anyColor := false | |
| 32 | for _, l := range labels { | |
| 33 | if l.Color != "" { | |
| 34 | anyColor = true | |
| 35 | break | |
| 36 | } | |
| 37 | } | |
| 31 | 38 | s.render(w, "labels.html", struct { |
| 32 | 39 | repoPage |
| 33 | 40 | Labels []store.Label |
| 34 | 41 | LabelColors map[string]template.CSS |
| 35 | 42 | CanWrite bool |
| 43 | AnyColor bool | |
| 36 | 44 | Notice string |
| 37 | }{p, labels, s.labelColors(p.Repo), s.canWriteRepo(r, p.Repo), s.takeFlash(w, r)}) | |
| 45 | }{p, labels, s.labelColors(p.Repo), s.canWriteRepo(r, p.Repo), anyColor, s.takeFlash(w, r)}) | |
| 38 | 46 | } |
| 39 | 47 | |
| 40 | 48 | // labelSubmit creates a label, sets its colour, or removes it, through |
internal/web/templates/labels.html +3 −3
| @@ -3,14 +3,14 @@ | ||
| 3 | 3 | <h1>Labels</h1> |
| 4 | 4 | {{if .Notice}}<p class="error" role="alert">{{.Notice}}</p>{{end}} |
| 5 | 5 | {{if .Labels}}<div class="tablewrap"><table class="keys"> |
| 6 | <tr class="cols"><th scope="col">label</th><th scope="col">colour</th><th scope="col">issues</th><th scope="col"></th></tr> | |
| 6 | <tr class="cols"><th scope="col">label</th>{{if or $.CanWrite $.AnyColor}}<th scope="col">colour</th>{{end}}<th scope="col">issues</th><th scope="col"></th></tr> | |
| 7 | 7 | {{range .Labels}}<tr> |
| 8 | 8 | <td><a class="chip label" style="{{index $.LabelColors .Name}}" href="/{{$.Repo.OwnerName}}/{{$.Repo.Name}}/issues?label={{.Name}}">{{.Name}}</a>{{if .Org}} <span class="chip chip-neutral">org</span>{{end}}</td> |
| 9 | <td>{{if and $.CanWrite (not .Org)}}<form method="post" action="/{{$.Repo.OwnerName}}/{{$.Repo.Name}}/labels" class="inline"> | |
| 9 | {{if or $.CanWrite $.AnyColor}}<td>{{if and $.CanWrite (not .Org)}}<form method="post" action="/{{$.Repo.OwnerName}}/{{$.Repo.Name}}/labels" class="inline"> | |
| 10 | 10 | <input type="hidden" name="name" value="{{.Name}}"> |
| 11 | 11 | <input type="text" name="color" value="{{.Color}}" aria-label="Colour for {{.Name}}" placeholder="rrggbb" size="8"> |
| 12 | 12 | <button type="submit" class="btn">Save</button> |
| 13 | </form>{{else}}<span class="mono">{{if .Color}}{{.Color}}{{else}}—{{end}}</span>{{end}}</td> | |
| 13 | </form>{{else}}<span class="mono">{{if .Color}}{{.Color}}{{else}}—{{end}}</span>{{end}}</td>{{end}} | |
| 14 | 14 | <td>{{.Issues}}</td> |
| 15 | 15 | <td class="act">{{if and $.CanWrite (not .Org)}}<form method="post" action="/{{$.Repo.OwnerName}}/{{$.Repo.Name}}/labels" class="inline"> |
| 16 | 16 | <input type="hidden" name="action" value="remove"> |