aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/issue.go23
-rw-r--r--models/issue_label.go21
-rw-r--r--models/issue_test.go12
3 files changed, 41 insertions, 15 deletions
diff --git a/models/issue.go b/models/issue.go
index baca512ab0..850346674b 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -1210,7 +1210,7 @@ type IssuesOptions struct {
PageSize int
IsClosed util.OptionalBool
IsPull util.OptionalBool
- Labels string
+ LabelIDs []int64
SortType string
IssueIDs []int64
}
@@ -1289,15 +1289,10 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) error {
sess.And("issue.is_pull=?", false)
}
- if len(opts.Labels) > 0 && opts.Labels != "0" {
- labelIDs, err := base.StringsToInt64s(strings.Split(opts.Labels, ","))
- if err != nil {
- return err
- }
- if len(labelIDs) > 0 {
- sess.
- Join("INNER", "issue_label", "issue.id = issue_label.issue_id").
- In("issue_label.label_id", labelIDs)
+ if opts.LabelIDs != nil {
+ for i, labelID := range opts.LabelIDs {
+ sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
+ fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
}
}
return nil
@@ -1475,9 +1470,11 @@ func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) {
labelIDs, err := base.StringsToInt64s(strings.Split(opts.Labels, ","))
if err != nil {
log.Warn("Malformed Labels argument: %s", opts.Labels)
- } else if len(labelIDs) > 0 {
- sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").
- In("issue_label.label_id", labelIDs)
+ } else {
+ for i, labelID := range labelIDs {
+ sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
+ fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
+ }
}
}
diff --git a/models/issue_label.go b/models/issue_label.go
index bf61fcaeca..6adb4eedcb 100644
--- a/models/issue_label.go
+++ b/models/issue_label.go
@@ -69,6 +69,8 @@ type Label struct {
NumClosedIssues int
NumOpenIssues int `xorm:"-"`
IsChecked bool `xorm:"-"`
+ QueryString string
+ IsSelected bool
}
// APIFormat converts a Label to the api.Label format
@@ -85,6 +87,25 @@ func (label *Label) CalOpenIssues() {
label.NumOpenIssues = label.NumIssues - label.NumClosedIssues
}
+// LoadSelectedLabelsAfterClick calculates the set of selected labels when a label is clicked
+func (label *Label) LoadSelectedLabelsAfterClick(currentSelectedLabels []int64) {
+ var labelQuerySlice []string
+ labelSelected := false
+ labelID := strconv.FormatInt(label.ID, 10)
+ for _, s := range currentSelectedLabels {
+ if s == label.ID {
+ labelSelected = true
+ } else if s > 0 {
+ labelQuerySlice = append(labelQuerySlice, strconv.FormatInt(s, 10))
+ }
+ }
+ if !labelSelected {
+ labelQuerySlice = append(labelQuerySlice, labelID)
+ }
+ label.IsSelected = labelSelected
+ label.QueryString = strings.Join(labelQuerySlice, ",")
+}
+
// ForegroundColor calculates the text color for labels based
// on their background color.
func (label *Label) ForegroundColor() template.CSS {
diff --git a/models/issue_test.go b/models/issue_test.go
index d98debb178..3bda3304c3 100644
--- a/models/issue_test.go
+++ b/models/issue_test.go
@@ -193,11 +193,19 @@ func TestIssues(t *testing.T) {
},
{
IssuesOptions{
- Labels: "1,2",
+ LabelIDs: []int64{1},
Page: 1,
PageSize: 4,
},
- []int64{5, 2, 1},
+ []int64{2, 1},
+ },
+ {
+ IssuesOptions{
+ LabelIDs: []int64{1, 2},
+ Page: 1,
+ PageSize: 4,
+ },
+ []int64{}, // issues with **both** label 1 and 2, none of these issues matches, TODO: add more tests
},
} {
issues, err := Issues(&test.Opts)