This commit is contained in:
Liang Ding 2023-03-03 10:26:02 +08:00
parent efa308d945
commit 9c1d6a1a70
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
12 changed files with 63 additions and 67 deletions

View file

@ -31,9 +31,9 @@ import (
// AttributeView 描述了属性视图的结构。
type AttributeView struct {
ID string `json:"id"` // 属性视图 ID
Columns []Column `json:"columns"` // 表格列名
Rows [][]Cell `json:"rows"` // 表格行记录
ID string `json:"id"` // 属性视图 ID
Columns []interface{} `json:"columns"` // 表格列名
Rows []*Row `json:"rows"` // 表格行记录
Type AttributeViewType `json:"type"` // 属性视图类型
Projections []string `json:"projections"` // 显示的列名SELECT *
@ -51,8 +51,8 @@ const (
func NewAttributeView(id string) *AttributeView {
return &AttributeView{
ID: id,
Columns: []Column{NewColumnBlock()},
Rows: [][]Cell{},
Columns: []interface{}{NewColumnBlock()},
Rows: []*Row{},
Type: AttributeViewTypeTable,
Projections: []string{},
Filters: []*AttributeViewFilter{},
@ -63,12 +63,12 @@ func NewAttributeView(id string) *AttributeView {
func (av *AttributeView) GetColumnNames() (ret []string) {
ret = []string{}
for _, column := range av.Columns {
ret = append(ret, column.Name())
ret = append(ret, column.(*Column).Name)
}
return
}
func (av *AttributeView) InsertColumn(index int, column Column) {
func (av *AttributeView) InsertColumn(index int, column interface{}) {
if 0 > index || len(av.Columns) == index {
av.Columns = append(av.Columns, column)
return

View file

@ -16,20 +16,14 @@
package av
type Cell interface {
// Value 返回单元格的值。
Value() string
type Cell struct {
Value string
}
type CellBlock struct {
ID string `json:"id"`
*Cell
}
func NewCellBlock(blockID string) *CellBlock {
return &CellBlock{ID: blockID}
}
func (c *CellBlock) Value() string {
return c.ID
return &CellBlock{&Cell{Value: blockID}}
}

View file

@ -18,19 +18,6 @@ package av
import "github.com/88250/lute/ast"
// Column 描述了属性视图的列。
type Column interface {
// ID 用于获取列 ID。
ID() string
// Name 用于获取列名。
Name() string
// Type 用于获取列类型。
Type() ColumnType
}
type ColumnType string
const (
@ -43,29 +30,17 @@ const (
ColumnTypeText ColumnType = "text"
)
// BaseColumn 描述了属性视图的基础结构。
type BaseColumn struct {
BaseID string `json:"id"` // 列 ID
BaseName string `json:"name"` // 列名
BaseType ColumnType `json:"type"` // 列类型
// Column 描述了属性视图的基础结构。
type Column struct {
ID string `json:"id"` // 列 ID
Name string `json:"name"` // 列名
Type ColumnType `json:"type"` // 列类型
}
func (c *BaseColumn) ID() string {
return c.BaseID
}
func (c *BaseColumn) Name() string {
return c.BaseName
}
func (c *BaseColumn) Type() ColumnType {
return c.BaseType
}
func NewBaseColumn(name string, columnType ColumnType) *BaseColumn {
return &BaseColumn{
BaseID: ast.NewNodeID(),
BaseName: name,
BaseType: columnType,
func NewColumn(name string, columnType ColumnType) *Column {
return &Column{
ID: ast.NewNodeID(),
Name: name,
Type: columnType,
}
}

View file

@ -17,11 +17,11 @@
package av
type ColumnBlock struct {
*BaseColumn
*Column
}
func NewColumnBlock() *ColumnBlock {
return &ColumnBlock{
BaseColumn: NewBaseColumn("Block", ColumnTypeBlock),
Column: NewColumn("Block", ColumnTypeBlock),
}
}

View file

@ -17,5 +17,5 @@
package av
type ColumnDate struct {
*BaseColumn
*Column
}

View file

@ -17,5 +17,5 @@
package av
type ColumnNumber struct {
*BaseColumn
*Column
}

View file

@ -17,6 +17,6 @@
package av
type ColumnRelation struct {
*BaseColumn
*Column
AttributeViewID string `json:"attributeViewId"` // 关联的属性视图 ID
}

View file

@ -17,6 +17,6 @@
package av
type ColumnRollup struct {
*BaseColumn
*Column
RelationColumnID string `json:"relationColumnId"` // 目标关联列 ID
}

View file

@ -17,7 +17,7 @@
package av
type ColumnSelect struct {
*BaseColumn
*Column
Options []*ColumnSelectOption `json:"options"`
}

View file

@ -17,11 +17,11 @@
package av
type ColumnText struct {
*BaseColumn
*Column
}
func NewColumnText(name string) *ColumnText {
return &ColumnText{
BaseColumn: NewBaseColumn(name, ColumnTypeText),
Column: NewColumn(name, ColumnTypeText),
}
}

28
kernel/av/row.go Normal file
View file

@ -0,0 +1,28 @@
// SiYuan - Build Your Eternal Digital Garden
// Copyright (c) 2020-present, b3log.org
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package av
import "github.com/88250/lute/ast"
type Row struct {
ID string `json:"id"`
Cells []interface{} `json:"cells"`
}
func NewRow() *Row {
return &Row{ID: ast.NewNodeID()}
}

View file

@ -19,7 +19,6 @@ package model
import (
"errors"
"fmt"
"github.com/88250/lute/parse"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/av"
@ -94,7 +93,7 @@ func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error
}
for i, row := range attrView.Rows {
if row[0].Value() == blockID {
if row.Cells[0].(*av.Cell).Value == blockID {
attrView.Rows = append(attrView.Rows[:i], attrView.Rows[i+1:]...)
break
}
@ -124,18 +123,18 @@ func addAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error) {
// 不允许重复添加相同的块到属性视图中
for _, row := range attrView.Rows {
if row[0].Value() == blockID {
if row.Cells[0].(*av.Cell).Value == blockID {
return
}
}
var row []av.Cell
row = append(row, av.NewCellBlock(block.ID))
row := av.NewRow()
row.Cells = append(row.Cells, av.NewCellBlock(block.ID))
if 1 < len(attrView.Columns) {
attrs := parse.IAL2Map(node.KramdownIAL)
for _, col := range attrView.Columns[1:] {
colName := col.Name()
colName := col.(*av.Column).Name
attrs[colName] = ""
}