♻️ Refactor av

This commit is contained in:
Daniel 2025-06-08 12:08:31 +08:00
parent d80bed7b85
commit 9fd0565a61
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
6 changed files with 31 additions and 19 deletions

View file

@ -16,13 +16,17 @@
package av
// Calculable 接口定义了可计算的视图类型。
type Calculable interface {
CalcCols()
// Calc 根据视图中设置的计算规则进行计算。
Calc()
}
// ColumnCalc 描述了列(字段)计算操作和结果的结构。
type ColumnCalc struct {
Operator CalcOperator `json:"operator"`
Result *Value `json:"result"`
Operator CalcOperator `json:"operator"` // 计算操作符
Result *Value `json:"result"` // 计算结果
}
type CalcOperator string

View file

@ -24,16 +24,20 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
// Filterable 接口定义了可过滤的视图类型。
type Filterable interface {
FilterRows(attrView *AttributeView)
// Filter 根据视图中设置的过滤器进行过滤。
Filter(attrView *AttributeView)
}
// ViewFilter 描述了视图过滤器的结构。
type ViewFilter struct {
Column string `json:"column"`
Operator FilterOperator `json:"operator"`
Value *Value `json:"value"`
RelativeDate *RelativeDate `json:"relativeDate"`
RelativeDate2 *RelativeDate `json:"relativeDate2"`
Column string `json:"column"` // 列字段ID
Operator FilterOperator `json:"operator"` // 过滤操作符
Value *Value `json:"value"` // 过滤值
RelativeDate *RelativeDate `json:"relativeDate"` // 相对时间
RelativeDate2 *RelativeDate `json:"relativeDate2"` // 第二个相对时间,用于某些操作符,比如 FilterOperatorIsBetween
}
type RelativeDateUnit int

View file

@ -126,7 +126,7 @@ func (table *Table) GetColumn(id string) *TableColumn {
return nil
}
func (table *Table) GetType() LayoutType {
func (*Table) GetType() LayoutType {
return LayoutTypeTable
}
@ -134,7 +134,7 @@ func (table *Table) GetID() string {
return table.ID
}
func (table *Table) SortRows(attrView *AttributeView) {
func (table *Table) Sort(attrView *AttributeView) {
if 1 > len(table.Sorts) {
return
}
@ -247,7 +247,7 @@ func (table *Table) SortRows(attrView *AttributeView) {
}
}
func (table *Table) FilterRows(attrView *AttributeView) {
func (table *Table) Filter(attrView *AttributeView) {
if 1 > len(table.Filters) {
return
}

View file

@ -23,7 +23,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func (table *Table) CalcCols() {
func (table *Table) Calc() {
for i, col := range table.Columns {
if nil == col.Calc {
continue

View file

@ -24,12 +24,16 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
// Sortable 接口定义了可排序的视图类型。
type Sortable interface {
SortRows(attrView *AttributeView)
// Sort 根据视图中设置的排序规则进行排序。
Sort(attrView *AttributeView)
}
// ViewSort 描述了视图排序规则的结构。
type ViewSort struct {
Column string `json:"column"` // 列 ID
Column string `json:"column"` // 列(字段)ID
Order SortOrder `json:"order"` // 排序顺序
}

View file

@ -83,8 +83,8 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
table := sql.RenderAttributeViewTable(attrView, view, "")
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
table.FilterRows(attrView)
table.SortRows(attrView)
table.Filter(attrView)
table.Sort(attrView)
exportFolder := filepath.Join(util.TempDir, "export", "csv", name)
if err = os.MkdirAll(exportFolder, 0755); err != nil {
@ -2495,8 +2495,8 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,
table := sql.RenderAttributeViewTable(attrView, view, "")
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
table.FilterRows(attrView)
table.SortRows(attrView)
table.Filter(attrView)
table.Sort(attrView)
var aligns []int
for range table.Columns {