Skip to content

Commit c278def

Browse files
committed
Use scoped label display and menu grouping also for non-exclusive labels
1 parent ebd797a commit c278def

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

models/issues/label.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,22 @@ func (label *Label) UseLightTextColor() bool {
190190
}
191191

192192
// Return scope substring of label name, or empty string if none exists
193-
func (label *Label) ExclusiveScope() string {
194-
if !label.Exclusive {
195-
return ""
196-
}
193+
func (label *Label) Scope() string {
197194
lastIndex := strings.LastIndex(label.Name, "/")
198195
if lastIndex == -1 || lastIndex == 0 || lastIndex == len(label.Name)-1 {
199196
return ""
200197
}
201198
return label.Name[:lastIndex]
202199
}
203200

201+
// Return scope for exclusive labels, or empty string if none exists
202+
func (label *Label) ExclusiveScope() string {
203+
if !label.Exclusive {
204+
return ""
205+
}
206+
return label.Scope()
207+
}
208+
204209
// NewLabel creates a new label
205210
func NewLabel(ctx context.Context, label *Label) error {
206211
if !LabelColorPattern.MatchString(label.Color) {

modules/templates/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ func RenderIssueTitle(ctx context.Context, text, urlPrefix string, metas map[str
809809

810810
// RenderLabel renders a label
811811
func RenderLabel(label *issues_model.Label) string {
812-
labelScope := label.ExclusiveScope()
812+
labelScope := label.Scope()
813813

814814
textColor := "#111"
815815
if label.UseLightTextColor() {

templates/repo/issue/labels/labels_selector_field.tmpl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,26 @@
1919
{{end}}
2020
<a class="no-select item" href="#">{{.locale.Tr "repo.issues.new.clear_labels"}}</a>
2121
{{if or .Labels .OrgLabels}}
22-
{{$previousExclusiveScope := "_no_scope"}}
22+
{{$previousScope := "_no_scope"}}
2323
{{range .Labels}}
24+
{{$scope := .Scope}}
2425
{{$exclusiveScope := .ExclusiveScope}}
25-
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
26+
{{if and (ne $previousScope "_no_scope") (ne $previousScope $scope)}}
2627
<div class="ui divider"></div>
2728
{{end}}
28-
{{$previousExclusiveScope = $exclusiveScope}}
29+
{{$previousScope = $scope}}
2930
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel .}}
3031
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji}}</small>{{end}}</a>
3132
{{end}}
3233
<div class="ui divider"></div>
33-
{{$previousExclusiveScope := "_no_scope"}}
34+
{{$previousScope := "_no_scope"}}
3435
{{range .OrgLabels}}
36+
{{$scope := .Scope}}
3537
{{$exclusiveScope := .ExclusiveScope}}
36-
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
38+
{{if and (ne $previousScope "_no_scope") (ne $previousScope $scope)}}
3739
<div class="ui divider"></div>
3840
{{end}}
39-
{{$previousExclusiveScope = $exclusiveScope}}
41+
{{$previousScope = $scope}}
4042
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel .}}
4143
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji}}</small>{{end}}</a>
4244
{{end}}

templates/repo/issue/list.tmpl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050
</div>
5151
<span class="info">{{.locale.Tr "repo.issues.filter_label_exclude" | Safe}}</span>
5252
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&milestone={{$.MilestoneID}}&project={{$.ProjectID}}&assignee={{$.AssigneeID}}&poster={{$.PosterID}}">{{.locale.Tr "repo.issues.filter_label_no_select"}}</a>
53-
{{$previousExclusiveScope := "_no_scope"}}
53+
{{$previousScope := "_no_scope"}}
5454
{{range .Labels}}
55-
{{$exclusiveScope := .ExclusiveScope}}
56-
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
55+
{{$scope := .Scope}}
56+
{{if and (ne $previousScope "_no_scope") (ne $previousScope $scope)}}
5757
<div class="ui divider"></div>
5858
{{end}}
59-
{{$previousExclusiveScope = $exclusiveScope}}
60-
<a class="item label-filter-item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{.QueryString}}&milestone={{$.MilestoneID}}&project={{$.ProjectID}}&assignee={{$.AssigneeID}}&poster={{$.PosterID}}" data-label-id="{{.ID}}">{{if .IsExcluded}}{{svg "octicon-circle-slash"}}{{else if .IsSelected}}{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel .}}</a>
59+
{{$previousScope = $scope}}
60+
<a class="item label-filter-item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{.QueryString}}&milestone={{$.MilestoneID}}&project={{$.ProjectID}}&assignee={{$.AssigneeID}}&poster={{$.PosterID}}" data-label-id="{{.ID}}">{{if .IsExcluded}}{{svg "octicon-circle-slash"}}{{else if .IsSelected}}{{if .ExclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel .}}</a>
6161
{{end}}
6262
</div>
6363
</div>
@@ -224,15 +224,15 @@
224224
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
225225
</span>
226226
<div class="menu">
227-
{{$previousExclusiveScope := "_no_scope"}}
227+
{{$previousScope := "_no_scope"}}
228228
{{range .Labels}}
229-
{{$exclusiveScope := .ExclusiveScope}}
230-
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
229+
{{$scope := .Scope}}
230+
{{if and (ne $previousScope "_no_scope") (ne $previousScope $scope)}}
231231
<div class="ui divider"></div>
232232
{{end}}
233-
{{$previousExclusiveScope = $exclusiveScope}}
233+
{{$previousScope = $scope}}
234234
<div class="item issue-action" data-action="toggle" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/labels">
235-
{{if contain $.SelLabelIDs .ID}}{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel .}}
235+
{{if contain $.SelLabelIDs .ID}}{{if .ExclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel .}}
236236
</div>
237237
{{end}}
238238
</div>

0 commit comments

Comments
 (0)