feat(views): (un)marshal custom project view mode types
This commit is contained in:
parent
a9020e976d
commit
652bf4b4ed
@ -18,12 +18,50 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProjectViewKind int
|
type ProjectViewKind int
|
||||||
|
|
||||||
|
func (p *ProjectViewKind) MarshalJSON() ([]byte, error) {
|
||||||
|
switch *p {
|
||||||
|
case ProjectViewKindList:
|
||||||
|
return []byte(`"list"`), nil
|
||||||
|
case ProjectViewKindGantt:
|
||||||
|
return []byte(`"gantt"`), nil
|
||||||
|
case ProjectViewKindTable:
|
||||||
|
return []byte(`"table"`), nil
|
||||||
|
case ProjectViewKindKanban:
|
||||||
|
return []byte(`"kanban"`), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return []byte(`null`), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProjectViewKind) UnmarshalJSON(bytes []byte) error {
|
||||||
|
var value string
|
||||||
|
err := json.Unmarshal(bytes, &value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch value {
|
||||||
|
case "list":
|
||||||
|
*p = ProjectViewKindList
|
||||||
|
case "gantt":
|
||||||
|
*p = ProjectViewKindGantt
|
||||||
|
case "table":
|
||||||
|
*p = ProjectViewKindTable
|
||||||
|
case "kanban":
|
||||||
|
*p = ProjectViewKindKanban
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("unkown project view kind: %s", bytes)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ProjectViewKindList ProjectViewKind = iota
|
ProjectViewKindList ProjectViewKind = iota
|
||||||
ProjectViewKindGantt
|
ProjectViewKindGantt
|
||||||
@ -39,6 +77,38 @@ const (
|
|||||||
BucketConfigurationModeFilter
|
BucketConfigurationModeFilter
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (p *BucketConfigurationModeKind) MarshalJSON() ([]byte, error) {
|
||||||
|
switch *p {
|
||||||
|
case BucketConfigurationModeNone:
|
||||||
|
return []byte(`"none"`), nil
|
||||||
|
case BucketConfigurationModeManual:
|
||||||
|
return []byte(`"manual"`), nil
|
||||||
|
case BucketConfigurationModeFilter:
|
||||||
|
return []byte(`"filter"`), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return []byte(`null`), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *BucketConfigurationModeKind) UnmarshalJSON(bytes []byte) error {
|
||||||
|
var value string
|
||||||
|
err := json.Unmarshal(bytes, &value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch value {
|
||||||
|
case "none":
|
||||||
|
*p = BucketConfigurationModeNone
|
||||||
|
case "manual":
|
||||||
|
*p = BucketConfigurationModeManual
|
||||||
|
case "filter":
|
||||||
|
*p = BucketConfigurationModeFilter
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("unkown bucket configuration mode kind: %s", bytes)
|
||||||
|
}
|
||||||
|
|
||||||
type ProjectViewBucketConfiguration struct {
|
type ProjectViewBucketConfiguration struct {
|
||||||
Title string
|
Title string
|
||||||
Filter string
|
Filter string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user