diff --git a/kernel/av/av.go b/kernel/av/av.go
index 7c8ccec5a..cad928641 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -24,6 +24,7 @@ import (
"strings"
"github.com/88250/gulu"
+ "github.com/88250/lute/ast"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
@@ -31,10 +32,10 @@ import (
// AttributeView 描述了属性视图的结构。
type AttributeView struct {
- Spec int `json:"spec"`
- ID string `json:"id"` // 属性视图 ID
- Columns []interface{} `json:"columns"` // 表格列名
- Rows []*Row `json:"rows"` // 表格行记录
+ Spec int `json:"spec"`
+ ID string `json:"id"` // 属性视图 ID
+ Columns []*Column `json:"columns"` // 表格列名
+ Rows []*Row `json:"rows"` // 表格行记录
Type AttributeViewType `json:"type"` // 属性视图类型
Projections []string `json:"projections"` // 显示的列名,SELECT *
@@ -53,7 +54,7 @@ func NewAttributeView(id string) *AttributeView {
return &AttributeView{
Spec: 0,
ID: id,
- Columns: []interface{}{NewColumnBlock()},
+ Columns: []*Column{&Column{ID: ast.NewNodeID(), Name: "Block", Type: ColumnTypeBlock}},
Rows: []*Row{},
Type: AttributeViewTypeTable,
Projections: []string{},
@@ -65,12 +66,12 @@ func NewAttributeView(id string) *AttributeView {
func (av *AttributeView) GetColumnNames() (ret []string) {
ret = []string{}
for _, column := range av.Columns {
- ret = append(ret, column.(*Column).Name)
+ ret = append(ret, column.Name)
}
return
}
-func (av *AttributeView) InsertColumn(index int, column interface{}) {
+func (av *AttributeView) InsertColumn(index int, column *Column) {
if 0 > index || len(av.Columns) == index {
av.Columns = append(av.Columns, column)
return
@@ -114,7 +115,7 @@ const (
)
func ParseAttributeView(avID string) (ret *AttributeView, err error) {
- avJSONPath := getAttributeViewJSONPath(avID)
+ avJSONPath := getAttributeViewDataPath(avID)
if !gulu.File.IsExist(avJSONPath) {
ret = NewAttributeView(avID)
return
@@ -141,7 +142,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
return
}
- avJSONPath := getAttributeViewJSONPath(av.ID)
+ avJSONPath := getAttributeViewDataPath(av.ID)
if err = filelock.WriteFile(avJSONPath, data); nil != err {
logging.LogErrorf("save attribute view [%s] failed: %s", av.ID, err)
return
@@ -149,7 +150,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
return
}
-func getAttributeViewJSONPath(avID string) (ret string) {
+func getAttributeViewDataPath(avID string) (ret string) {
av := filepath.Join(util.DataDir, "storage", "av")
ret = filepath.Join(av, avID+".json")
if !gulu.File.IsDir(av) {
diff --git a/kernel/av/column.go b/kernel/av/column.go
index ee57ba28a..e0dbf70c3 100644
--- a/kernel/av/column.go
+++ b/kernel/av/column.go
@@ -35,6 +35,15 @@ type Column struct {
ID string `json:"id"` // 列 ID
Name string `json:"name"` // 列名
Type ColumnType `json:"type"` // 列类型
+
+ AttributeViewID string `json:"attributeViewId"` // 关联的属性视图 ID
+ RelationColumnID string `json:"relationColumnId"` // 目标关联列 ID
+ Options []*ColumnSelectOption `json:"options"` // 选项列表
+}
+
+type ColumnSelectOption struct {
+ Name string `json:"name"`
+ Color string `json:"color"`
}
func NewColumn(name string, columnType ColumnType) *Column {
diff --git a/kernel/av/column_block.go b/kernel/av/column_block.go
deleted file mode 100644
index 47e5f172f..000000000
--- a/kernel/av/column_block.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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 .
-
-package av
-
-type ColumnBlock struct {
- *Column
-}
-
-func NewColumnBlock() *ColumnBlock {
- return &ColumnBlock{
- Column: NewColumn("Block", ColumnTypeBlock),
- }
-}
diff --git a/kernel/av/column_date.go b/kernel/av/column_date.go
deleted file mode 100644
index e7787b63b..000000000
--- a/kernel/av/column_date.go
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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 .
-
-package av
-
-type ColumnDate struct {
- *Column
-}
diff --git a/kernel/av/column_number.go b/kernel/av/column_number.go
deleted file mode 100644
index dc48325bc..000000000
--- a/kernel/av/column_number.go
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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 .
-
-package av
-
-type ColumnNumber struct {
- *Column
-}
diff --git a/kernel/av/column_relation.go b/kernel/av/column_relation.go
deleted file mode 100644
index fe17f83de..000000000
--- a/kernel/av/column_relation.go
+++ /dev/null
@@ -1,22 +0,0 @@
-// 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 .
-
-package av
-
-type ColumnRelation struct {
- *Column
- AttributeViewID string `json:"attributeViewId"` // 关联的属性视图 ID
-}
diff --git a/kernel/av/column_rollup.go b/kernel/av/column_rollup.go
deleted file mode 100644
index 20306bacf..000000000
--- a/kernel/av/column_rollup.go
+++ /dev/null
@@ -1,22 +0,0 @@
-// 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 .
-
-package av
-
-type ColumnRollup struct {
- *Column
- RelationColumnID string `json:"relationColumnId"` // 目标关联列 ID
-}
diff --git a/kernel/av/column_select.go b/kernel/av/column_select.go
deleted file mode 100644
index 20bc17bd9..000000000
--- a/kernel/av/column_select.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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 .
-
-package av
-
-type ColumnSelect struct {
- *Column
- Options []*ColumnSelectOption `json:"options"`
-}
-
-type ColumnSelectOption struct {
- Name string `json:"name"`
- Color string `json:"color"`
-}
diff --git a/kernel/av/column_text.go b/kernel/av/column_text.go
deleted file mode 100644
index db61dc332..000000000
--- a/kernel/av/column_text.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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 .
-
-package av
-
-type ColumnText struct {
- *Column
-}
-
-func NewColumnText(name string) *ColumnText {
- return &ColumnText{
- Column: NewColumn(name, ColumnTypeText),
- }
-}
diff --git a/kernel/av/row.go b/kernel/av/row.go
index 845c92b42..7cd22217c 100644
--- a/kernel/av/row.go
+++ b/kernel/av/row.go
@@ -19,8 +19,8 @@ package av
import "github.com/88250/lute/ast"
type Row struct {
- ID string `json:"id"`
- Cells []interface{} `json:"cells"`
+ ID string `json:"id"`
+ Cells []*Cell `json:"cells"`
}
func NewRow() *Row {
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index c4c922723..e5eb439b6 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -20,6 +20,7 @@ import (
"errors"
"fmt"
+ "github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/av"
@@ -69,7 +70,7 @@ func AddAttributeViewColumn(name string, typ string, columnIndex int, avID strin
switch av.ColumnType(typ) {
case av.ColumnTypeText:
- attrView.InsertColumn(columnIndex, av.NewColumnText(name))
+ attrView.InsertColumn(columnIndex, &av.Column{ID: ast.NewNodeID(), Name: name, Type: av.ColumnTypeText})
default:
msg := fmt.Sprintf("invalid column type [%s]", typ)
logging.LogErrorf(msg)
@@ -94,7 +95,7 @@ func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error
}
for i, row := range attrView.Rows {
- if row.Cells[0].(*av.Cell).Value == blockID {
+ if row.Cells[0].Value == blockID {
attrView.Rows = append(attrView.Rows[:i], attrView.Rows[i+1:]...)
break
}
@@ -111,6 +112,11 @@ func addAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error) {
return
}
+ if ast.NodeAttributeView == node.Type {
+ // 不能将一个属性视图拖拽到另一个属性视图中
+ return
+ }
+
block := sql.BuildBlockFromNode(node, tree)
if nil == block {
err = ErrBlockNotFound
@@ -124,18 +130,18 @@ func addAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error) {
// 不允许重复添加相同的块到属性视图中
for _, row := range attrView.Rows {
- if row.Cells[0].(*av.Cell).Value == blockID {
+ if row.Cells[0].Value == blockID {
return
}
}
row := av.NewRow()
- row.Cells = append(row.Cells, av.NewCellBlock(block.ID))
+ row.Cells = append(row.Cells, &av.Cell{Value: blockID})
if 1 < len(attrView.Columns) {
attrs := parse.IAL2Map(node.KramdownIAL)
for _, col := range attrView.Columns[1:] {
- colName := col.(*av.Column).Name
+ colName := col.Name
attrs[colName] = ""
}