Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
276c598e0c
12 changed files with 371 additions and 7 deletions
8
app/stage/protyle/js/lute/lute.min.js
vendored
8
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
141
kernel/av/av.go
Normal file
141
kernel/av/av.go
Normal file
|
@ -0,0 +1,141 @@
|
|||
// 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 包含了属性视图(Attribute View)相关的实现。
|
||||
package av
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
// AttributeView 描述了属性视图的结构。
|
||||
type AttributeView struct {
|
||||
ID string `json:"id"` // 属性视图 ID
|
||||
Columns []Column `json:"columns"` // 表格列名
|
||||
Rows [][]string `json:"rows"` // 表格行记录
|
||||
|
||||
Type AttributeViewType `json:"type"` // 属性视图类型
|
||||
Projections []string `json:"projections"` // 显示的列名,SELECT *
|
||||
Filters []*AttributeViewFilter `json:"filters"` // 过滤规则,WHERE ...
|
||||
Sorts []*AttributeViewSort `json:"sorts"` // 排序规则,ORDER BY ...
|
||||
}
|
||||
|
||||
// AttributeViewType 描述了属性视图的类型。
|
||||
type AttributeViewType string
|
||||
|
||||
const (
|
||||
AttributeViewTypeTable AttributeViewType = "table" // 属性视图类型 - 表格
|
||||
)
|
||||
|
||||
func (av *AttributeView) GetColumnNames() (ret []string) {
|
||||
ret = []string{}
|
||||
for _, column := range av.Columns {
|
||||
ret = append(ret, column.Name())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type AttributeViewFilter struct {
|
||||
Column string `json:"column"`
|
||||
Operator string `json:"operator"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type AttributeViewSort struct {
|
||||
Column string `json:"column"`
|
||||
Order string `json:"order"`
|
||||
}
|
||||
|
||||
// SyncAttributeViewTableFromJSON 从 JSON 文件同步属性视图表,用于数据同步后将属性视图 JSON 文件同步到数据库。
|
||||
func SyncAttributeViewTableFromJSON(tableID string) (err error) {
|
||||
avJSONPath := getAttributeViewJSONPath(tableID)
|
||||
data, err := filelock.ReadFile(avJSONPath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read attribute view table failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
var attributeView AttributeView
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &attributeView); nil != err {
|
||||
logging.LogErrorf("unmarshal attribute view table failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// SyncAttributeViewTableToJSON 同步属性视图表到 JSON 文件,用于将数据库中的属性视图持久化到 JSON 文件中。
|
||||
func SyncAttributeViewTableToJSON(av *AttributeView) (err error) {
|
||||
data, err := gulu.JSON.MarshalJSON(av)
|
||||
if nil != err {
|
||||
logging.LogErrorf("marshal attribute view table [%s] failed: %s", av.ID, err)
|
||||
return
|
||||
}
|
||||
|
||||
avJSONPath := getAttributeViewJSONPath(av.ID)
|
||||
if err = filelock.WriteFile(avJSONPath, data); nil != err {
|
||||
logging.LogErrorf("save attribute view table [%s] failed: %s", av.ID, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getAttributeViewJSONPath(tableID string) string {
|
||||
return filepath.Join(util.DataDir, "storage", "av", tableID+".json")
|
||||
}
|
||||
|
||||
func dropAttributeViewTableColumn(db *sql.DB, tableID string, column string) (err error) {
|
||||
_, err = db.Exec("ALTER TABLE `av_" + tableID + "` DROP COLUMN `" + column + "`")
|
||||
if nil != err {
|
||||
logging.LogErrorf("drop column [%s] failed: %s", column, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addAttributeViewTableColumn(db *sql.DB, tableID string, column string) (err error) {
|
||||
_, err = db.Exec("ALTER TABLE `av_" + tableID + "` ADD COLUMN `" + column + "`")
|
||||
if nil != err {
|
||||
logging.LogErrorf("add column [%s] failed: %s", column, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func dropAttributeViewTable(db *sql.DB, tableID string) (err error) {
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS `av_" + tableID + "`")
|
||||
if nil != err {
|
||||
logging.LogErrorf("drop table [%s] failed: %s", tableID, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func createAttributeViewTable(db *sql.DB, tableID string, column []string) (err error) {
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS `av_" + tableID + "` (id, " + strings.Join(column, ", ") + ")")
|
||||
if nil != err {
|
||||
logging.LogErrorf("create table [%s] failed: %s", tableID, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
56
kernel/av/column.go
Normal file
56
kernel/av/column.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
// 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
|
||||
|
||||
// Column 描述了属性视图的列。
|
||||
type Column interface {
|
||||
|
||||
// ID 用于获取列 ID。
|
||||
ID() string
|
||||
|
||||
// Name 用于获取列名。
|
||||
Name() string
|
||||
|
||||
// Type 用于获取列类型。
|
||||
Type() string
|
||||
}
|
||||
|
||||
// BaseColumn 描述了属性视图的基础结构。
|
||||
type BaseColumn struct {
|
||||
BaseID string `json:"id"` // 列 ID
|
||||
BaseName string `json:"name"` // 列名
|
||||
BaseType string `json:"type"` // 列类型
|
||||
}
|
||||
|
||||
func (c *BaseColumn) ID() string {
|
||||
return c.BaseID
|
||||
}
|
||||
|
||||
func (c *BaseColumn) Name() string {
|
||||
return c.BaseName
|
||||
}
|
||||
|
||||
func (c *BaseColumn) Type() string {
|
||||
return c.BaseType
|
||||
}
|
||||
|
||||
// ColumnValueResolver 描述了属性视图的列值解析器。
|
||||
type ColumnValueResolver interface {
|
||||
|
||||
// Resolve 用于解析列值。
|
||||
Resolve() string
|
||||
}
|
21
kernel/av/column_date.go
Normal file
21
kernel/av/column_date.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
// 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 {
|
||||
*BaseColumn
|
||||
}
|
21
kernel/av/column_number.go
Normal file
21
kernel/av/column_number.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
// 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 {
|
||||
*BaseColumn
|
||||
}
|
22
kernel/av/column_relation.go
Normal file
22
kernel/av/column_relation.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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 {
|
||||
*BaseColumn
|
||||
AttributeViewID string `json:"attributeViewId"` // 关联的属性视图 ID
|
||||
}
|
22
kernel/av/column_rollup.go
Normal file
22
kernel/av/column_rollup.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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 {
|
||||
*BaseColumn
|
||||
RelationColumnID string `json:"relationColumnId"` // 目标关联列 ID
|
||||
}
|
27
kernel/av/column_select.go
Normal file
27
kernel/av/column_select.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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 {
|
||||
*BaseColumn
|
||||
Options []*ColumnSelectOption `json:"options"`
|
||||
}
|
||||
|
||||
type ColumnSelectOption struct {
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
}
|
21
kernel/av/column_text.go
Normal file
21
kernel/av/column_text.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
// 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 {
|
||||
*BaseColumn
|
||||
}
|
|
@ -6,7 +6,7 @@ require (
|
|||
github.com/88250/clipboard v0.1.5
|
||||
github.com/88250/css v0.1.2
|
||||
github.com/88250/gulu v1.2.3-0.20230223100136-26e5f16ac3c0
|
||||
github.com/88250/lute v1.7.6-0.20230227052817-6f1ed4c3a0b5
|
||||
github.com/88250/lute v1.7.6-0.20230301072643-4edada969ffd
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230224021324-e51076eb6390
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||
github.com/ClarkThan/ahocorasick v0.0.0-20230220142845-f237b6348b3e
|
||||
|
|
|
@ -8,8 +8,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
|
|||
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/88250/gulu v1.2.3-0.20230223100136-26e5f16ac3c0 h1:hZn2F/kNKcxoK41JhfoTfJ5BYHoWG3fSYk/BlOPYqLo=
|
||||
github.com/88250/gulu v1.2.3-0.20230223100136-26e5f16ac3c0/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
|
||||
github.com/88250/lute v1.7.6-0.20230227052817-6f1ed4c3a0b5 h1:c1QJKEKsPwBJPbDMX6FJWQFxBZLZDe8SFwDigFFtZKc=
|
||||
github.com/88250/lute v1.7.6-0.20230227052817-6f1ed4c3a0b5/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/lute v1.7.6-0.20230301072643-4edada969ffd h1:OxBN45x484KqSlHLN4urLqUj1Bpq96T8NFtPZ5mBSsc=
|
||||
github.com/88250/lute v1.7.6-0.20230301072643-4edada969ffd/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230224021324-e51076eb6390 h1:q2AR33VoQ87WYtvZ4pEvwj5gZkv22HK/yMlPWwF1oyc=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230224021324-e51076eb6390/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
||||
|
|
33
kernel/model/attribute_view.go
Normal file
33
kernel/model/attribute_view.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
// 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 model
|
||||
|
||||
import (
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
)
|
||||
|
||||
func CreateAttributeView() (err error) {
|
||||
avID := ast.NewNodeID()
|
||||
av := &sql.AttributeView{}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func addBlockToAttributeView(block *Block, avID string) {
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue