Skip to content

Commit c0d41b1

Browse files
lafrikslunny
authored andcommittedMar 13, 2018
Add label descriptions (#3662)
* Add label descriptions * Add default descriptions to label template
1 parent ad33730 commit c0d41b1

File tree

14 files changed

+109
-34
lines changed

14 files changed

+109
-34
lines changed
 

‎models/issue_label.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ import (
1919
var labelColorPattern = regexp.MustCompile("#([a-fA-F0-9]{6})")
2020

2121
// GetLabelTemplateFile loads the label template file by given name,
22-
// then parses and returns a list of name-color pairs.
23-
func GetLabelTemplateFile(name string) ([][2]string, error) {
22+
// then parses and returns a list of name-color pairs and optionally description.
23+
func GetLabelTemplateFile(name string) ([][3]string, error) {
2424
data, err := getRepoInitFile("label", name)
2525
if err != nil {
2626
return nil, fmt.Errorf("getRepoInitFile: %v", err)
2727
}
2828

2929
lines := strings.Split(string(data), "\n")
30-
list := make([][2]string, 0, len(lines))
30+
list := make([][3]string, 0, len(lines))
3131
for i := 0; i < len(lines); i++ {
3232
line := strings.TrimSpace(lines[i])
3333
if len(line) == 0 {
3434
continue
3535
}
3636

37-
fields := strings.SplitN(line, " ", 2)
37+
parts := strings.SplitN(line, ";", 2)
38+
39+
fields := strings.SplitN(parts[0], " ", 2)
3840
if len(fields) != 2 {
3941
return nil, fmt.Errorf("line is malformed: %s", line)
4042
}
@@ -43,8 +45,14 @@ func GetLabelTemplateFile(name string) ([][2]string, error) {
4345
return nil, fmt.Errorf("bad HTML color code in line: %s", line)
4446
}
4547

48+
var description string
49+
50+
if len(parts) > 1 {
51+
description = strings.TrimSpace(parts[1])
52+
}
53+
4654
fields[1] = strings.TrimSpace(fields[1])
47-
list = append(list, [2]string{fields[1], fields[0]})
55+
list = append(list, [3]string{fields[1], fields[0], description})
4856
}
4957

5058
return list, nil
@@ -55,6 +63,7 @@ type Label struct {
5563
ID int64 `xorm:"pk autoincr"`
5664
RepoID int64 `xorm:"INDEX"`
5765
Name string
66+
Description string
5867
Color string `xorm:"VARCHAR(7)"`
5968
NumIssues int
6069
NumClosedIssues int

‎models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ var migrations = []Migration{
168168
NewMigration("remove is_owner, num_teams columns from org_user", removeIsOwnerColumnFromOrgUser),
169169
// v57 -> v58
170170
NewMigration("add closed_unix column for issues", addIssueClosedTime),
171+
// v58 -> v59
172+
NewMigration("add label descriptions", addLabelsDescriptions),
171173
}
172174

173175
// Migrate database to current version

‎models/migrations/v58.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/go-xorm/xorm"
11+
)
12+
13+
func addLabelsDescriptions(x *xorm.Engine) error {
14+
type Label struct {
15+
Description string
16+
}
17+
18+
if err := x.Sync2(new(Label)); err != nil {
19+
return fmt.Errorf("Sync2: %v", err)
20+
}
21+
return nil
22+
}

‎modules/auth/repo_form.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,10 @@ func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors
310310

311311
// CreateLabelForm form for creating label
312312
type CreateLabelForm struct {
313-
ID int64
314-
Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_name"`
315-
Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
313+
ID int64
314+
Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
315+
Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
316+
Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
316317
}
317318

318319
// Validate validates the fields

‎options/label/Default

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#ee0701 bug
2-
#cccccc duplicate
3-
#84b6eb enhancement
4-
#128a0c help wanted
5-
#e6e6e6 invalid
6-
#cc317c question
7-
#ffffff wontfix
1+
#ee0701 bug ; Something is not working
2+
#cccccc duplicate ; This issue or pull request already exists
3+
#84b6eb enhancement ; New feature
4+
#128a0c help wanted ; Need some help
5+
#e6e6e6 invalid ; Something is wrong
6+
#cc317c question ; More information is needed
7+
#ffffff wontfix ; This won't be fixed

‎options/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ issues.no_ref = No Branch/Tag Specified
627627
issues.create = Create Issue
628628
issues.new_label = New Label
629629
issues.new_label_placeholder = Label name…
630+
issues.new_label_desc_placeholder = Description…
630631
issues.create_label = Create Label
631632
issues.label_templates.title = Load a predefined set of labels
632633
issues.label_templates.info = There are not any labels yet. You can click on the "New Label" button above to create one or use a predefined set below.
@@ -697,6 +698,7 @@ issues.edit = Edit
697698
issues.cancel = Cancel
698699
issues.save = Save
699700
issues.label_title = Label name
701+
issues.label_description = Label description
700702
issues.label_color = Label color
701703
issues.label_count = %d labels
702704
issues.label_open_issues = %d open issues

‎public/css/index.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/js/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ function initRepository() {
491491
$('.edit-label-button').click(function () {
492492
$('#label-modal-id').val($(this).data('id'));
493493
$('.edit-label .new-label-input').val($(this).data('title'));
494+
$('.edit-label .new-label-desc-input').val($(this).data('description'));
494495
$('.edit-label .color-picker').val($(this).data('color'));
495496
$('.minicolors-swatch-color').css("background-color", $(this).data('color'));
496497
$('.edit-label.modal').modal({

‎public/less/_repository.less

+11
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@
134134
}
135135
}
136136

137+
.select-label {
138+
.item {
139+
max-width: 250px;
140+
overflow: hidden;
141+
text-overflow: ellipsis;
142+
}
143+
.desc {
144+
padding-left: 16px;
145+
}
146+
}
147+
137148
.ui.tabs {
138149
&.container {
139150
margin-top: 14px;

‎routers/repo/issue_label.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
4242
labels := make([]*models.Label, len(list))
4343
for i := 0; i < len(list); i++ {
4444
labels[i] = &models.Label{
45-
RepoID: ctx.Repo.Repository.ID,
46-
Name: list[i][0],
47-
Color: list[i][1],
45+
RepoID: ctx.Repo.Repository.ID,
46+
Name: list[i][0],
47+
Description: list[i][2],
48+
Color: list[i][1],
4849
}
4950
}
5051
if err := models.NewLabels(labels...); err != nil {
@@ -81,9 +82,10 @@ func NewLabel(ctx *context.Context, form auth.CreateLabelForm) {
8182
}
8283

8384
l := &models.Label{
84-
RepoID: ctx.Repo.Repository.ID,
85-
Name: form.Title,
86-
Color: form.Color,
85+
RepoID: ctx.Repo.Repository.ID,
86+
Name: form.Title,
87+
Description: form.Description,
88+
Color: form.Color,
8789
}
8890
if err := models.NewLabel(l); err != nil {
8991
ctx.ServerError("NewLabel", err)
@@ -106,6 +108,7 @@ func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
106108
}
107109

108110
l.Name = form.Title
111+
l.Description = form.Description
109112
l.Color = form.Color
110113
if err := models.UpdateLabel(l); err != nil {
111114
ctx.ServerError("UpdateLabel", err)

‎templates/repo/issue/labels.tmpl

+31-8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
<form class="ui form" action="{{$.RepoLink}}/labels/new" method="post">
1515
{{.CsrfTokenHtml}}
1616
<div class="ui grid">
17-
<div class="five wide column">
17+
<div class="three wide column">
1818
<div class="ui small input">
1919
<input class="new-label-input" name="title" placeholder="{{.i18n.Tr "repo.issues.new_label_placeholder"}}" autofocus required>
2020
</div>
2121
</div>
22+
<div class="five wide column">
23+
<div class="ui small fluid input">
24+
<input class="new-label-desc-input" name="description" placeholder="{{.i18n.Tr "repo.issues.new_label_desc_placeholder"}}">
25+
</div>
26+
</div>
2227
<div class="color picker column">
2328
<input class="color-picker" name="color" value="#70c24a" required>
2429
</div>
@@ -85,14 +90,27 @@
8590
</div>
8691
{{end}}
8792

93+
<div class="ui divider"></div>
94+
8895
{{range .Labels}}
8996
<li class="item">
90-
<div class="ui label" style="color: {{.ForegroundColor}}; background-color: {{.Color}}"><i class="octicon octicon-tag"></i> {{.Name}}</div>
91-
{{if $.IsRepositoryWriter}}
92-
<a class="ui right delete-button" href="#" data-url="{{$.RepoLink}}/labels/delete" data-id="{{.ID}}"><i class="octicon octicon-trashcan"></i> {{$.i18n.Tr "repo.issues.label_delete"}}</a>
93-
<a class="ui right edit-label-button" href="#" data-id={{.ID}} data-title={{.Name}} data-color={{.Color}}><i class="octicon octicon-pencil"></i> {{$.i18n.Tr "repo.issues.label_edit"}}</a>
94-
{{end}}
95-
<a class="ui right open-issues" href="{{$.RepoLink}}/issues?labels={{.ID}}"><i class="octicon octicon-issue-opened"></i> {{$.i18n.Tr "repo.issues.label_open_issues" .NumOpenIssues}}</a>
97+
<div class="ui grid">
98+
<div class="three wide column">
99+
<div class="ui label" style="color: {{.ForegroundColor}}; background-color: {{.Color}}"><i class="octicon octicon-tag"></i> {{.Name}}</div>
100+
</div>
101+
<div class="seven wide column">
102+
{{.Description}}
103+
</div>
104+
<div class="three wide column">
105+
<a class="ui right open-issues" href="{{$.RepoLink}}/issues?labels={{.ID}}"><i class="octicon octicon-issue-opened"></i> {{$.i18n.Tr "repo.issues.label_open_issues" .NumOpenIssues}}</a>
106+
</div>
107+
<div class="three wide column">
108+
{{if $.IsRepositoryWriter}}
109+
<a class="ui right delete-button" href="#" data-url="{{$.RepoLink}}/labels/delete" data-id="{{.ID}}"><i class="octicon octicon-trashcan"></i> {{$.i18n.Tr "repo.issues.label_delete"}}</a>
110+
<a class="ui right edit-label-button" href="#" data-id="{{.ID}}" data-title="{{.Name}}" data-description="{{.Description}}" data-color={{.Color}}><i class="octicon octicon-pencil"></i> {{$.i18n.Tr "repo.issues.label_edit"}}</a>
111+
{{end}}
112+
</div>
113+
</div>
96114
</li>
97115
{{end}}
98116
</div>
@@ -129,11 +147,16 @@
129147
{{.CsrfTokenHtml}}
130148
<input id="label-modal-id" name="id" type="hidden">
131149
<div class="ui grid">
132-
<div class="five wide column">
150+
<div class="three wide column">
133151
<div class="ui small input">
134152
<input class="new-label-input" name="title" placeholder="{{.i18n.Tr "repo.issues.new_label_placeholder"}}" autofocus required>
135153
</div>
136154
</div>
155+
<div class="five wide column">
156+
<div class="ui small fluid input">
157+
<input class="new-label-desc-input" name="description" placeholder="{{.i18n.Tr "repo.issues.new_label_desc_placeholder"}}">
158+
</div>
159+
</div>
137160
<div class="color picker column">
138161
<input class="color-picker" name="color" value="#70c24a" required>
139162
</div>

‎templates/repo/issue/list.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
<a class="ui label" href="{{$.RepoLink}}/src/branch/{{.Ref}}">{{.Ref}}</a>
192192
{{end}}
193193
{{range .Labels}}
194-
<a class="ui label" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}">{{.Name}}</a>
194+
<a class="ui label" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}" title="{{.Description}}">{{.Name}}</a>
195195
{{end}}
196196

197197
{{if .NumComments}}

‎templates/repo/issue/view_content/sidebar.tmpl

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
<div class="filter menu" data-action="update" data-issue-id="{{$.Issue.ID}}" data-update-url="{{$.RepoLink}}/issues/labels">
1111
<div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_labels"}}</div>
1212
{{range .Labels}}
13-
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}"><span class="octicon {{if .IsChecked}}octicon-check{{end}}"></span><span class="label color" style="background-color: {{.Color}}"></span> {{.Name}}</a>
13+
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}"><span class="octicon {{if .IsChecked}}octicon-check{{end}}"></span><span class="label color" style="background-color: {{.Color}}"></span> {{.Name}}
14+
{{if .Description }}<br><small class="desc">{{.Description}}</small>{{end}}</a>
1415
{{end}}
1516
</div>
1617
</div>
1718
<div class="ui labels list">
1819
<span class="no-select item {{if .HasSelectedLabel}}hide{{end}}">{{.i18n.Tr "repo.issues.new.no_label"}}</span>
1920
{{range .Labels}}
2021
<div class="item">
21-
<a class="ui label {{if not .IsChecked}}hide{{end}}" id="label_{{.ID}}" href="{{$.RepoLink}}/issues?labels={{.ID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}">{{.Name}}</a>
22+
<a class="ui label {{if not .IsChecked}}hide{{end}}" id="label_{{.ID}}" href="{{$.RepoLink}}/issues?labels={{.ID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}" title="{{.Description}}">{{.Name}}</a>
2223
</div>
2324

2425
{{end}}

‎templates/user/dashboard/issues.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
especially on mobile views. */}}
7272
<span style="line-height: 2.5">
7373
{{range .}}
74-
<a class="ui label" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}">{{.Name}}</a>
74+
<a class="ui label" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}" title="{{.Description}}">{{.Name}}</a>
7575
{{end}}
7676
</span>
7777
{{end}}

0 commit comments

Comments
 (0)
Please sign in to comment.