🎨 Add template type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8766
This commit is contained in:
parent
7d1e1bf2e5
commit
0aa61fe5b7
3 changed files with 18 additions and 17 deletions
|
@ -143,7 +143,7 @@ func (value *Value) String() string {
|
||||||
}
|
}
|
||||||
return strings.Join(ret, " ")
|
return strings.Join(ret, " ")
|
||||||
case KeyTypeTemplate:
|
case KeyTypeTemplate:
|
||||||
return value.Template.content
|
return value.Template.Content
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -351,11 +351,11 @@ type ValueAsset struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ValueTemplate struct {
|
type ValueTemplate struct {
|
||||||
content string `json:"content"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ValueTemplate) Render(blockID string, r func(blockID string) string) {
|
func (t *ValueTemplate) Render(blockID string, r func(blockID string) string) {
|
||||||
t.content = r(blockID)
|
t.Content = r(blockID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// View 描述了视图的结构。
|
// View 描述了视图的结构。
|
||||||
|
|
|
@ -523,7 +523,7 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
|
||||||
case CalcOperatorCountValues:
|
case CalcOperatorCountValues:
|
||||||
countValues := 0
|
countValues := 0
|
||||||
for _, row := range table.Rows {
|
for _, row := range table.Rows {
|
||||||
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.content {
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
||||||
countValues++
|
countValues++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -532,9 +532,9 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
|
||||||
countUniqueValues := 0
|
countUniqueValues := 0
|
||||||
uniqueValues := map[string]bool{}
|
uniqueValues := map[string]bool{}
|
||||||
for _, row := range table.Rows {
|
for _, row := range table.Rows {
|
||||||
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.content {
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
||||||
if !uniqueValues[row.Cells[colIndex].Value.Template.content] {
|
if !uniqueValues[row.Cells[colIndex].Value.Template.Content] {
|
||||||
uniqueValues[row.Cells[colIndex].Value.Template.content] = true
|
uniqueValues[row.Cells[colIndex].Value.Template.Content] = true
|
||||||
countUniqueValues++
|
countUniqueValues++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -543,7 +543,7 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
|
||||||
case CalcOperatorCountEmpty:
|
case CalcOperatorCountEmpty:
|
||||||
countEmpty := 0
|
countEmpty := 0
|
||||||
for _, row := range table.Rows {
|
for _, row := range table.Rows {
|
||||||
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.content {
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.Content {
|
||||||
countEmpty++
|
countEmpty++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -551,7 +551,7 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
|
||||||
case CalcOperatorCountNotEmpty:
|
case CalcOperatorCountNotEmpty:
|
||||||
countNotEmpty := 0
|
countNotEmpty := 0
|
||||||
for _, row := range table.Rows {
|
for _, row := range table.Rows {
|
||||||
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.content {
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
||||||
countNotEmpty++
|
countNotEmpty++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -559,7 +559,7 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
|
||||||
case CalcOperatorPercentEmpty:
|
case CalcOperatorPercentEmpty:
|
||||||
countEmpty := 0
|
countEmpty := 0
|
||||||
for _, row := range table.Rows {
|
for _, row := range table.Rows {
|
||||||
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.content {
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.Content {
|
||||||
countEmpty++
|
countEmpty++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -569,7 +569,7 @@ func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
|
||||||
case CalcOperatorPercentNotEmpty:
|
case CalcOperatorPercentNotEmpty:
|
||||||
countNotEmpty := 0
|
countNotEmpty := 0
|
||||||
for _, row := range table.Rows {
|
for _, row := range table.Rows {
|
||||||
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.content {
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
||||||
countNotEmpty++
|
countNotEmpty++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -969,16 +969,16 @@ func (table *Table) calcColNumber(col *TableColumn, colIndex int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case CalcOperatorMin:
|
case CalcOperatorMin:
|
||||||
min := math.MaxFloat64
|
minVal := math.MaxFloat64
|
||||||
for _, row := range table.Rows {
|
for _, row := range table.Rows {
|
||||||
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
||||||
if row.Cells[colIndex].Value.Number.Content < min {
|
if row.Cells[colIndex].Value.Number.Content < minVal {
|
||||||
min = row.Cells[colIndex].Value.Number.Content
|
minVal = row.Cells[colIndex].Value.Number.Content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if math.MaxFloat64 != min {
|
if math.MaxFloat64 != minVal {
|
||||||
col.Calc.Result = &Value{Number: NewFormattedValueNumber(min, col.NumberFormat)}
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(minVal, col.NumberFormat)}
|
||||||
}
|
}
|
||||||
case CalcOperatorMax:
|
case CalcOperatorMax:
|
||||||
maxVal := -math.MaxFloat64
|
maxVal := -math.MaxFloat64
|
||||||
|
|
|
@ -232,7 +232,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染模板列
|
// 渲染模板列
|
||||||
if av.KeyTypeTemplate == tableCell.ValueType && nil != tableCell.Value && nil != tableCell.Value.Template {
|
if av.KeyTypeTemplate == tableCell.ValueType {
|
||||||
render := func(blockID string) string {
|
render := func(blockID string) string {
|
||||||
funcMap := sprig.TxtFuncMap()
|
funcMap := sprig.TxtFuncMap()
|
||||||
goTpl := template.New("").Delims(".action{", "}")
|
goTpl := template.New("").Delims(".action{", "}")
|
||||||
|
@ -250,6 +250,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tableCell.Value = &av.Value{ID: tableCell.ID, KeyID: col.ID, BlockID: rowID, Type: av.KeyTypeTemplate, Template: &av.ValueTemplate{}}
|
||||||
tableCell.Value.Template.Render(tableCell.Value.BlockID, render)
|
tableCell.Value.Template.Render(tableCell.Value.BlockID, render)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue