|
|
@ -12,6 +12,7 @@ import ( |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db" |
|
|
|
"code.gitea.io/gitea/models/db" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/container" |
|
|
|
"code.gitea.io/gitea/modules/label" |
|
|
|
"code.gitea.io/gitea/modules/label" |
|
|
|
"code.gitea.io/gitea/modules/optional" |
|
|
|
"code.gitea.io/gitea/modules/optional" |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
@ -143,37 +144,32 @@ func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) { |
|
|
|
|
|
|
|
|
|
|
|
// LoadSelectedLabelsAfterClick calculates the set of selected labels when a label is clicked
|
|
|
|
// LoadSelectedLabelsAfterClick calculates the set of selected labels when a label is clicked
|
|
|
|
func (l *Label) LoadSelectedLabelsAfterClick(currentSelectedLabels []int64, currentSelectedExclusiveScopes []string) { |
|
|
|
func (l *Label) LoadSelectedLabelsAfterClick(currentSelectedLabels []int64, currentSelectedExclusiveScopes []string) { |
|
|
|
labelQuerySlice := []int64{} |
|
|
|
labelQueryParams := container.Set[string]{} |
|
|
|
labelSelected := false |
|
|
|
labelSelected := false |
|
|
|
labelScope := l.ExclusiveScope() |
|
|
|
exclusiveScope := l.ExclusiveScope() |
|
|
|
for i, s := range currentSelectedLabels { |
|
|
|
for i, curSel := range currentSelectedLabels { |
|
|
|
if s == l.ID { |
|
|
|
if curSel == l.ID { |
|
|
|
labelSelected = true |
|
|
|
labelSelected = true |
|
|
|
} else if -s == l.ID { |
|
|
|
} else if -curSel == l.ID { |
|
|
|
labelSelected = true |
|
|
|
labelSelected = true |
|
|
|
l.IsExcluded = true |
|
|
|
l.IsExcluded = true |
|
|
|
} else if s != 0 { |
|
|
|
} else if curSel != 0 { |
|
|
|
// Exclude other labels in the same scope from selection
|
|
|
|
// Exclude other labels in the same scope from selection
|
|
|
|
if s < 0 || labelScope == "" || labelScope != currentSelectedExclusiveScopes[i] { |
|
|
|
if curSel < 0 || exclusiveScope == "" || exclusiveScope != currentSelectedExclusiveScopes[i] { |
|
|
|
labelQuerySlice = append(labelQuerySlice, s) |
|
|
|
labelQueryParams.Add(strconv.FormatInt(curSel, 10)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !labelSelected { |
|
|
|
if !labelSelected { |
|
|
|
labelQuerySlice = append(labelQuerySlice, l.ID) |
|
|
|
labelQueryParams.Add(strconv.FormatInt(l.ID, 10)) |
|
|
|
} |
|
|
|
} |
|
|
|
l.IsSelected = labelSelected |
|
|
|
l.IsSelected = labelSelected |
|
|
|
|
|
|
|
|
|
|
|
// Sort and deduplicate the ids to avoid the crawlers asking for the
|
|
|
|
// Sort and deduplicate the ids to avoid the crawlers asking for the
|
|
|
|
// same thing with simply a different order of parameters
|
|
|
|
// same thing with simply a different order of parameters
|
|
|
|
slices.Sort(labelQuerySlice) |
|
|
|
labelQuerySliceStrings := labelQueryParams.Values() |
|
|
|
labelQuerySlice = slices.Compact(labelQuerySlice) |
|
|
|
slices.Sort(labelQuerySliceStrings) // the sort is still needed because the underlying map of Set doesn't guarantee order
|
|
|
|
// Quick conversion (strings.Join() doesn't accept slices of Int64)
|
|
|
|
|
|
|
|
labelQuerySliceStrings := make([]string, len(labelQuerySlice)) |
|
|
|
|
|
|
|
for i, x := range labelQuerySlice { |
|
|
|
|
|
|
|
labelQuerySliceStrings[i] = strconv.FormatInt(x, 10) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
l.QueryString = strings.Join(labelQuerySliceStrings, ",") |
|
|
|
l.QueryString = strings.Join(labelQuerySliceStrings, ",") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -187,7 +183,7 @@ func (l *Label) BelongsToRepo() bool { |
|
|
|
return l.RepoID > 0 |
|
|
|
return l.RepoID > 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Return scope substring of label name, or empty string if none exists
|
|
|
|
// ExclusiveScope returns scope substring of label name, or empty string if none exists
|
|
|
|
func (l *Label) ExclusiveScope() string { |
|
|
|
func (l *Label) ExclusiveScope() string { |
|
|
|
if !l.Exclusive { |
|
|
|
if !l.Exclusive { |
|
|
|
return "" |
|
|
|
return "" |
|
|
|