Colors for lists and namespaces (#155)
Add Hex Color properties migration Add Hex Color properties Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/155
This commit is contained in:
parent
35f05cbbec
commit
7b619bd084
4 changed files with 101 additions and 0 deletions
45
pkg/migration/20200322214440.go
Normal file
45
pkg/migration/20200322214440.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2020 Vikunja and contriubtors. All rights reserved.
|
||||
//
|
||||
// This file is part of Vikunja.
|
||||
//
|
||||
// Vikunja is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Vikunja is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Vikunja. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package migration
|
||||
|
||||
import (
|
||||
"src.techknowlogick.com/xormigrate"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
type namespace20200322214440 struct {
|
||||
HexColor string `xorm:"varchar(6) null"`
|
||||
}
|
||||
|
||||
func (s namespace20200322214440) TableName() string {
|
||||
return "namespaces"
|
||||
}
|
||||
|
||||
func init() {
|
||||
migrations = append(migrations, &xormigrate.Migration{
|
||||
ID: "20200322214440",
|
||||
Description: "Add hex color property to namepaces",
|
||||
Migrate: func(tx *xorm.Engine) error {
|
||||
return tx.Sync2(namespace20200322214440{})
|
||||
},
|
||||
Rollback: func(tx *xorm.Engine) error {
|
||||
return tx.DropTables(namespace20200322214440{})
|
||||
},
|
||||
})
|
||||
|
||||
}
|
45
pkg/migration/20200322214624.go
Normal file
45
pkg/migration/20200322214624.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2020 Vikunja and contriubtors. All rights reserved.
|
||||
//
|
||||
// This file is part of Vikunja.
|
||||
//
|
||||
// Vikunja is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Vikunja is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Vikunja. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package migration
|
||||
|
||||
import (
|
||||
"src.techknowlogick.com/xormigrate"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
type list20200322214624 struct {
|
||||
HexColor string `xorm:"varchar(6) null"`
|
||||
}
|
||||
|
||||
func (s list20200322214624) TableName() string {
|
||||
return "list"
|
||||
}
|
||||
|
||||
func init() {
|
||||
migrations = append(migrations, &xormigrate.Migration{
|
||||
ID: "20200322214624",
|
||||
Description: "Add hex color property to list",
|
||||
Migrate: func(tx *xorm.Engine) error {
|
||||
return tx.Sync2(list20200322214624{})
|
||||
},
|
||||
Rollback: func(tx *xorm.Engine) error {
|
||||
return tx.DropTables(list20200322214624{})
|
||||
},
|
||||
})
|
||||
|
||||
}
|
|
@ -34,6 +34,8 @@ type List struct {
|
|||
Description string `xorm:"longtext null" json:"description"`
|
||||
// The unique list short identifier. Used to build task identifiers.
|
||||
Identifier string `xorm:"varchar(10) null" json:"identifier" valid:"runelength(0|10)" minLength:"0" maxLength:"10"`
|
||||
// The hex color of this list
|
||||
HexColor string `xorm:"varchar(6) null" json:"hex_color" valid:"runelength(0|6)" maxLength:"6"`
|
||||
|
||||
OwnerID int64 `xorm:"int(11) INDEX not null" json:"-"`
|
||||
NamespaceID int64 `xorm:"int(11) INDEX not null" json:"-" param:"namespace"`
|
||||
|
@ -382,6 +384,9 @@ func CreateOrUpdateList(list *List) (err error) {
|
|||
if list.Identifier != "" {
|
||||
colsToUpdate = append(colsToUpdate, "identifier")
|
||||
}
|
||||
if list.HexColor != "" {
|
||||
colsToUpdate = append(colsToUpdate, "hex_color")
|
||||
}
|
||||
|
||||
_, err = x.
|
||||
ID(list.ID).
|
||||
|
|
|
@ -36,6 +36,9 @@ type Namespace struct {
|
|||
Description string `xorm:"longtext null" json:"description"`
|
||||
OwnerID int64 `xorm:"int(11) not null INDEX" json:"-"`
|
||||
|
||||
// The hex color of this namespace
|
||||
HexColor string `xorm:"varchar(6) null" json:"hex_color" valid:"runelength(0|6)" maxLength:"6"`
|
||||
|
||||
// Whether or not a namespace is archived.
|
||||
IsArchived bool `xorm:"not null default false" json:"is_archived" query:"is_archived"`
|
||||
|
||||
|
@ -461,6 +464,9 @@ func (n *Namespace) Update() (err error) {
|
|||
if n.Description != "" {
|
||||
colsToUpdate = append(colsToUpdate, "description")
|
||||
}
|
||||
if n.HexColor != "" {
|
||||
colsToUpdate = append(colsToUpdate, "hex_color")
|
||||
}
|
||||
|
||||
// Do the actual update
|
||||
_, err = x.
|
||||
|
|
Loading…
Reference in a new issue