🎨 Clean code
This commit is contained in:
parent
46402dd709
commit
25a75982c9
3 changed files with 59 additions and 58 deletions
|
@ -25,6 +25,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
|
@ -902,3 +903,56 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc, destKey *Key) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetAttributeViewDefaultValue(valueID, keyID, blockID string, typ KeyType) (ret *Value) {
|
||||
if "" == valueID {
|
||||
valueID = ast.NewNodeID()
|
||||
}
|
||||
|
||||
ret = &Value{ID: valueID, KeyID: keyID, BlockID: blockID, Type: typ}
|
||||
|
||||
createdStr := valueID[:len("20060102150405")]
|
||||
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
|
||||
if nil == parseErr {
|
||||
ret.CreatedAt = created.UnixMilli()
|
||||
} else {
|
||||
ret.CreatedAt = time.Now().UnixMilli()
|
||||
}
|
||||
if 0 == ret.UpdatedAt {
|
||||
ret.UpdatedAt = ret.CreatedAt
|
||||
}
|
||||
|
||||
switch typ {
|
||||
case KeyTypeText:
|
||||
ret.Text = &ValueText{}
|
||||
case KeyTypeNumber:
|
||||
ret.Number = &ValueNumber{}
|
||||
case KeyTypeDate:
|
||||
ret.Date = &ValueDate{}
|
||||
case KeyTypeSelect:
|
||||
ret.MSelect = []*ValueSelect{}
|
||||
case KeyTypeMSelect:
|
||||
ret.MSelect = []*ValueSelect{}
|
||||
case KeyTypeURL:
|
||||
ret.URL = &ValueURL{}
|
||||
case KeyTypeEmail:
|
||||
ret.Email = &ValueEmail{}
|
||||
case KeyTypePhone:
|
||||
ret.Phone = &ValuePhone{}
|
||||
case KeyTypeMAsset:
|
||||
ret.MAsset = []*ValueAsset{}
|
||||
case KeyTypeTemplate:
|
||||
ret.Template = &ValueTemplate{}
|
||||
case KeyTypeCreated:
|
||||
ret.Created = &ValueCreated{}
|
||||
case KeyTypeUpdated:
|
||||
ret.Updated = &ValueUpdated{}
|
||||
case KeyTypeCheckbox:
|
||||
ret.Checkbox = &ValueCheckbox{}
|
||||
case KeyTypeRelation:
|
||||
ret.Relation = &ValueRelation{}
|
||||
case KeyTypeRollup:
|
||||
ret.Rollup = &ValueRollup{}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -398,7 +398,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|||
keyValues = append(keyValues, kValues)
|
||||
} else {
|
||||
// 如果没有值,那么就补一个默认值
|
||||
kValues.Values = append(kValues.Values, treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.ID, blockID, kv.Key.Type))
|
||||
kValues.Values = append(kValues.Values, av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.ID, blockID, kv.Key.Type))
|
||||
keyValues = append(keyValues, kValues)
|
||||
}
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|||
destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID)
|
||||
if nil == destVal {
|
||||
if destAv.ExistBlock(bID) { // 数据库中存在行但是列值不存在是数据未初始化,这里补一个默认值
|
||||
destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, bID, destKey.Type)
|
||||
destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, bID, destKey.Type)
|
||||
}
|
||||
if nil == destVal {
|
||||
continue
|
||||
|
@ -1118,7 +1118,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
||||
if nil == destVal {
|
||||
if destAv.ExistBlock(blockID) { // 数据库中存在行但是列值不存在是数据未初始化,这里补一个默认值
|
||||
destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
||||
destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
||||
}
|
||||
if nil == destVal {
|
||||
continue
|
||||
|
|
|
@ -765,7 +765,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
|||
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
||||
if nil == destVal {
|
||||
if destAv.ExistBlock(blockID) { // 数据库中存在行但是列值不存在是数据未初始化,这里补一个默认值
|
||||
destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
||||
destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
||||
}
|
||||
if nil == destVal {
|
||||
continue
|
||||
|
@ -870,7 +870,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
|||
|
||||
func FillAttributeViewTableCellNilValue(tableCell *av.TableCell, rowID, colID string) {
|
||||
if nil == tableCell.Value {
|
||||
tableCell.Value = GetAttributeViewDefaultValue(tableCell.ID, colID, rowID, tableCell.ValueType)
|
||||
tableCell.Value = av.GetAttributeViewDefaultValue(tableCell.ID, colID, rowID, tableCell.ValueType)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -939,59 +939,6 @@ func FillAttributeViewTableCellNilValue(tableCell *av.TableCell, rowID, colID st
|
|||
}
|
||||
}
|
||||
|
||||
func GetAttributeViewDefaultValue(valueID, keyID, blockID string, typ av.KeyType) (ret *av.Value) {
|
||||
if "" == valueID {
|
||||
valueID = ast.NewNodeID()
|
||||
}
|
||||
|
||||
ret = &av.Value{ID: valueID, KeyID: keyID, BlockID: blockID, Type: typ}
|
||||
|
||||
createdStr := valueID[:len("20060102150405")]
|
||||
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
|
||||
if nil == parseErr {
|
||||
ret.CreatedAt = created.UnixMilli()
|
||||
} else {
|
||||
ret.CreatedAt = time.Now().UnixMilli()
|
||||
}
|
||||
if 0 == ret.UpdatedAt {
|
||||
ret.UpdatedAt = ret.CreatedAt
|
||||
}
|
||||
|
||||
switch typ {
|
||||
case av.KeyTypeText:
|
||||
ret.Text = &av.ValueText{}
|
||||
case av.KeyTypeNumber:
|
||||
ret.Number = &av.ValueNumber{}
|
||||
case av.KeyTypeDate:
|
||||
ret.Date = &av.ValueDate{}
|
||||
case av.KeyTypeSelect:
|
||||
ret.MSelect = []*av.ValueSelect{}
|
||||
case av.KeyTypeMSelect:
|
||||
ret.MSelect = []*av.ValueSelect{}
|
||||
case av.KeyTypeURL:
|
||||
ret.URL = &av.ValueURL{}
|
||||
case av.KeyTypeEmail:
|
||||
ret.Email = &av.ValueEmail{}
|
||||
case av.KeyTypePhone:
|
||||
ret.Phone = &av.ValuePhone{}
|
||||
case av.KeyTypeMAsset:
|
||||
ret.MAsset = []*av.ValueAsset{}
|
||||
case av.KeyTypeTemplate:
|
||||
ret.Template = &av.ValueTemplate{}
|
||||
case av.KeyTypeCreated:
|
||||
ret.Created = &av.ValueCreated{}
|
||||
case av.KeyTypeUpdated:
|
||||
ret.Updated = &av.ValueUpdated{}
|
||||
case av.KeyTypeCheckbox:
|
||||
ret.Checkbox = &av.ValueCheckbox{}
|
||||
case av.KeyTypeRelation:
|
||||
ret.Relation = &av.ValueRelation{}
|
||||
case av.KeyTypeRollup:
|
||||
ret.Rollup = &av.ValueRollup{}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func renderTemplateCol(ial map[string]string, rowValues []*av.KeyValues, tplContent string) string {
|
||||
if "" == ial["id"] {
|
||||
block := getRowBlockValue(rowValues)
|
||||
|
|
Loading…
Add table
Reference in a new issue