Просмотр исходного кода

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 2 лет назад
Родитель
Сommit
4f11da8176

+ 11 - 10
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) {

+ 9 - 0
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 {

+ 0 - 27
kernel/av/column_block.go

@@ -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 <https://www.gnu.org/licenses/>.
-
-package av
-
-type ColumnBlock struct {
-	*Column
-}
-
-func NewColumnBlock() *ColumnBlock {
-	return &ColumnBlock{
-		Column: NewColumn("Block", ColumnTypeBlock),
-	}
-}

+ 0 - 21
kernel/av/column_date.go

@@ -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 <https://www.gnu.org/licenses/>.
-
-package av
-
-type ColumnDate struct {
-	*Column
-}

+ 0 - 21
kernel/av/column_number.go

@@ -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 <https://www.gnu.org/licenses/>.
-
-package av
-
-type ColumnNumber struct {
-	*Column
-}

+ 0 - 22
kernel/av/column_relation.go

@@ -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 <https://www.gnu.org/licenses/>.
-
-package av
-
-type ColumnRelation struct {
-	*Column
-	AttributeViewID string `json:"attributeViewId"` // 关联的属性视图 ID
-}

+ 0 - 22
kernel/av/column_rollup.go

@@ -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 <https://www.gnu.org/licenses/>.
-
-package av
-
-type ColumnRollup struct {
-	*Column
-	RelationColumnID string `json:"relationColumnId"` // 目标关联列 ID
-}

+ 0 - 27
kernel/av/column_select.go

@@ -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 <https://www.gnu.org/licenses/>.
-
-package av
-
-type ColumnSelect struct {
-	*Column
-	Options []*ColumnSelectOption `json:"options"`
-}
-
-type ColumnSelectOption struct {
-	Name  string `json:"name"`
-	Color string `json:"color"`
-}

+ 0 - 27
kernel/av/column_text.go

@@ -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 <https://www.gnu.org/licenses/>.
-
-package av
-
-type ColumnText struct {
-	*Column
-}
-
-func NewColumnText(name string) *ColumnText {
-	return &ColumnText{
-		Column: NewColumn(name, ColumnTypeText),
-	}
-}

+ 2 - 2
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 {

+ 11 - 5
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] = ""
 		}