refactor: change Status.Order to Status.Position
Change Status.Order to Status.Position, and the ByStatusOrder type to ByStatusPosition to make it clearer that status' are ordered by their position on the Kanban board.
This commit is contained in:
parent
e13d3e2085
commit
3169d341d2
4 changed files with 64 additions and 64 deletions
|
@ -84,7 +84,7 @@ func (b *Board) StatusList() ([]Status, error) {
|
||||||
statuses[ind] = status
|
statuses[ind] = status
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(ByStatusOrder(statuses))
|
sort.Sort(ByStatusPosition(statuses))
|
||||||
|
|
||||||
return statuses, nil
|
return statuses, nil
|
||||||
}
|
}
|
||||||
|
@ -117,10 +117,10 @@ type StatusArgs struct {
|
||||||
// CreateStatus creates a status in the db.
|
// CreateStatus creates a status in the db.
|
||||||
func (b *Board) CreateStatus(args StatusArgs) error {
|
func (b *Board) CreateStatus(args StatusArgs) error {
|
||||||
status := Status{
|
status := Status{
|
||||||
ID: -1,
|
ID: -1,
|
||||||
Name: args.Name,
|
Name: args.Name,
|
||||||
Order: args.Order,
|
Position: args.Order,
|
||||||
CardIds: nil,
|
CardIds: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := db.Write(b.db, db.StatusBucket, &status); err != nil {
|
if _, err := db.Write(b.db, db.StatusBucket, &status); err != nil {
|
||||||
|
@ -147,7 +147,7 @@ func (b *Board) UpdateStatus(args UpdateStatusArgs) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.Order > 0 {
|
if args.Order > 0 {
|
||||||
status.Order = args.Order
|
status.Position = args.Order
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := db.Write(b.db, db.StatusBucket, &status); err != nil {
|
if _, err := db.Write(b.db, db.StatusBucket, &status); err != nil {
|
||||||
|
|
|
@ -6,10 +6,10 @@ import (
|
||||||
|
|
||||||
// Status represents the status of the Kanban board.
|
// Status represents the status of the Kanban board.
|
||||||
type Status struct {
|
type Status struct {
|
||||||
ID int
|
ID int
|
||||||
Name string
|
Name string
|
||||||
CardIds []int
|
CardIds []int
|
||||||
Order int
|
Position int
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateID updates the ID of the Status value.
|
// UpdateID updates the ID of the Status value.
|
||||||
|
@ -79,41 +79,41 @@ func (s *Status) RemoveCardID(cardID int) {
|
||||||
s.CardIds = append(s.CardIds[:ind], s.CardIds[ind+1:]...)
|
s.CardIds = append(s.CardIds[:ind], s.CardIds[ind+1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByStatusOrder implements sort.Interface for []Status based on the Order field.
|
// ByStatusPosition implements sort.Interface for []Status based on the status' position on the Kanban board.
|
||||||
type ByStatusOrder []Status
|
type ByStatusPosition []Status
|
||||||
|
|
||||||
func (s ByStatusOrder) Len() int {
|
func (s ByStatusPosition) Len() int {
|
||||||
return len(s)
|
return len(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s ByStatusOrder) Swap(i, j int) {
|
func (s ByStatusPosition) Swap(i, j int) {
|
||||||
s[i], s[j] = s[j], s[i]
|
s[i], s[j] = s[j], s[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s ByStatusOrder) Less(i, j int) bool {
|
func (s ByStatusPosition) Less(i, j int) bool {
|
||||||
return s[i].Order < s[j].Order
|
return s[i].Position < s[j].Position
|
||||||
}
|
}
|
||||||
|
|
||||||
// defaultStatusList returns the default list of statuses.
|
// defaultStatusList returns the default list of statuses.
|
||||||
func defaultStatusList() []Status {
|
func defaultStatusList() []Status {
|
||||||
return []Status{
|
return []Status{
|
||||||
{
|
{
|
||||||
ID: -1,
|
ID: -1,
|
||||||
Name: "To Do",
|
Name: "To Do",
|
||||||
Order: 1,
|
Position: 1,
|
||||||
CardIds: nil,
|
CardIds: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: -1,
|
ID: -1,
|
||||||
Name: "Doing",
|
Name: "Doing",
|
||||||
Order: 2,
|
Position: 2,
|
||||||
CardIds: nil,
|
CardIds: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: -1,
|
ID: -1,
|
||||||
Name: "Done",
|
Name: "Done",
|
||||||
Order: 3,
|
Position: 3,
|
||||||
CardIds: nil,
|
CardIds: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,10 +103,10 @@ func testUpdateStatus(kanban board.Board, statusID int, newName string) func(t *
|
||||||
}
|
}
|
||||||
|
|
||||||
want := board.Status{
|
want := board.Status{
|
||||||
ID: statusID,
|
ID: statusID,
|
||||||
Name: newName,
|
Name: newName,
|
||||||
CardIds: nil,
|
CardIds: nil,
|
||||||
Order: 2,
|
Position: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(status, want) {
|
if !reflect.DeepEqual(status, want) {
|
||||||
|
|
|
@ -81,28 +81,28 @@ func testWriteStatusList(t *testing.T, database *bolt.DB) {
|
||||||
|
|
||||||
newStatusList := []board.Status{
|
newStatusList := []board.Status{
|
||||||
{
|
{
|
||||||
ID: -1,
|
ID: -1,
|
||||||
Name: "Backlog",
|
Name: "Backlog",
|
||||||
CardIds: []int{1, 14, 9, 10},
|
CardIds: []int{1, 14, 9, 10},
|
||||||
Order: 1,
|
Position: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: -1,
|
ID: -1,
|
||||||
Name: "Next",
|
Name: "Next",
|
||||||
CardIds: []int{2, 5, 12},
|
CardIds: []int{2, 5, 12},
|
||||||
Order: 2,
|
Position: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: -1,
|
ID: -1,
|
||||||
Name: "In progress",
|
Name: "In progress",
|
||||||
CardIds: []int{3, 14},
|
CardIds: []int{3, 14},
|
||||||
Order: 3,
|
Position: 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: -1,
|
ID: -1,
|
||||||
Name: "Finished!",
|
Name: "Finished!",
|
||||||
CardIds: []int{4, 6, 7, 8, 11, 13},
|
CardIds: []int{4, 6, 7, 8, 11, 13},
|
||||||
Order: 4,
|
Position: 4,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,28 +143,28 @@ func testReadStatusList(t *testing.T, database *bolt.DB) {
|
||||||
|
|
||||||
want := []board.Status{
|
want := []board.Status{
|
||||||
{
|
{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Name: "Backlog",
|
Name: "Backlog",
|
||||||
CardIds: []int{1, 14, 9, 10},
|
CardIds: []int{1, 14, 9, 10},
|
||||||
Order: 1,
|
Position: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 2,
|
ID: 2,
|
||||||
Name: "Next",
|
Name: "Next",
|
||||||
CardIds: []int{2, 5, 12},
|
CardIds: []int{2, 5, 12},
|
||||||
Order: 2,
|
Position: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
Name: "In progress",
|
Name: "In progress",
|
||||||
CardIds: []int{3, 14},
|
CardIds: []int{3, 14},
|
||||||
Order: 3,
|
Position: 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 4,
|
ID: 4,
|
||||||
Name: "Finished!",
|
Name: "Finished!",
|
||||||
CardIds: []int{4, 6, 7, 8, 11, 13},
|
CardIds: []int{4, 6, 7, 8, 11, 13},
|
||||||
Order: 4,
|
Position: 4,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue