Skip to content

Commit 0aa61fe

Browse files
committed
🎨 Add template type column to Attribute View #8766
1 parent 7d1e1bf commit 0aa61fe

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

kernel/av/av.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (value *Value) String() string {
143143
}
144144
return strings.Join(ret, " ")
145145
case KeyTypeTemplate:
146-
return value.Template.content
146+
return value.Template.Content
147147
default:
148148
return ""
149149
}
@@ -351,11 +351,11 @@ type ValueAsset struct {
351351
}
352352

353353
type ValueTemplate struct {
354-
content string `json:"content"`
354+
Content string `json:"content"`
355355
}
356356

357357
func (t *ValueTemplate) Render(blockID string, r func(blockID string) string) {
358-
t.content = r(blockID)
358+
t.Content = r(blockID)
359359
}
360360

361361
// View 描述了视图的结构。

kernel/av/table.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
523523
case CalcOperatorCountValues:
524524
countValues := 0
525525
for _, row := range table.Rows {
526-
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.content {
526+
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
527527
countValues++
528528
}
529529
}
@@ -532,9 +532,9 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
532532
countUniqueValues := 0
533533
uniqueValues := map[string]bool{}
534534
for _, row := range table.Rows {
535-
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.content {
536-
if !uniqueValues[row.Cells[colIndex].Value.Template.content] {
537-
uniqueValues[row.Cells[colIndex].Value.Template.content] = true
535+
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
536+
if !uniqueValues[row.Cells[colIndex].Value.Template.Content] {
537+
uniqueValues[row.Cells[colIndex].Value.Template.Content] = true
538538
countUniqueValues++
539539
}
540540
}
@@ -543,23 +543,23 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
543543
case CalcOperatorCountEmpty:
544544
countEmpty := 0
545545
for _, row := range table.Rows {
546-
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.content {
546+
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.Content {
547547
countEmpty++
548548
}
549549
}
550550
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
551551
case CalcOperatorCountNotEmpty:
552552
countNotEmpty := 0
553553
for _, row := range table.Rows {
554-
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.content {
554+
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
555555
countNotEmpty++
556556
}
557557
}
558558
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
559559
case CalcOperatorPercentEmpty:
560560
countEmpty := 0
561561
for _, row := range table.Rows {
562-
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.content {
562+
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.Content {
563563
countEmpty++
564564
}
565565
}
@@ -569,7 +569,7 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
569569
case CalcOperatorPercentNotEmpty:
570570
countNotEmpty := 0
571571
for _, row := range table.Rows {
572-
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.content {
572+
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
573573
countNotEmpty++
574574
}
575575
}
@@ -969,16 +969,16 @@ func (table *Table) calcColNumber(col *TableColumn, colIndex int) {
969969
}
970970
}
971971
case CalcOperatorMin:
972-
min := math.MaxFloat64
972+
minVal := math.MaxFloat64
973973
for _, row := range table.Rows {
974974
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
975-
if row.Cells[colIndex].Value.Number.Content < min {
976-
min = row.Cells[colIndex].Value.Number.Content
975+
if row.Cells[colIndex].Value.Number.Content < minVal {
976+
minVal = row.Cells[colIndex].Value.Number.Content
977977
}
978978
}
979979
}
980-
if math.MaxFloat64 != min {
981-
col.Calc.Result = &Value{Number: NewFormattedValueNumber(min, col.NumberFormat)}
980+
if math.MaxFloat64 != minVal {
981+
col.Calc.Result = &Value{Number: NewFormattedValueNumber(minVal, col.NumberFormat)}
982982
}
983983
case CalcOperatorMax:
984984
maxVal := -math.MaxFloat64

kernel/model/attribute_view.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
232232
}
233233

234234
// 渲染模板列
235-
if av.KeyTypeTemplate == tableCell.ValueType && nil != tableCell.Value && nil != tableCell.Value.Template {
235+
if av.KeyTypeTemplate == tableCell.ValueType {
236236
render := func(blockID string) string {
237237
funcMap := sprig.TxtFuncMap()
238238
goTpl := template.New("").Delims(".action{", "}")
@@ -250,6 +250,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
250250
return buf.String()
251251
}
252252

253+
tableCell.Value = &av.Value{ID: tableCell.ID, KeyID: col.ID, BlockID: rowID, Type: av.KeyTypeTemplate, Template: &av.ValueTemplate{}}
253254
tableCell.Value.Template.Render(tableCell.Value.BlockID, render)
254255
}
255256

0 commit comments

Comments
 (0)