Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-10-08 15:43:40 +08:00
commit 8985c9b3a9
3 changed files with 41 additions and 17 deletions

View file

@ -16,7 +16,7 @@ import {setKey} from "../sync/syncGuide";
export const about = {
element: undefined as Element,
genHTML: () => {
return `<label class="fn__flex b3-label${isBrowser() || "std" !== window.siyuan.config.system.container || "linux" === window.siyuan.config.system.os ? " fn__none" : ""}">
return `<label class="fn__flex b3-label${isBrowser() || window.siyuan.config.system.isMicrosoftStore || "std" !== window.siyuan.config.system.container || "linux" === window.siyuan.config.system.os ? " fn__none" : ""}">
<div class="fn__flex-1">
${window.siyuan.languages.autoLaunch}
<div class="b3-label__text">${window.siyuan.languages.autoLaunchTip}</div>

View file

@ -39,7 +39,7 @@ type BlockAttributeViewKeys struct {
KeyValues []*av.KeyValues `json:"keyValues"`
}
func renderTemplateCol(blockID, tplContent string, rowValues []*av.KeyValues) string {
func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av.KeyValues) string {
funcMap := sprig.TxtFuncMap()
goTpl := template.New("").Delims(".action{", "}")
tplContent = strings.ReplaceAll(tplContent, ".custom-", ".custom_") // 模板中的属性名不允许包含 - 字符,因此这里需要替换
@ -50,7 +50,6 @@ func renderTemplateCol(blockID, tplContent string, rowValues []*av.KeyValues) st
}
buf := &bytes.Buffer{}
ial := GetBlockAttrs(blockID)
dataModel := map[string]interface{}{} // 复制一份 IAL 以避免修改原始数据
for k, v := range ial {
dataModel[strings.ReplaceAll(k, "custom-", "custom_")] = v
@ -141,7 +140,8 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
for _, kv := range keyValues {
if av.KeyTypeTemplate == kv.Key.Type {
if 0 < len(kv.Values) {
kv.Values[0].Template.Content = renderTemplateCol(blockID, kv.Key.Template, keyValues)
ial := GetBlockAttrs(blockID)
kv.Values[0].Template.Content = renderTemplateCol(ial, kv.Key.Template, keyValues)
}
}
}
@ -309,15 +309,18 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
}
tableRow.ID = rowID
// 格式化数字
if av.KeyTypeNumber == tableCell.ValueType && nil != tableCell.Value && nil != tableCell.Value.Number && tableCell.Value.Number.IsNotEmpty {
tableCell.Value.Number.Format = col.NumberFormat
tableCell.Value.Number.FormatNumber()
}
// 渲染模板列
if av.KeyTypeTemplate == tableCell.ValueType {
switch tableCell.ValueType {
case av.KeyTypeNumber: // 格式化数字
if nil != tableCell.Value && nil != tableCell.Value.Number && tableCell.Value.Number.IsNotEmpty {
tableCell.Value.Number.Format = col.NumberFormat
tableCell.Value.Number.FormatNumber()
}
case av.KeyTypeTemplate: // 渲染模板列
tableCell.Value = &av.Value{ID: tableCell.ID, KeyID: col.ID, BlockID: rowID, Type: av.KeyTypeTemplate, Template: &av.ValueTemplate{Content: col.Template}}
case av.KeyTypeCreated: // 填充创建时间列值,后面再渲染
tableCell.Value = &av.Value{ID: tableCell.ID, KeyID: col.ID, BlockID: rowID, Type: av.KeyTypeCreated}
case av.KeyTypeUpdated: // 填充更新时间列值,后面再渲染
tableCell.Value = &av.Value{ID: tableCell.ID, KeyID: col.ID, BlockID: rowID, Type: av.KeyTypeUpdated}
}
tableRow.Cells = append(tableRow.Cells, tableCell)
@ -325,13 +328,34 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
ret.Rows = append(ret.Rows, &tableRow)
}
// 渲染模板
// 渲染自动生成的列值,比如模板列、创建时间列和更新时间
for _, row := range ret.Rows {
for _, cell := range row.Cells {
if av.KeyTypeTemplate == cell.ValueType {
switch cell.ValueType {
case av.KeyTypeTemplate: // 渲染模板列
keyValues := rows[row.ID]
content := renderTemplateCol(row.ID, cell.Value.Template.Content, keyValues)
ial := GetBlockAttrs(row.ID)
content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)
cell.Value.Template.Content = content
case av.KeyTypeCreated: // 渲染创建时间
createdStr := row.ID[:len("20060102150405")]
created, parseErr := time.Parse("20060102150405", createdStr)
if nil == parseErr {
cell.Value.Created = av.NewFormattedValueCreated(created.Unix(), 0, av.CreatedFormatNone)
} else {
logging.LogWarnf("parse created [%s] failed: %s", createdStr, parseErr)
cell.Value.Created = av.NewFormattedValueCreated(time.Now().Unix(), 0, av.CreatedFormatNone)
}
case av.KeyTypeUpdated: // 渲染更新时间
ial := GetBlockAttrs(row.ID)
updatedStr := ial["updated"]
updated, parseErr := time.Parse("20060102150405", updatedStr)
if nil == parseErr {
cell.Value.Created = av.NewFormattedValueCreated(updated.Unix(), 0, av.CreatedFormatNone)
} else {
logging.LogWarnf("parse updated [%s] failed: %s", updatedStr, parseErr)
cell.Value.Created = av.NewFormattedValueCreated(time.Now().Unix(), 0, av.CreatedFormatNone)
}
}
}
}

View file

@ -1915,11 +1915,11 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
}
} else if av.KeyTypeCreated == cell.Value.Type {
if nil != cell.Value.Created {
cell.Value.Created = av.NewFormattedValueCreated(cell.Value.Date.Content, av.CreatedFormatNone)
cell.Value.Created = av.NewFormattedValueCreated(cell.Value.Date.Content, 0, av.CreatedFormatNone)
}
} else if av.KeyTypeUpdated == cell.Value.Type {
if nil != cell.Value.Updated {
cell.Value.Updated = av.NewFormattedValueUpdated(cell.Value.Date.Content, av.UpdatedFormatNone)
cell.Value.Updated = av.NewFormattedValueUpdated(cell.Value.Date.Content, 0, av.UpdatedFormatNone)
}
}