♻️ Refactor av data structure

This commit is contained in:
Daniel 2023-07-12 10:35:17 +08:00
parent 7ca8eab0cd
commit fbd26d1fd6
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 63 additions and 38 deletions

View file

@ -37,38 +37,38 @@ type AttributeView struct {
Columns []*Column `json:"columns"` // 列
Rows []*Row `json:"rows"` // 行
CurrentViewID string `json:"currentViewId"` // 当前视图 ID
CurrentViewID string `json:"currentViewID"` // 当前视图 ID
Views []*View `json:"views"` // 视图
}
// View 描述了视图的结构。
type View struct {
ID string `json:"id"` // 视图 ID
Name string `json:"name"` // 视图名称
Type ViewType `json:"type"` // 视图类型
ID string `json:"id"` // 视图 ID
Name string `json:"name"` // 视图名称
Table *Table `json:"table,omitempty"` // 表格视图
// TODO Kanban *Kanban `json:"kanban,omitempty"` // 看板视图
CurrentLayoutID string `json:"CurrentLayoutID"` // 当前布局 ID
CurrentLayoutType LayoutType `json:"type"` // 当前布局类型
Table *LayoutTable `json:"table,omitempty"` // 表格布局
}
// ViewType 描述了视图的类型。
type ViewType string
// LayoutType 描述了视图布局的类型。
type LayoutType string
const (
ViewTypeTable ViewType = "table" // 属性视图类型 - 表格
ViewTypeKanban ViewType = "kanban" // 属性视图类型 - 看板
LayoutTypeTable LayoutType = "table" // 属性视图类型 - 表格
)
func NewView() *View {
id := ast.NewNodeID()
name := "Table"
layoutID := ast.NewNodeID()
return &View{
ID: id,
Name: name,
Type: ViewTypeTable,
Table: &Table{
ID: ast.NewNodeID(),
Name: name,
CurrentLayoutID: layoutID,
CurrentLayoutType: LayoutTypeTable,
Table: &LayoutTable{
Spec: 0,
ID: id,
ID: layoutID,
Filters: []*ViewFilter{},
Sorts: []*ViewSort{},
},
@ -81,7 +81,7 @@ type Viewable interface {
Sortable
Calculable
GetType() ViewType
GetType() LayoutType
GetID() string
}

View file

@ -21,13 +21,14 @@ import (
"sort"
)
// Table 描述了表格视图的结构。
type Table struct {
Spec int `json:"spec"` // 视图格式版本
ID string `json:"id"` // 视图 ID
// LayoutTable 描述了表格布局的结构。
type LayoutTable struct {
Spec int `json:"spec"` // 布局格式版本
ID string `json:"id"` // 布局 ID
Columns []*TableColumn `json:"columns"` // 表格列
Rows []*TableRow `json:"rows"` // 表格行
ColIDs []string `json:"colIds"` // 列 ID用于自定义排序
RowIDs []string `json:"rowIds"` // 行 ID用于自定义排序
Filters []*ViewFilter `json:"filters"` // 过滤规则
Sorts []*ViewSort `json:"sorts"` // 排序规则
}
@ -49,8 +50,18 @@ type TableRow struct {
Cells []*Cell `json:"cells"`
}
func (table *Table) GetType() ViewType {
return ViewTypeTable
// Table 描述了表格实例的结构。
type Table struct {
ID string `json:"id"` // 表格布局 ID
Name string `json:"name"` // 表格名称
Filters []*ViewFilter `json:"filters"` // 过滤规则
Sorts []*ViewSort `json:"sorts"` // 排序规则
Columns []*TableColumn `json:"columns"` // 表格列
Rows []*TableRow `json:"rows"` // 表格行
}
func (table *Table) GetType() LayoutType {
return LayoutTypeTable
}
func (table *Table) GetID() string {