An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 持久化属性视图 https://github.com/siyuan-note/siyuan/issues/2829
Liang Dinga78f0d4b7800
diff --git a/kernel/av/av.go b/kernel/av/av.goindex 7c8ccec5a3..cad9286419 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.goindex ee57ba28ae..e0dbf70c32 100644--- a/kernel/av/column.go+++ b/kernel/av/column.go@@ -35,6 +35,15 @@ type Column struct {ID string `json:"id"` // 列 IDName 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.godeleted file mode 100644index 47e5f172fb..0000000000--- 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 <https://www.gnu.org/licenses/>.--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.godeleted file mode 100644index e7787b63b1..0000000000--- 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 <https://www.gnu.org/licenses/>.--package av--type ColumnDate struct {- *Column-}diff --git a/kernel/av/column_number.go b/kernel/av/column_number.godeleted file mode 100644index dc48325bcc..0000000000--- 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 <https://www.gnu.org/licenses/>.--package av--type ColumnNumber struct {- *Column-}diff --git a/kernel/av/column_relation.go b/kernel/av/column_relation.godeleted file mode 100644index fe17f83de4..0000000000--- 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 <https://www.gnu.org/licenses/>.--package av--type ColumnRelation struct {- *Column- AttributeViewID string `json:"attributeViewId"` // 关联的属性视图 ID-}diff --git a/kernel/av/column_rollup.go b/kernel/av/column_rollup.godeleted file mode 100644index 20306bacf1..0000000000--- 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 <https://www.gnu.org/licenses/>.--package av--type ColumnRollup struct {- *Column- RelationColumnID string `json:"relationColumnId"` // 目标关联列 ID-}diff --git a/kernel/av/column_select.go b/kernel/av/column_select.godeleted file mode 100644index 20bc17bd90..0000000000--- 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 <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"`-}diff --git a/kernel/av/column_text.go b/kernel/av/column_text.godeleted file mode 100644index db61dc332a..0000000000--- 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 <https://www.gnu.org/licenses/>.--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.goindex 845c92b42a..7cd22217ca 100644--- a/kernel/av/row.go+++ b/kernel/av/row.go@@ -19,8 +19,8 @@ package avimport "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.goindex c4c9227232..ad493cbce5 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 strinswitch 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}@@ -124,18 +125,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.Nameattrs[colName] = ""}