Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-11-17 10:39:37 +08:00
commit cb3d412458
9 changed files with 109 additions and 8 deletions

File diff suppressed because one or more lines are too long

View file

@ -107,6 +107,7 @@ const (
KeyTypeTemplate KeyType = "template"
KeyTypeCreated KeyType = "created"
KeyTypeUpdated KeyType = "updated"
KeyTypeCheckbox KeyType = "checkbox"
)
// Key 描述了属性视图属性列的基础结构。
@ -157,6 +158,7 @@ type Value struct {
Template *ValueTemplate `json:"template,omitempty"`
Created *ValueCreated `json:"created,omitempty"`
Updated *ValueUpdated `json:"updated,omitempty"`
Checkbox *ValueCheckbox `json:"checkbox,omitempty"`
}
func (value *Value) String() string {
@ -234,6 +236,14 @@ func (value *Value) String() string {
return ""
}
return value.Updated.FormattedContent
case KeyTypeCheckbox:
if nil == value.Checkbox {
return ""
}
if value.Checkbox.Checked {
return "√"
}
return ""
default:
return ""
}
@ -529,6 +539,10 @@ func NewFormattedValueUpdated(content, content2 int64, format UpdatedFormat) (re
return
}
type ValueCheckbox struct {
Checked bool `json:"checked"`
}
// View 描述了视图的结构。
type View struct {
ID string `json:"id"` // 视图 ID
@ -609,7 +623,8 @@ func SaveAttributeView(av *AttributeView) (err error) {
// 做一些数据兼容和订正处理
now := util.CurrentTimeMillis()
for _, kv := range av.KeyValues {
if KeyTypeBlock == kv.Key.Type {
switch kv.Key.Type {
case KeyTypeBlock:
// 补全 block 的创建时间和更新时间
for _, v := range kv.Values {
if 0 == v.Block.Created {
@ -633,6 +648,12 @@ func SaveAttributeView(av *AttributeView) (err error) {
v.Block.Updated = now
}
}
case KeyTypeNumber:
for _, v := range kv.Values {
if 0 != v.Number.Content && !v.Number.IsNotEmpty {
v.Number.IsNotEmpty = true
}
}
}
}

View file

@ -43,4 +43,6 @@ const (
FilterOperatorEndsWith FilterOperator = "Ends with"
FilterOperatorIsBetween FilterOperator = "Is between"
FilterOperatorIsRelativeToToday FilterOperator = "Is relative to today"
FilterOperatorIsTrue FilterOperator = "Is true"
FilterOperatorIsFalse FilterOperator = "Is false"
)

View file

@ -72,6 +72,10 @@ const (
CalcOperatorRange CalcOperator = "Range"
CalcOperatorEarliest CalcOperator = "Earliest"
CalcOperatorLatest CalcOperator = "Latest"
CalcOperatorChecked CalcOperator = "Checked"
CalcOperatorUnchecked CalcOperator = "Unchecked"
CalcOperatorPercentChecked CalcOperator = "Percent checked"
CalcOperatorPercentUnchecked CalcOperator = "Percent unchecked"
)
func (value *Value) Compare(other *Value) int {
@ -171,6 +175,16 @@ func (value *Value) Compare(other *Value) int {
if nil != value.Template && nil != other.Template {
return strings.Compare(value.Template.Content, other.Template.Content)
}
case KeyTypeCheckbox:
if nil != value.Checkbox && nil != other.Checkbox {
if value.Checkbox.Checked && !other.Checkbox.Checked {
return 1
}
if !value.Checkbox.Checked && other.Checkbox.Checked {
return -1
}
return 0
}
}
return 0
}
@ -543,6 +557,15 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
return "" != strings.TrimSpace(value.Template.Content)
}
}
if nil != value.Checkbox {
switch operator {
case FilterOperatorIsTrue:
return value.Checkbox.Checked
case FilterOperatorIsFalse:
return !value.Checkbox.Checked
}
}
return true
}
@ -731,6 +754,8 @@ func (table *Table) CalcCols() {
table.calcColCreated(col, i)
case KeyTypeUpdated:
table.calcColUpdated(col, i)
case KeyTypeCheckbox:
table.calcColCheckbox(col, i)
}
}
}
@ -1840,3 +1865,46 @@ func (table *Table) calcColUpdated(col *TableColumn, colIndex int) {
}
}
}
func (table *Table) calcColCheckbox(col *TableColumn, colIndex int) {
switch col.Calc.Operator {
case CalcOperatorCountAll:
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
case CalcOperatorChecked:
countChecked := 0
for _, row := range table.Rows {
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Checkbox && row.Cells[colIndex].Value.Checkbox.Checked {
countChecked++
}
}
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countChecked), NumberFormatNone)}
case CalcOperatorUnchecked:
countUnchecked := 0
for _, row := range table.Rows {
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Checkbox && !row.Cells[colIndex].Value.Checkbox.Checked {
countUnchecked++
}
}
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUnchecked), NumberFormatNone)}
case CalcOperatorPercentChecked:
countChecked := 0
for _, row := range table.Rows {
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Checkbox && row.Cells[colIndex].Value.Checkbox.Checked {
countChecked++
}
}
if 0 < len(table.Rows) {
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countChecked)/float64(len(table.Rows)), NumberFormatPercent)}
}
case CalcOperatorPercentUnchecked:
countUnchecked := 0
for _, row := range table.Rows {
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Checkbox && !row.Cells[colIndex].Value.Checkbox.Checked {
countUnchecked++
}
}
if 0 < len(table.Rows) {
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUnchecked)/float64(len(table.Rows)), NumberFormatPercent)}
}
}
}

View file

@ -9,7 +9,7 @@ require (
github.com/88250/clipboard v0.1.5
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/gulu v1.2.3-0.20231023172823-f152fc5d93ef
github.com/88250/lute v1.7.6-0.20231113042205-e8dab3abc952
github.com/88250/lute v1.7.6-0.20231117014702-f00e74ce2d3d
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4

View file

@ -10,8 +10,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20231023172823-f152fc5d93ef h1:LVJO3aj18v63T2whGGt3gL5imkJk+7ujPfFv38X7Oi8=
github.com/88250/gulu v1.2.3-0.20231023172823-f152fc5d93ef/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
github.com/88250/lute v1.7.6-0.20231113042205-e8dab3abc952 h1:ECggYsXuyJvhxoxVbLVaJ985y5hrboF6X7W5vB4zn3I=
github.com/88250/lute v1.7.6-0.20231113042205-e8dab3abc952/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/lute v1.7.6-0.20231117014702-f00e74ce2d3d h1:G9x/Jj0X/sSx2236+Q0QVjNoR3sSO9SQDQwvWTO8e8E=
github.com/88250/lute v1.7.6-0.20231117014702-f00e74ce2d3d/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -1126,7 +1126,7 @@ func addAttributeViewColumn(operation *Operation) (err error) {
keyType := av.KeyType(operation.Typ)
switch keyType {
case av.KeyTypeText, av.KeyTypeNumber, av.KeyTypeDate, av.KeyTypeSelect, av.KeyTypeMSelect, av.KeyTypeURL, av.KeyTypeEmail, av.KeyTypePhone, av.KeyTypeMAsset, av.KeyTypeTemplate, av.KeyTypeCreated, av.KeyTypeUpdated:
case av.KeyTypeText, av.KeyTypeNumber, av.KeyTypeDate, av.KeyTypeSelect, av.KeyTypeMSelect, av.KeyTypeURL, av.KeyTypeEmail, av.KeyTypePhone, av.KeyTypeMAsset, av.KeyTypeTemplate, av.KeyTypeCreated, av.KeyTypeUpdated, av.KeyTypeCheckbox:
var icon string
if nil != operation.Data {
icon = operation.Data.(string)
@ -1218,7 +1218,7 @@ func updateAttributeViewColumn(operation *Operation) (err error) {
colType := av.KeyType(operation.Typ)
switch colType {
case av.KeyTypeBlock, av.KeyTypeText, av.KeyTypeNumber, av.KeyTypeDate, av.KeyTypeSelect, av.KeyTypeMSelect, av.KeyTypeURL, av.KeyTypeEmail, av.KeyTypePhone, av.KeyTypeMAsset, av.KeyTypeTemplate, av.KeyTypeCreated, av.KeyTypeUpdated:
case av.KeyTypeBlock, av.KeyTypeText, av.KeyTypeNumber, av.KeyTypeDate, av.KeyTypeSelect, av.KeyTypeMSelect, av.KeyTypeURL, av.KeyTypeEmail, av.KeyTypePhone, av.KeyTypeMAsset, av.KeyTypeTemplate, av.KeyTypeCreated, av.KeyTypeUpdated, av.KeyTypeCheckbox:
for _, keyValues := range attrView.KeyValues {
if keyValues.Key.ID == operation.ID {
keyValues.Key.Name = operation.Name

View file

@ -329,11 +329,17 @@ func getCardsBlocks(cards []riff.Card, page int) (blocks []*Block, total, pageCo
return
}
// sort by due date asc https://github.com/siyuan-note/siyuan/pull/9673
sort.Slice(cards, func(i, j int) bool {
due1 := cards[i].(*riff.FSRSCard).C.Due
due2 := cards[j].(*riff.FSRSCard).C.Due
return due1.Before(due2)
})
var blockIDs []string
for _, card := range cards {
blockIDs = append(blockIDs, card.BlockID())
}
sort.Strings(blockIDs)
sqlBlocks := sql.GetBlocks(blockIDs)
blocks = fromSQLBlocks(&sqlBlocks, "", 36)

View file

@ -779,6 +779,10 @@ func FillAttributeViewTableCellNilValue(tableCell *av.TableCell, rowID, colID st
if nil == tableCell.Value.Updated {
tableCell.Value.Updated = &av.ValueUpdated{}
}
case av.KeyTypeCheckbox:
if nil == tableCell.Value.Checkbox {
tableCell.Value.Checkbox = &av.ValueCheckbox{}
}
}
}