mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-12-31 02:46:16 +01:00
fix tag count by including type in grouping
This commit is contained in:
@@ -224,10 +224,10 @@ func (r *JobRepository) CountTags(user *schema.User) (tags []schema.Tag, counts
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query and Count Jobs with attached Tags
|
// Query and Count Jobs with attached Tags
|
||||||
q := sq.Select("t.tag_name, t.id, count(jt.tag_id)").
|
q := sq.Select("t.tag_type, t.tag_name, t.id, count(jt.tag_id)").
|
||||||
From("tag t").
|
From("tag t").
|
||||||
LeftJoin("jobtag jt ON t.id = jt.tag_id").
|
LeftJoin("jobtag jt ON t.id = jt.tag_id").
|
||||||
GroupBy("t.tag_name")
|
GroupBy("t.tag_type, t.tag_name")
|
||||||
|
|
||||||
// Build scope list for filtering
|
// Build scope list for filtering
|
||||||
var scopeBuilder strings.Builder
|
var scopeBuilder strings.Builder
|
||||||
@@ -260,14 +260,15 @@ func (r *JobRepository) CountTags(user *schema.User) (tags []schema.Tag, counts
|
|||||||
|
|
||||||
counts = make(map[string]int)
|
counts = make(map[string]int)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
var tagType string
|
||||||
var tagName string
|
var tagName string
|
||||||
var tagId int
|
var tagId int
|
||||||
var count int
|
var count int
|
||||||
if err = rows.Scan(&tagName, &tagId, &count); err != nil {
|
if err = rows.Scan(&tagType, &tagName, &tagId, &count); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
// Use tagId as second Map-Key component to differentiate tags with identical names
|
// Use tagId as second Map-Key component to differentiate tags with identical names
|
||||||
counts[fmt.Sprint(tagName, tagId)] = count
|
counts[fmt.Sprint(tagType, tagName, tagId)] = count
|
||||||
}
|
}
|
||||||
err = rows.Err()
|
err = rows.Err()
|
||||||
|
|
||||||
|
|||||||
@@ -205,13 +205,13 @@ func setupTaglistRoute(i InfoType, r *http.Request) InfoType {
|
|||||||
"id": tag.ID,
|
"id": tag.ID,
|
||||||
"name": tag.Name,
|
"name": tag.Name,
|
||||||
"scope": tag.Scope,
|
"scope": tag.Scope,
|
||||||
"count": counts[fmt.Sprint(tag.Name, tag.ID)],
|
"count": counts[fmt.Sprint(tag.Type, tag.Name, tag.ID)],
|
||||||
}
|
}
|
||||||
tagMap[tag.Type] = append(tagMap[tag.Type], tagItem)
|
tagMap[tag.Type] = append(tagMap[tag.Type], tagItem)
|
||||||
}
|
}
|
||||||
} else if userAuthlevel < 4 && userAuthlevel >= 2 { // User+ : Show global and admin scope only if at least 1 tag used, private scope regardless of count
|
} else if userAuthlevel < 4 && userAuthlevel >= 2 { // User+ : Show global and admin scope only if at least 1 tag used, private scope regardless of count
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
tagCount := counts[fmt.Sprint(tag.Name, tag.ID)]
|
tagCount := counts[fmt.Sprint(tag.Type, tag.Name, tag.ID)]
|
||||||
if ((tag.Scope == "global" || tag.Scope == "admin") && tagCount >= 1) || (tag.Scope != "global" && tag.Scope != "admin") {
|
if ((tag.Scope == "global" || tag.Scope == "admin") && tagCount >= 1) || (tag.Scope != "global" && tag.Scope != "admin") {
|
||||||
tagItem := map[string]interface{}{
|
tagItem := map[string]interface{}{
|
||||||
"id": tag.ID,
|
"id": tag.ID,
|
||||||
|
|||||||
Reference in New Issue
Block a user