mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
🎨 Adding rows after setting the sort field in the database table view no longer fills in the default value https://github.com/siyuan-note/siyuan/issues/10486
This commit is contained in:
parent
6f4302164d
commit
06a5a59cae
3 changed files with 137 additions and 23 deletions
|
|
@ -321,8 +321,6 @@ func SaveAttributeView(av *AttributeView) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据订正
|
|
||||||
|
|
||||||
// 值去重
|
// 值去重
|
||||||
blockValues := av.GetBlockKeyValues()
|
blockValues := av.GetBlockKeyValues()
|
||||||
blockIDs := map[string]bool{}
|
blockIDs := map[string]bool{}
|
||||||
|
|
|
||||||
|
|
@ -83,22 +83,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (value *Value) Compare(other *Value) int {
|
func (value *Value) Compare(other *Value) int {
|
||||||
if nil == value {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if nil == other {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
if !value.IsEdited() {
|
|
||||||
if other.IsEdited() {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return int(value.CreatedAt - other.CreatedAt)
|
|
||||||
} else if !other.IsEdited() {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
switch value.Type {
|
switch value.Type {
|
||||||
case KeyTypeBlock:
|
case KeyTypeBlock:
|
||||||
if nil != value.Block && nil != other.Block {
|
if nil != value.Block && nil != other.Block {
|
||||||
|
|
@ -273,7 +257,7 @@ func (value *Value) Compare(other *Value) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (value *Value) CompareOperator(filter *ViewFilter, attrView *AttributeView, rowID string) bool {
|
func (value *Value) CompareOperator(filter *ViewFilter, attrView *AttributeView, rowID string) bool {
|
||||||
if nil != value.Rollup && nil != filter.Value.Rollup {
|
if nil != value.Rollup && KeyTypeRollup == filter.Value.Type {
|
||||||
rollupKey, _ := attrView.GetKey(value.KeyID)
|
rollupKey, _ := attrView.GetKey(value.KeyID)
|
||||||
if nil == rollupKey {
|
if nil == rollupKey {
|
||||||
return false
|
return false
|
||||||
|
|
@ -904,9 +888,53 @@ func (table *Table) SortRows() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(table.Rows, func(i, j int) bool {
|
includeUneditedRows := map[string]bool{}
|
||||||
|
for i, row := range table.Rows {
|
||||||
for _, colIndexSort := range colIndexSorts {
|
for _, colIndexSort := range colIndexSorts {
|
||||||
result := table.Rows[i].Cells[colIndexSort.Index].Value.Compare(table.Rows[j].Cells[colIndexSort.Index].Value)
|
val := table.Rows[i].Cells[colIndexSort.Index].Value
|
||||||
|
if !val.IsEdited() {
|
||||||
|
// 如果该行的某个列的值是未编辑的,则该行不参与排序
|
||||||
|
includeUneditedRows[row.ID] = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将包含未编辑的行和全部已编辑的行分开排序
|
||||||
|
var uneditedRows, editedRows []*TableRow
|
||||||
|
for _, row := range table.Rows {
|
||||||
|
if _, ok := includeUneditedRows[row.ID]; ok {
|
||||||
|
uneditedRows = append(uneditedRows, row)
|
||||||
|
} else {
|
||||||
|
editedRows = append(editedRows, row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(uneditedRows, func(i, j int) bool {
|
||||||
|
val1 := uneditedRows[i].GetBlockValue()
|
||||||
|
if nil == val1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
val2 := uneditedRows[j].GetBlockValue()
|
||||||
|
if nil == val2 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return val1.CreatedAt < val2.CreatedAt
|
||||||
|
})
|
||||||
|
|
||||||
|
sort.Slice(editedRows, func(i, j int) bool {
|
||||||
|
for _, colIndexSort := range colIndexSorts {
|
||||||
|
val1 := editedRows[i].Cells[colIndexSort.Index].Value
|
||||||
|
if nil == val1 {
|
||||||
|
return colIndexSort.Order == SortOrderAsc
|
||||||
|
}
|
||||||
|
|
||||||
|
val2 := editedRows[j].Cells[colIndexSort.Index].Value
|
||||||
|
if nil == val2 {
|
||||||
|
return colIndexSort.Order != SortOrderAsc
|
||||||
|
}
|
||||||
|
|
||||||
|
result := val1.Compare(val2)
|
||||||
if 0 == result {
|
if 0 == result {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -918,6 +946,9 @@ func (table *Table) SortRows() {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 将包含未编辑的行放在最后
|
||||||
|
table.Rows = append(editedRows, uneditedRows...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *Table) FilterRows(attrView *AttributeView) {
|
func (table *Table) FilterRows(attrView *AttributeView) {
|
||||||
|
|
|
||||||
|
|
@ -189,10 +189,95 @@ func (value *Value) IsEdited() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if value.CreatedAt == value.UpdatedAt {
|
if value.IsGenerated() {
|
||||||
|
// 所有生成的数据都认为是编辑过的
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if value.IsEmpty() {
|
||||||
|
// 空数据认为是未编辑过的
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return value.CreatedAt != value.UpdatedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
func (value *Value) IsGenerated() bool {
|
||||||
|
return KeyTypeTemplate == value.Type || KeyTypeRollup == value.Type || KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (value *Value) IsEmpty() bool {
|
||||||
|
switch value.Type {
|
||||||
|
case KeyTypeBlock:
|
||||||
|
if nil == value.Block {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return "" == value.Block.Content
|
||||||
|
case KeyTypeText:
|
||||||
|
if nil == value.Text {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return "" == value.Text.Content
|
||||||
|
case KeyTypeNumber:
|
||||||
|
if nil == value.Number {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return !value.Number.IsNotEmpty
|
||||||
|
case KeyTypeDate:
|
||||||
|
if nil == value.Date {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return !value.Date.IsNotEmpty
|
||||||
|
case KeyTypeSelect:
|
||||||
|
if 1 > len(value.MSelect) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return "" == value.MSelect[0].Content
|
||||||
|
case KeyTypeMSelect:
|
||||||
|
return 1 > len(value.MSelect)
|
||||||
|
case KeyTypeURL:
|
||||||
|
if nil == value.URL {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return "" == value.URL.Content
|
||||||
|
case KeyTypeEmail:
|
||||||
|
if nil == value.Email {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return "" == value.Email.Content
|
||||||
|
case KeyTypePhone:
|
||||||
|
if nil == value.Phone {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return "" == value.Phone.Content
|
||||||
|
case KeyTypeMAsset:
|
||||||
|
return 1 > len(value.MAsset)
|
||||||
|
case KeyTypeTemplate:
|
||||||
|
if nil == value.Template {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return "" == value.Template.Content
|
||||||
|
case KeyTypeCreated:
|
||||||
|
if nil == value.Created {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return !value.Created.IsNotEmpty
|
||||||
|
case KeyTypeUpdated:
|
||||||
|
if nil == value.Updated {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return !value.Updated.IsNotEmpty
|
||||||
|
case KeyTypeCheckbox:
|
||||||
|
if nil == value.Checkbox {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return !value.Checkbox.Checked
|
||||||
|
case KeyTypeRelation:
|
||||||
|
return 1 > len(value.Relation.Contents)
|
||||||
|
case KeyTypeRollup:
|
||||||
|
return 1 > len(value.Rollup.Contents)
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
type ValueBlock struct {
|
type ValueBlock struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue