mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 10:00:13 +01:00
🎨 The database date field supports filling the current time by default https://github.com/siyuan-note/siyuan/issues/10823
This commit is contained in:
parent
9bdf885763
commit
66e2b0eaa7
3 changed files with 62 additions and 11 deletions
|
|
@ -91,20 +91,23 @@ type Key struct {
|
||||||
|
|
||||||
// 以下是某些列类型的特有属性
|
// 以下是某些列类型的特有属性
|
||||||
|
|
||||||
// 单选/多选列
|
// 单选/多选
|
||||||
Options []*SelectOption `json:"options,omitempty"` // 选项列表
|
Options []*SelectOption `json:"options,omitempty"` // 选项列表
|
||||||
|
|
||||||
// 数字列
|
// 数字
|
||||||
NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
|
NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
|
||||||
|
|
||||||
// 模板列
|
// 模板
|
||||||
Template string `json:"template"` // 模板内容
|
Template string `json:"template"` // 模板内容
|
||||||
|
|
||||||
// 关联列
|
// 关联
|
||||||
Relation *Relation `json:"relation,omitempty"` // 关联信息
|
Relation *Relation `json:"relation,omitempty"` // 关联信息
|
||||||
|
|
||||||
// 汇总列
|
// 汇总
|
||||||
Rollup *Rollup `json:"rollup,omitempty"` // 汇总信息
|
Rollup *Rollup `json:"rollup,omitempty"` // 汇总信息
|
||||||
|
|
||||||
|
// 日期
|
||||||
|
Date *Date `json:"date,omitempty"` // 日期设置
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKey(id, name, icon string, keyType KeyType) *Key {
|
func NewKey(id, name, icon string, keyType KeyType) *Key {
|
||||||
|
|
@ -116,6 +119,10 @@ func NewKey(id, name, icon string, keyType KeyType) *Key {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Date struct {
|
||||||
|
AutoFillNow bool `json:"autoFillNow"` // 是否自动填充当前时间 The database date field supports filling the current time by default https://github.com/siyuan-note/siyuan/issues/10823
|
||||||
|
}
|
||||||
|
|
||||||
type Rollup struct {
|
type Rollup struct {
|
||||||
RelationKeyID string `json:"relationKeyID"` // 关联列 ID
|
RelationKeyID string `json:"relationKeyID"` // 关联列 ID
|
||||||
KeyID string `json:"keyID"` // 目标列 ID
|
KeyID string `json:"keyID"` // 目标列 ID
|
||||||
|
|
|
||||||
|
|
@ -1184,6 +1184,36 @@ func getRowBlockValue(keyValues []*av.KeyValues) (ret *av.Value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tx *Transaction) doSetAttrViewColDate(operation *Operation) (ret *TxErr) {
|
||||||
|
err := setAttributeViewColDate(operation)
|
||||||
|
if nil != err {
|
||||||
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func setAttributeViewColDate(operation *Operation) (err error) {
|
||||||
|
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
keyID := operation.ID
|
||||||
|
key, _ := attrView.GetKey(keyID)
|
||||||
|
if nil == key || av.KeyTypeDate != key.Type {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if nil == key.Date {
|
||||||
|
key.Date = &av.Date{}
|
||||||
|
}
|
||||||
|
|
||||||
|
key.Date.AutoFillNow = operation.Data.(bool)
|
||||||
|
|
||||||
|
err = av.SaveAttributeView(attrView)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doHideAttrViewName(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doHideAttrViewName(operation *Operation) (ret *TxErr) {
|
||||||
err := hideAttrViewName(operation)
|
err := hideAttrViewName(operation)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -2104,27 +2134,39 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理日期字段默认填充当前创建时间
|
||||||
|
// The database date field supports filling the current time by default https://github.com/siyuan-note/siyuan/issues/10823
|
||||||
|
for _, keyValues := range attrView.KeyValues {
|
||||||
|
if av.KeyTypeDate == keyValues.Key.Type && nil != keyValues.Key.Date && keyValues.Key.Date.AutoFillNow {
|
||||||
|
dateVal := &av.Value{
|
||||||
|
ID: ast.NewNodeID(), KeyID: keyValues.Key.ID, BlockID: addingBlockID, Type: av.KeyTypeDate, IsDetached: isDetached, CreatedAt: now, UpdatedAt: now + 1000,
|
||||||
|
Date: &av.ValueDate{Content: now, IsNotEmpty: true},
|
||||||
|
}
|
||||||
|
keyValues.Values = append(keyValues.Values, dateVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !isDetached {
|
if !isDetached {
|
||||||
bindBlockAv0(tx, avID, blockID, node, tree)
|
bindBlockAv0(tx, avID, blockID, node, tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, view := range attrView.Views {
|
for _, v := range attrView.Views {
|
||||||
switch view.LayoutType {
|
switch v.LayoutType {
|
||||||
case av.LayoutTypeTable:
|
case av.LayoutTypeTable:
|
||||||
if "" != previousBlockID {
|
if "" != previousBlockID {
|
||||||
changed := false
|
changed := false
|
||||||
for i, id := range view.Table.RowIDs {
|
for i, id := range v.Table.RowIDs {
|
||||||
if id == previousBlockID {
|
if id == previousBlockID {
|
||||||
view.Table.RowIDs = append(view.Table.RowIDs[:i+1], append([]string{addingBlockID}, view.Table.RowIDs[i+1:]...)...)
|
v.Table.RowIDs = append(v.Table.RowIDs[:i+1], append([]string{addingBlockID}, v.Table.RowIDs[i+1:]...)...)
|
||||||
changed = true
|
changed = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !changed {
|
if !changed {
|
||||||
view.Table.RowIDs = append(view.Table.RowIDs, addingBlockID)
|
v.Table.RowIDs = append(v.Table.RowIDs, addingBlockID)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
view.Table.RowIDs = append([]string{addingBlockID}, view.Table.RowIDs...)
|
v.Table.RowIDs = append([]string{addingBlockID}, v.Table.RowIDs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
||||||
ret = tx.doUpdateAttrViewColRollup(op)
|
ret = tx.doUpdateAttrViewColRollup(op)
|
||||||
case "hideAttrViewName":
|
case "hideAttrViewName":
|
||||||
ret = tx.doHideAttrViewName(op)
|
ret = tx.doHideAttrViewName(op)
|
||||||
|
case "setAttrViewColDate":
|
||||||
|
ret = tx.doSetAttrViewColDate(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != ret {
|
if nil != ret {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue