1
0

Add task filters for kanban

Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
kolaente
2020-12-22 12:38:05 +01:00
parent 2d4e2e452c
commit fa68e89c04
5 changed files with 262 additions and 39 deletions

View File

@ -48,6 +48,9 @@ type Bucket struct {
CreatedBy *user.User `xorm:"-" json:"created_by" valid:"-"`
CreatedByID int64 `xorm:"bigint not null" json:"-"`
// Including the task collection type so we can use task filters on kanban
TaskCollection `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`
web.CRUDable `xorm:"-" json:"-"`
}
@ -86,6 +89,11 @@ func getDefaultBucket(s *xorm.Session, listID int64) (bucket *Bucket, err error)
// @Produce json
// @Security JWTKeyAuth
// @Param id path int true "List Id"
// @Param filter_by query string false "The name of the field to filter by. Allowed values are all task properties. Task properties which are their own object require passing in the id of that entity. Accepts an array for multiple filters which will be chanied together, all supplied filter must match."
// @Param filter_value query string false "The value to filter for."
// @Param filter_comparator query string false "The comparator to use for a filter. Available values are `equals`, `greater`, `greater_equals`, `less`, `less_equals`, `like` and `in`. `in` expects comma-separated values in `filter_value`. Defaults to `equals`"
// @Param filter_concat query string false "The concatinator to use for filters. Available values are `and` or `or`. Defaults to `or`."
// @Param filter_include_nulls query string false "If set to true the result will include filtered fields whose value is set to `null`. Available values are `true` or `false`. Defaults to `false`."
// @Success 200 {array} models.Bucket "The buckets with their tasks"
// @Failure 500 {object} models.Message "Internal server error"
// @Router /lists/{id}/buckets [get]
@ -121,19 +129,16 @@ func (b *Bucket) ReadAll(auth web.Auth, search string, page int, perPage int) (r
}
// Get all tasks for this list
opts := &taskOptions{
sortby: []*sortParam{
{
sortBy: taskPropertyPosition,
orderBy: orderAscending,
},
},
}
tasks, _, _, err := getTasksForLists([]*List{{ID: b.ListID}}, auth, opts)
b.TaskCollection.ListID = b.ListID
b.TaskCollection.OrderBy = []string{string(orderAscending)}
b.TaskCollection.SortBy = []string{taskPropertyPosition}
ts, _, _, err := b.TaskCollection.ReadAll(auth, "", -1, 0)
if err != nil {
return
}
tasks := ts.([]*Task)
// Put all tasks in their buckets
// All tasks which are not associated to any bucket will have bucket id 0 which is the nil value for int64
// Since we created a bucked with that id at the beginning, all tasks should be in there.

View File

@ -25,43 +25,64 @@ import (
)
func TestBucket_ReadAll(t *testing.T) {
db.LoadAndAssertFixtures(t)
t.Run("normal", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
testuser := &user.User{ID: 1}
b := &Bucket{ListID: 1}
bucketsInterface, _, _, err := b.ReadAll(testuser, "", 0, 0)
assert.NoError(t, err)
testuser := &user.User{ID: 1}
b := &Bucket{ListID: 1}
bucketsInterface, _, _, err := b.ReadAll(testuser, "", 0, 0)
assert.NoError(t, err)
buckets, is := bucketsInterface.([]*Bucket)
assert.True(t, is)
buckets, is := bucketsInterface.([]*Bucket)
assert.True(t, is)
// Assert that we have a user for each bucket
assert.Equal(t, testuser.ID, buckets[0].CreatedBy.ID)
assert.Equal(t, testuser.ID, buckets[1].CreatedBy.ID)
assert.Equal(t, testuser.ID, buckets[2].CreatedBy.ID)
// Assert that we have a user for each bucket
assert.Equal(t, testuser.ID, buckets[0].CreatedBy.ID)
assert.Equal(t, testuser.ID, buckets[1].CreatedBy.ID)
assert.Equal(t, testuser.ID, buckets[2].CreatedBy.ID)
// Assert our three test buckets
assert.Len(t, buckets, 3)
// Assert our three test buckets
assert.Len(t, buckets, 3)
// Assert all tasks are in the right bucket
assert.Len(t, buckets[0].Tasks, 12)
assert.Len(t, buckets[1].Tasks, 3)
assert.Len(t, buckets[2].Tasks, 3)
// Assert all tasks are in the right bucket
assert.Len(t, buckets[0].Tasks, 12)
assert.Len(t, buckets[1].Tasks, 3)
assert.Len(t, buckets[2].Tasks, 3)
// Assert we have bucket 0, 1, 2, 3 but not 4 (that belongs to a different list)
assert.Equal(t, int64(1), buckets[0].ID)
assert.Equal(t, int64(2), buckets[1].ID)
assert.Equal(t, int64(3), buckets[2].ID)
// Assert we have bucket 0, 1, 2, 3 but not 4 (that belongs to a different list)
assert.Equal(t, int64(1), buckets[0].ID)
assert.Equal(t, int64(2), buckets[1].ID)
assert.Equal(t, int64(3), buckets[2].ID)
// Kinda assert all tasks are in the right buckets
assert.Equal(t, int64(1), buckets[0].Tasks[0].BucketID)
assert.Equal(t, int64(1), buckets[0].Tasks[1].BucketID)
assert.Equal(t, int64(2), buckets[1].Tasks[0].BucketID)
assert.Equal(t, int64(2), buckets[1].Tasks[1].BucketID)
assert.Equal(t, int64(2), buckets[1].Tasks[2].BucketID)
assert.Equal(t, int64(3), buckets[2].Tasks[0].BucketID)
assert.Equal(t, int64(3), buckets[2].Tasks[1].BucketID)
assert.Equal(t, int64(3), buckets[2].Tasks[2].BucketID)
// Kinda assert all tasks are in the right buckets
assert.Equal(t, int64(1), buckets[0].Tasks[0].BucketID)
assert.Equal(t, int64(1), buckets[0].Tasks[1].BucketID)
assert.Equal(t, int64(2), buckets[1].Tasks[0].BucketID)
assert.Equal(t, int64(2), buckets[1].Tasks[1].BucketID)
assert.Equal(t, int64(2), buckets[1].Tasks[2].BucketID)
assert.Equal(t, int64(3), buckets[2].Tasks[0].BucketID)
assert.Equal(t, int64(3), buckets[2].Tasks[1].BucketID)
assert.Equal(t, int64(3), buckets[2].Tasks[2].BucketID)
})
t.Run("filtered", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
testuser := &user.User{ID: 1}
b := &Bucket{
ListID: 1,
TaskCollection: TaskCollection{
FilterBy: []string{"title"},
FilterComparator: []string{"like"},
FilterValue: []string{"done"},
},
}
bucketsInterface, _, _, err := b.ReadAll(testuser, "", 0, 0)
assert.NoError(t, err)
buckets := bucketsInterface.([]*Bucket)
assert.Len(t, buckets, 3)
assert.Equal(t, int64(2), buckets[0].Tasks[0].ID)
})
}
func TestBucket_Delete(t *testing.T) {