mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-20 14:04:06 +01:00
🎨 Add template type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8766
This commit is contained in:
parent
e8359edebc
commit
c0424caf67
3 changed files with 95 additions and 21 deletions
|
|
@ -509,6 +509,71 @@ func (table *Table) CalcCols() {
|
|||
table.calcColPhone(col, i)
|
||||
case KeyTypeMAsset:
|
||||
table.calcColMAsset(col, i)
|
||||
case KeyTypeTemplate:
|
||||
table.calcColTemplate(col, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
|
||||
switch col.Calc.Operator {
|
||||
case CalcOperatorCountAll:
|
||||
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
||||
case CalcOperatorCountValues:
|
||||
countValues := 0
|
||||
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.RenderedContent {
|
||||
countValues++
|
||||
}
|
||||
}
|
||||
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
||||
case CalcOperatorCountUniqueValues:
|
||||
countUniqueValues := 0
|
||||
uniqueValues := map[string]bool{}
|
||||
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.RenderedContent {
|
||||
if !uniqueValues[row.Cells[colIndex].Value.Template.RenderedContent] {
|
||||
uniqueValues[row.Cells[colIndex].Value.Template.RenderedContent] = true
|
||||
countUniqueValues++
|
||||
}
|
||||
}
|
||||
}
|
||||
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
||||
case CalcOperatorCountEmpty:
|
||||
countEmpty := 0
|
||||
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.RenderedContent {
|
||||
countEmpty++
|
||||
}
|
||||
}
|
||||
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
||||
case CalcOperatorCountNotEmpty:
|
||||
countNotEmpty := 0
|
||||
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.RenderedContent {
|
||||
countNotEmpty++
|
||||
}
|
||||
}
|
||||
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
||||
case CalcOperatorPercentEmpty:
|
||||
countEmpty := 0
|
||||
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.RenderedContent {
|
||||
countEmpty++
|
||||
}
|
||||
}
|
||||
if 0 < len(table.Rows) {
|
||||
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
||||
}
|
||||
case CalcOperatorPercentNotEmpty:
|
||||
countNotEmpty := 0
|
||||
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.RenderedContent {
|
||||
countNotEmpty++
|
||||
}
|
||||
}
|
||||
if 0 < len(table.Rows) {
|
||||
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue