🎨 Clean code

This commit is contained in:
Daniel 2024-04-17 19:38:27 +08:00
parent 46402dd709
commit 25a75982c9
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 59 additions and 58 deletions

View file

@ -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
}