Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Update av

Danield43016839053
diff --git a/kernel/av/av.go b/kernel/av/av.go
index 7dcc2bfa23..f990ed6ad6 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -22,6 +22,7 @@ import (
"database/sql"
"os"
"path/filepath"
+ "sort"
"strings"
"github.com/88250/gulu"
@@ -226,3 +227,76 @@ func RebuildAttributeViewTable(tx *sql.Tx, av *AttributeView) (err error) {
}
return
}
+
+func (av *AttributeView) SortRows() {
+ if 0 < len(av.Sorts) {
+ type ColIndexSort struct {
+ Index int
+ Order SortOrder
+ }
+
+ var colIndexSorts []*ColIndexSort
+ for _, s := range av.Sorts {
+ for i, c := range av.Columns {
+ if c.ID == s.Column {
+ colIndexSorts = append(colIndexSorts, &ColIndexSort{Index: i, Order: s.Order})
+ break
+ }
+ }
+ }
+
+ sort.Slice(av.Rows, func(i, j int) bool {
+ for _, colIndexSort := range colIndexSorts {
+ c := av.Columns[colIndexSort.Index]
+ if c.Type == ColumnTypeBlock {
+ continue
+ }
+
+ result := av.Rows[i].Cells[colIndexSort.Index].Value.Compare(av.Rows[j].Cells[colIndexSort.Index].Value)
+ if 0 == result {
+ continue
+ }
+
+ if colIndexSort.Order == SortOrderAsc {
+ return 0 > result
+ }
+ return 0 < result
+ }
+ return false
+ })
+ }
+}
+
+func (av *AttributeView) FilterRows() {
+ if 0 < len(av.Filters) {
+ var colIndexes []int
+ for _, f := range av.Filters {
+ for i, c := range av.Columns {
+ if c.ID == f.Column {
+ colIndexes = append(colIndexes, i)
+ break
+ }
+ }
+ }
+
+ var rows []*Row
+ for _, row := range av.Rows {
+ pass := true
+ for j, index := range colIndexes {
+ c := av.Columns[index]
+ if c.Type == ColumnTypeBlock {
+ continue
+ }
+
+ if !row.Cells[index].Value.CompareOperator(av.Filters[j].Value, av.Filters[j].Operator) {
+ pass = false
+ break
+ }
+ }
+ if pass {
+ rows = append(rows, row)
+ }
+ }
+ av.Rows = rows
+ }
+}
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 79a09a8afc..836c107e60 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"github.com/jinzhu/copier"
- "sort"
"strings"
"github.com/88250/gulu"
@@ -42,84 +41,11 @@ func RenderAttributeView(avID string) (ret *av.AttributeView, err error) {
return
}
- filterRows(ret)
- sortRows(ret)
+ ret.FilterRows()
+ ret.SortRows()
return
}
-func filterRows(ret *av.AttributeView) {
- if 0 < len(ret.Filters) {
- var colIndexes []int
- for _, f := range ret.Filters {
- for i, c := range ret.Columns {
- if c.ID == f.Column {
- colIndexes = append(colIndexes, i)
- break
- }
- }
- }
-
- var rows []*av.Row
- for _, row := range ret.Rows {
- pass := true
- for j, index := range colIndexes {
- c := ret.Columns[index]
- if c.Type == av.ColumnTypeBlock {
- continue
- }
-
- if !row.Cells[index].Value.CompareOperator(ret.Filters[j].Value, ret.Filters[j].Operator) {
- pass = false
- break
- }
- }
- if pass {
- rows = append(rows, row)
- }
- }
- ret.Rows = rows
- }
-}
-
-func sortRows(ret *av.AttributeView) {
- if 0 < len(ret.Sorts) {
- type ColIndexSort struct {
- Index int
- Order av.SortOrder
- }
-
- var colIndexSorts []*ColIndexSort
- for _, s := range ret.Sorts {
- for i, c := range ret.Columns {
- if c.ID == s.Column {
- colIndexSorts = append(colIndexSorts, &ColIndexSort{Index: i, Order: s.Order})
- break
- }
- }
- }
-
- sort.Slice(ret.Rows, func(i, j int) bool {
- for _, colIndexSort := range colIndexSorts {
- c := ret.Columns[colIndexSort.Index]
- if c.Type == av.ColumnTypeBlock {
- continue
- }
-
- result := ret.Rows[i].Cells[colIndexSort.Index].Value.Compare(ret.Rows[j].Cells[colIndexSort.Index].Value)
- if 0 == result {
- continue
- }
-
- if colIndexSort.Order == av.SortOrderAsc {
- return 0 > result
- }
- return 0 < result
- }
- return false
- })
- }
-}
-
func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
avID := operation.ParentID
view, err := av.ParseAttributeView(avID)