mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 Improve default value filling https://github.com/siyuan-note/siyuan/issues/10038
This commit is contained in:
parent
a12f3f5c42
commit
d7e5411e55
2 changed files with 63 additions and 8 deletions
|
|
@ -246,15 +246,21 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
if nil != destAv {
|
if nil != destAv {
|
||||||
for _, bID := range relVal.Relation.BlockIDs {
|
for _, bID := range relVal.Relation.BlockIDs {
|
||||||
destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID)
|
destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID)
|
||||||
if nil != destVal {
|
if nil == destVal {
|
||||||
if av.KeyTypeNumber == destVal.Type {
|
destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID)
|
||||||
destVal.Number.Format = kv.Key.NumberFormat
|
if nil == destKey {
|
||||||
destVal.Number.FormatNumber()
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
kv.Values[0].Rollup.Contents = append(kv.Values[0].Rollup.Contents, destVal.String())
|
destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, blockID, destKey.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if av.KeyTypeNumber == destVal.Type {
|
||||||
|
destVal.Number.Format = kv.Key.NumberFormat
|
||||||
|
destVal.Number.FormatNumber()
|
||||||
|
}
|
||||||
|
|
||||||
|
kv.Values[0].Rollup.Contents = append(kv.Values[0].Rollup.Contents, destVal.String())
|
||||||
kv.Values[0].Rollup.RenderContents(kv.Key.Rollup.Calc)
|
kv.Values[0].Rollup.RenderContents(kv.Key.Rollup.Calc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -814,7 +820,12 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
||||||
for _, blockID := range relVal.Relation.BlockIDs {
|
for _, blockID := range relVal.Relation.BlockIDs {
|
||||||
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
||||||
if nil == destVal {
|
if nil == destVal {
|
||||||
continue
|
destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID)
|
||||||
|
if nil == destKey {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
||||||
}
|
}
|
||||||
if av.KeyTypeNumber == destVal.Type {
|
if av.KeyTypeNumber == destVal.Type {
|
||||||
destVal.Number.Format = rollupKey.NumberFormat
|
destVal.Number.Format = rollupKey.NumberFormat
|
||||||
|
|
|
||||||
|
|
@ -777,7 +777,12 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
||||||
for _, blockID := range relVal.Relation.BlockIDs {
|
for _, blockID := range relVal.Relation.BlockIDs {
|
||||||
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
||||||
if nil == destVal {
|
if nil == destVal {
|
||||||
continue
|
destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID)
|
||||||
|
if nil == destKey {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
||||||
}
|
}
|
||||||
if av.KeyTypeNumber == destVal.Type {
|
if av.KeyTypeNumber == destVal.Type {
|
||||||
destVal.Number.Format = rollupKey.NumberFormat
|
destVal.Number.Format = rollupKey.NumberFormat
|
||||||
|
|
@ -841,8 +846,10 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
||||||
|
|
||||||
func FillAttributeViewTableCellNilValue(tableCell *av.TableCell, rowID, colID string) {
|
func FillAttributeViewTableCellNilValue(tableCell *av.TableCell, rowID, colID string) {
|
||||||
if nil == tableCell.Value {
|
if nil == tableCell.Value {
|
||||||
tableCell.Value = &av.Value{ID: tableCell.ID, KeyID: colID, BlockID: rowID, Type: tableCell.ValueType}
|
tableCell.Value = GetAttributeViewDefaultValue(tableCell.ID, colID, rowID, tableCell.ValueType)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tableCell.Value.Type = tableCell.ValueType
|
tableCell.Value.Type = tableCell.ValueType
|
||||||
switch tableCell.ValueType {
|
switch tableCell.ValueType {
|
||||||
case av.KeyTypeText:
|
case av.KeyTypeText:
|
||||||
|
|
@ -908,6 +915,43 @@ func FillAttributeViewTableCellNilValue(tableCell *av.TableCell, rowID, colID st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAttributeViewDefaultValue(valueID, keyID, blockID string, typ av.KeyType) (ret *av.Value) {
|
||||||
|
ret = &av.Value{ID: valueID, KeyID: keyID, BlockID: blockID, Type: typ}
|
||||||
|
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, tplContent string, rowValues []*av.KeyValues) string {
|
func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av.KeyValues) string {
|
||||||
if "" == ial["id"] {
|
if "" == ial["id"] {
|
||||||
block := getRowBlockValue(rowValues)
|
block := getRowBlockValue(rowValues)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue