Skip to content

Commit

Permalink
🎨 Add created and updated type column to database #9371
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 9, 2023
1 parent 8a245a3 commit 9288e52
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions kernel/model/attribute_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,47 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
}
}

if av.KeyTypeTemplate == kValues.Key.Type {
switch kValues.Key.Type {
case av.KeyTypeTemplate:
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeTemplate, Template: &av.ValueTemplate{Content: ""}})
case av.KeyTypeCreated:
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeCreated})
case av.KeyTypeUpdated:
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeUpdated})
}

if 0 < len(kValues.Values) {
keyValues = append(keyValues, kValues)
}
}

// 渲染模板列
// 渲染自动生成的列值,比如模板列、创建时间列和更新时间列
for _, kv := range keyValues {
if av.KeyTypeTemplate == kv.Key.Type {
switch kv.Key.Type {
case av.KeyTypeTemplate:
if 0 < len(kv.Values) {
ial := GetBlockAttrs(blockID)
kv.Values[0].Template.Content = renderTemplateCol(ial, kv.Key.Template, keyValues)
}
case av.KeyTypeCreated:
createdStr := blockID[:len("20060102150405")]
created, parseErr := time.Parse("20060102150405", createdStr)
if nil == parseErr {
kv.Values[0].Created = av.NewFormattedValueCreated(created.UnixMilli(), 0, av.CreatedFormatNone)
} else {
logging.LogWarnf("parse created [%s] failed: %s", createdStr, parseErr)
kv.Values[0].Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)
}
case av.KeyTypeUpdated:
ial := GetBlockAttrs(blockID)
updatedStr := ial["updated"]
updated, parseErr := time.Parse("20060102150405", updatedStr)
if nil == parseErr {
kv.Values[0].Updated = av.NewFormattedValueUpdated(updated.UnixMilli(), 0, av.UpdatedFormatNone)
} else {
logging.LogWarnf("parse updated [%s] failed: %s", updatedStr, parseErr)
kv.Values[0].Updated = av.NewFormattedValueUpdated(time.Now().UnixMilli(), 0, av.UpdatedFormatNone)
}
}
}

Expand Down

0 comments on commit 9288e52

Please sign in to comment.