mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 The database supports adding view/field/option description https://github.com/siyuan-note/siyuan/issues/11053
This commit is contained in:
parent
d9bcb12c34
commit
9371c68ec9
5 changed files with 108 additions and 9 deletions
|
|
@ -102,12 +102,13 @@ const (
|
|||
KeyTypeLineNumber KeyType = "lineNumber"
|
||||
)
|
||||
|
||||
// Key 描述了属性视图属性列的基础结构。
|
||||
// Key 描述了属性视图属性字段的基础结构。
|
||||
type Key struct {
|
||||
ID string `json:"id"` // 列 ID
|
||||
Name string `json:"name"` // 列名
|
||||
Type KeyType `json:"type"` // 列类型
|
||||
Icon string `json:"icon"` // 列图标
|
||||
ID string `json:"id"` // 字段 ID
|
||||
Name string `json:"name"` // 字段名
|
||||
Type KeyType `json:"type"` // 字段类型
|
||||
Icon string `json:"icon"` // 字段图标
|
||||
Desc string `json:"desc"` // 字段描述
|
||||
|
||||
// 以下是某些列类型的特有属性
|
||||
|
||||
|
|
@ -154,8 +155,8 @@ type Date struct {
|
|||
}
|
||||
|
||||
type Rollup struct {
|
||||
RelationKeyID string `json:"relationKeyID"` // 关联列 ID
|
||||
KeyID string `json:"keyID"` // 目标列 ID
|
||||
RelationKeyID string `json:"relationKeyID"` // 关联字段 ID
|
||||
KeyID string `json:"keyID"` // 目标字段 ID
|
||||
Calc *RollupCalc `json:"calc"` // 计算方式
|
||||
}
|
||||
|
||||
|
|
@ -171,8 +172,9 @@ type Relation struct {
|
|||
}
|
||||
|
||||
type SelectOption struct {
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
Name string `json:"name"` // 选项名称
|
||||
Color string `json:"color"` // 选项颜色
|
||||
Desc string `json:"desc"` // 选项描述
|
||||
}
|
||||
|
||||
// View 描述了视图的结构。
|
||||
|
|
@ -181,6 +183,7 @@ type View struct {
|
|||
Icon string `json:"icon"` // 视图图标
|
||||
Name string `json:"name"` // 视图名称
|
||||
HideAttrViewName bool `json:"hideAttrViewName"` // 是否隐藏属性视图名称
|
||||
Desc string `json:"desc"` // 视图描述
|
||||
|
||||
LayoutType LayoutType `json:"type"` // 当前布局类型
|
||||
Table *LayoutTable `json:"table,omitempty"` // 表格布局
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ type ViewTableColumn struct {
|
|||
Hidden bool `json:"hidden"` // 是否隐藏
|
||||
Pin bool `json:"pin"` // 是否固定
|
||||
Width string `json:"width"` // 列宽度
|
||||
Desc string `json:"desc,omitempty"` // 列描述
|
||||
Calc *ColumnCalc `json:"calc,omitempty"` // 计算
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +48,7 @@ type Table struct {
|
|||
ID string `json:"id"` // 表格布局 ID
|
||||
Icon string `json:"icon"` // 表格图标
|
||||
Name string `json:"name"` // 表格名称
|
||||
Desc string `json:"desc"` // 表格描述
|
||||
HideAttrViewName bool `json:"hideAttrViewName"` // 是否隐藏属性视图名称
|
||||
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
||||
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
||||
|
|
@ -65,6 +67,7 @@ type TableColumn struct {
|
|||
Hidden bool `json:"hidden"` // 是否隐藏
|
||||
Pin bool `json:"pin"` // 是否固定
|
||||
Width string `json:"width"` // 列宽度
|
||||
Desc string `json:"desc"` // 列描述
|
||||
Calc *ColumnCalc `json:"calc"` // 计算
|
||||
|
||||
// 以下是某些列类型的特有属性
|
||||
|
|
|
|||
|
|
@ -1527,6 +1527,7 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
|
|||
Hidden: col.Hidden,
|
||||
Pin: col.Pin,
|
||||
Width: col.Width,
|
||||
Desc: col.Desc,
|
||||
Calc: col.Calc,
|
||||
})
|
||||
}
|
||||
|
|
@ -1658,6 +1659,30 @@ func (tx *Transaction) doSetAttrViewViewIcon(operation *Operation) (ret *TxErr)
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewViewDesc(operation *Operation) (ret *TxErr) {
|
||||
var err error
|
||||
avID := operation.AvID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
||||
}
|
||||
|
||||
viewID := operation.ID
|
||||
view := attrView.GetView(viewID)
|
||||
if nil == view {
|
||||
logging.LogErrorf("get view [%s] failed: %s", viewID, err)
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: viewID}
|
||||
}
|
||||
|
||||
view.Desc = strings.TrimSpace(operation.Data.(string))
|
||||
if err = av.SaveAttributeView(attrView); err != nil {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrWriteAttributeView, msg: err.Error(), id: avID}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewName(operation *Operation) (ret *TxErr) {
|
||||
err := tx.setAttributeViewName(operation)
|
||||
if err != nil {
|
||||
|
|
@ -2247,6 +2272,7 @@ func duplicateAttributeViewKey(operation *Operation) (err error) {
|
|||
Hidden: column.Hidden,
|
||||
Pin: column.Pin,
|
||||
Width: column.Width,
|
||||
Desc: column.Desc,
|
||||
},
|
||||
}, view.Table.Columns[i+1:]...)...)
|
||||
break
|
||||
|
|
@ -2416,6 +2442,31 @@ func setAttributeViewColIcon(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColumnDesc(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColDesc(operation)
|
||||
if err != nil {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewColDesc(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, keyValues := range attrView.KeyValues {
|
||||
if keyValues.Key.ID == operation.ID {
|
||||
keyValues.Key.Desc = operation.Data.(string)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSortAttrViewRow(operation *Operation) (ret *TxErr) {
|
||||
err := sortAttributeViewRow(operation)
|
||||
if err != nil {
|
||||
|
|
@ -3472,6 +3523,40 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColOptionDesc(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColumnOptionDesc(operation)
|
||||
if err != nil {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewColumnOptionDesc(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
key, err := attrView.GetKey(operation.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data := operation.Data.(map[string]interface{})
|
||||
name := data["name"].(string)
|
||||
desc := data["desc"].(string)
|
||||
|
||||
for i, opt := range key.Options {
|
||||
if name == opt.Name {
|
||||
key.Options[i].Desc = desc
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func getAttrViewViewByBlockID(attrView *av.AttributeView, blockID string) (ret *av.View, err error) {
|
||||
node, _, _ := getNodeByBlockID(nil, blockID)
|
||||
var viewID string
|
||||
|
|
|
|||
|
|
@ -216,6 +216,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doSetAttrViewColumnPin(op)
|
||||
case "setAttrViewColIcon":
|
||||
ret = tx.doSetAttrViewColumnIcon(op)
|
||||
case "setAttrViewColDesc":
|
||||
ret = tx.doSetAttrViewColumnDesc(op)
|
||||
case "insertAttrViewBlock":
|
||||
ret = tx.doInsertAttrViewBlock(op)
|
||||
case "removeAttrViewBlock":
|
||||
|
|
@ -240,6 +242,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doRemoveAttrViewColOption(op)
|
||||
case "updateAttrViewColOption":
|
||||
ret = tx.doUpdateAttrViewColOption(op)
|
||||
case "setAttrViewColOptionDesc":
|
||||
ret = tx.doSetAttrViewColOptionDesc(op)
|
||||
case "setAttrViewColCalc":
|
||||
ret = tx.doSetAttrViewColCalc(op)
|
||||
case "updateAttrViewColNumberFormat":
|
||||
|
|
@ -256,6 +260,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doSetAttrViewViewName(op)
|
||||
case "setAttrViewViewIcon":
|
||||
ret = tx.doSetAttrViewViewIcon(op)
|
||||
case "setAttrViewViewDesc":
|
||||
ret = tx.doSetAttrViewViewDesc(op)
|
||||
case "duplicateAttrViewView":
|
||||
ret = tx.doDuplicateAttrViewView(op)
|
||||
case "sortAttrViewView":
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||
ID: view.ID,
|
||||
Icon: view.Icon,
|
||||
Name: view.Name,
|
||||
Desc: view.Desc,
|
||||
HideAttrViewName: view.HideAttrViewName,
|
||||
Columns: []*av.TableColumn{},
|
||||
Rows: []*av.TableRow{},
|
||||
|
|
@ -78,6 +79,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||
Wrap: col.Wrap,
|
||||
Hidden: col.Hidden,
|
||||
Width: col.Width,
|
||||
Desc: col.Desc,
|
||||
Pin: col.Pin,
|
||||
Calc: col.Calc,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue