mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
This commit is contained in:
parent
efa308d945
commit
9c1d6a1a70
12 changed files with 63 additions and 67 deletions
|
|
@ -32,8 +32,8 @@ import (
|
||||||
// AttributeView 描述了属性视图的结构。
|
// AttributeView 描述了属性视图的结构。
|
||||||
type AttributeView struct {
|
type AttributeView struct {
|
||||||
ID string `json:"id"` // 属性视图 ID
|
ID string `json:"id"` // 属性视图 ID
|
||||||
Columns []Column `json:"columns"` // 表格列名
|
Columns []interface{} `json:"columns"` // 表格列名
|
||||||
Rows [][]Cell `json:"rows"` // 表格行记录
|
Rows []*Row `json:"rows"` // 表格行记录
|
||||||
|
|
||||||
Type AttributeViewType `json:"type"` // 属性视图类型
|
Type AttributeViewType `json:"type"` // 属性视图类型
|
||||||
Projections []string `json:"projections"` // 显示的列名,SELECT *
|
Projections []string `json:"projections"` // 显示的列名,SELECT *
|
||||||
|
|
@ -51,8 +51,8 @@ const (
|
||||||
func NewAttributeView(id string) *AttributeView {
|
func NewAttributeView(id string) *AttributeView {
|
||||||
return &AttributeView{
|
return &AttributeView{
|
||||||
ID: id,
|
ID: id,
|
||||||
Columns: []Column{NewColumnBlock()},
|
Columns: []interface{}{NewColumnBlock()},
|
||||||
Rows: [][]Cell{},
|
Rows: []*Row{},
|
||||||
Type: AttributeViewTypeTable,
|
Type: AttributeViewTypeTable,
|
||||||
Projections: []string{},
|
Projections: []string{},
|
||||||
Filters: []*AttributeViewFilter{},
|
Filters: []*AttributeViewFilter{},
|
||||||
|
|
@ -63,12 +63,12 @@ func NewAttributeView(id string) *AttributeView {
|
||||||
func (av *AttributeView) GetColumnNames() (ret []string) {
|
func (av *AttributeView) GetColumnNames() (ret []string) {
|
||||||
ret = []string{}
|
ret = []string{}
|
||||||
for _, column := range av.Columns {
|
for _, column := range av.Columns {
|
||||||
ret = append(ret, column.Name())
|
ret = append(ret, column.(*Column).Name)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (av *AttributeView) InsertColumn(index int, column Column) {
|
func (av *AttributeView) InsertColumn(index int, column interface{}) {
|
||||||
if 0 > index || len(av.Columns) == index {
|
if 0 > index || len(av.Columns) == index {
|
||||||
av.Columns = append(av.Columns, column)
|
av.Columns = append(av.Columns, column)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,14 @@
|
||||||
|
|
||||||
package av
|
package av
|
||||||
|
|
||||||
type Cell interface {
|
type Cell struct {
|
||||||
|
Value string
|
||||||
// Value 返回单元格的值。
|
|
||||||
Value() string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CellBlock struct {
|
type CellBlock struct {
|
||||||
ID string `json:"id"`
|
*Cell
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCellBlock(blockID string) *CellBlock {
|
func NewCellBlock(blockID string) *CellBlock {
|
||||||
return &CellBlock{ID: blockID}
|
return &CellBlock{&Cell{Value: blockID}}
|
||||||
}
|
|
||||||
|
|
||||||
func (c *CellBlock) Value() string {
|
|
||||||
return c.ID
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,6 @@ package av
|
||||||
|
|
||||||
import "github.com/88250/lute/ast"
|
import "github.com/88250/lute/ast"
|
||||||
|
|
||||||
// Column 描述了属性视图的列。
|
|
||||||
type Column interface {
|
|
||||||
|
|
||||||
// ID 用于获取列 ID。
|
|
||||||
ID() string
|
|
||||||
|
|
||||||
// Name 用于获取列名。
|
|
||||||
Name() string
|
|
||||||
|
|
||||||
// Type 用于获取列类型。
|
|
||||||
Type() ColumnType
|
|
||||||
}
|
|
||||||
|
|
||||||
type ColumnType string
|
type ColumnType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -43,29 +30,17 @@ const (
|
||||||
ColumnTypeText ColumnType = "text"
|
ColumnTypeText ColumnType = "text"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BaseColumn 描述了属性视图的基础结构。
|
// Column 描述了属性视图的基础结构。
|
||||||
type BaseColumn struct {
|
type Column struct {
|
||||||
BaseID string `json:"id"` // 列 ID
|
ID string `json:"id"` // 列 ID
|
||||||
BaseName string `json:"name"` // 列名
|
Name string `json:"name"` // 列名
|
||||||
BaseType ColumnType `json:"type"` // 列类型
|
Type ColumnType `json:"type"` // 列类型
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BaseColumn) ID() string {
|
func NewColumn(name string, columnType ColumnType) *Column {
|
||||||
return c.BaseID
|
return &Column{
|
||||||
}
|
ID: ast.NewNodeID(),
|
||||||
|
Name: name,
|
||||||
func (c *BaseColumn) Name() string {
|
Type: columnType,
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
package av
|
package av
|
||||||
|
|
||||||
type ColumnBlock struct {
|
type ColumnBlock struct {
|
||||||
*BaseColumn
|
*Column
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewColumnBlock() *ColumnBlock {
|
func NewColumnBlock() *ColumnBlock {
|
||||||
return &ColumnBlock{
|
return &ColumnBlock{
|
||||||
BaseColumn: NewBaseColumn("Block", ColumnTypeBlock),
|
Column: NewColumn("Block", ColumnTypeBlock),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,5 @@
|
||||||
package av
|
package av
|
||||||
|
|
||||||
type ColumnDate struct {
|
type ColumnDate struct {
|
||||||
*BaseColumn
|
*Column
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,5 @@
|
||||||
package av
|
package av
|
||||||
|
|
||||||
type ColumnNumber struct {
|
type ColumnNumber struct {
|
||||||
*BaseColumn
|
*Column
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,6 @@
|
||||||
package av
|
package av
|
||||||
|
|
||||||
type ColumnRelation struct {
|
type ColumnRelation struct {
|
||||||
*BaseColumn
|
*Column
|
||||||
AttributeViewID string `json:"attributeViewId"` // 关联的属性视图 ID
|
AttributeViewID string `json:"attributeViewId"` // 关联的属性视图 ID
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,6 @@
|
||||||
package av
|
package av
|
||||||
|
|
||||||
type ColumnRollup struct {
|
type ColumnRollup struct {
|
||||||
*BaseColumn
|
*Column
|
||||||
RelationColumnID string `json:"relationColumnId"` // 目标关联列 ID
|
RelationColumnID string `json:"relationColumnId"` // 目标关联列 ID
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
package av
|
package av
|
||||||
|
|
||||||
type ColumnSelect struct {
|
type ColumnSelect struct {
|
||||||
*BaseColumn
|
*Column
|
||||||
Options []*ColumnSelectOption `json:"options"`
|
Options []*ColumnSelectOption `json:"options"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
package av
|
package av
|
||||||
|
|
||||||
type ColumnText struct {
|
type ColumnText struct {
|
||||||
*BaseColumn
|
*Column
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewColumnText(name string) *ColumnText {
|
func NewColumnText(name string) *ColumnText {
|
||||||
return &ColumnText{
|
return &ColumnText{
|
||||||
BaseColumn: NewBaseColumn(name, ColumnTypeText),
|
Column: NewColumn(name, ColumnTypeText),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
kernel/av/row.go
Normal file
28
kernel/av/row.go
Normal 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()}
|
||||||
|
}
|
||||||
|
|
@ -19,7 +19,6 @@ package model
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
"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 {
|
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:]...)
|
attrView.Rows = append(attrView.Rows[:i], attrView.Rows[i+1:]...)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -124,18 +123,18 @@ func addAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error) {
|
||||||
|
|
||||||
// 不允许重复添加相同的块到属性视图中
|
// 不允许重复添加相同的块到属性视图中
|
||||||
for _, row := range attrView.Rows {
|
for _, row := range attrView.Rows {
|
||||||
if row[0].Value() == blockID {
|
if row.Cells[0].(*av.Cell).Value == blockID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var row []av.Cell
|
row := av.NewRow()
|
||||||
row = append(row, av.NewCellBlock(block.ID))
|
row.Cells = append(row.Cells, av.NewCellBlock(block.ID))
|
||||||
if 1 < len(attrView.Columns) {
|
if 1 < len(attrView.Columns) {
|
||||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
|
|
||||||
for _, col := range attrView.Columns[1:] {
|
for _, col := range attrView.Columns[1:] {
|
||||||
colName := col.Name()
|
colName := col.(*av.Column).Name
|
||||||
attrs[colName] = ""
|
attrs[colName] = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue