Enable searching labels by their ids
continuous-integration/drone/pr Build is failing Details

Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
kolaente 2020-12-21 22:02:26 +01:00
parent 89a2e00958
commit 4c7893cef3
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 20 additions and 1 deletions

View File

@ -17,6 +17,9 @@
package models
import (
"code.vikunja.io/api/pkg/log"
"strconv"
"strings"
"time"
"code.vikunja.io/api/pkg/user"
@ -171,13 +174,29 @@ func getLabelsByTaskIDs(opts *LabelByTaskIDsOptions) (ls []*labelWithTaskID, res
cond = builder.Or(cond, builder.Eq{"labels.created_by_id": opts.User.ID})
}
vals := strings.Split(opts.Search, ",")
ids := []int64{}
for _, val := range vals {
v, err := strconv.ParseInt(val, 10, 64)
if err != nil {
log.Debugf("Label search string part '%s' is not a number: %s", val, err)
continue
}
ids = append(ids, v)
}
if len(ids) > 0 {
cond = builder.And(cond, builder.In("labels.id", ids))
} else {
cond = builder.And(cond, &builder.Like{"labels.title", "%" + opts.Search + "%"})
}
limit, start := getLimitFromPageIndex(opts.Page, opts.PerPage)
query := x.Table("labels").
Select(selectStmt).
Join("LEFT", "label_task", "label_task.label_id = labels.id").
Where(cond).
And("labels.title LIKE ?", "%"+opts.Search+"%").
GroupBy(groupBy).
OrderBy("labels.id ASC")
if limit > 0 {