Skip to content

Commit

Permalink
🎨 Database template column support using values from other columns #9327
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 3, 2023
1 parent 29f34fe commit cc3b4e3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions kernel/model/attribute_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func renderTemplateCol(blockID, tplContent string, rowValues []*av.KeyValues) st
dataModel[strings.ReplaceAll(k, "custom-", "custom_")] = v
}
for _, rowValue := range rowValues {
dataModel[rowValue.Key.Name] = rowValue.Values[0].String()
if 0 < len(rowValue.Values) {
dataModel[rowValue.Key.Name] = rowValue.Values[0].String()
}
}
if err := tpl.Execute(buf, dataModel); nil != err {
logging.LogWarnf("execute template [%s] failed: %s", tplContent, err)
Expand Down Expand Up @@ -111,8 +113,9 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
// 渲染模板列
for _, kv := range keyValues {
if av.KeyTypeTemplate == kv.Key.Type {
content := renderTemplateCol(blockID, kv.Key.Template, keyValues)
kv.Values[0].Template.Content = content
if 0 < len(kv.Values) {
kv.Values[0].Template.Content = renderTemplateCol(blockID, kv.Key.Template, keyValues)
}
}
}

Expand Down Expand Up @@ -222,7 +225,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
for _, val := range keyValues.Values {
values := rows[val.BlockID]
if nil == values {
values = []*av.KeyValues{&av.KeyValues{Key: keyValues.Key, Values: []*av.Value{val}}}
values = []*av.KeyValues{{Key: keyValues.Key, Values: []*av.Value{val}}}
} else {
values = append(values, &av.KeyValues{Key: keyValues.Key, Values: []*av.Value{val}})
}
Expand Down Expand Up @@ -327,7 +330,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a

func getRowBlockValue(keyValues []*av.KeyValues) (ret *av.Value) {
for _, kv := range keyValues {
if av.KeyTypeBlock == kv.Key.Type {
if av.KeyTypeBlock == kv.Key.Type && 0 < len(kv.Values) {
ret = kv.Values[0]
break
}
Expand Down

0 comments on commit cc3b4e3

Please sign in to comment.