mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
♻️ Refactor av
This commit is contained in:
parent
d80bed7b85
commit
9fd0565a61
6 changed files with 31 additions and 19 deletions
|
|
@ -16,13 +16,17 @@
|
||||||
|
|
||||||
package av
|
package av
|
||||||
|
|
||||||
|
// Calculable 接口定义了可计算的视图类型。
|
||||||
type Calculable interface {
|
type Calculable interface {
|
||||||
CalcCols()
|
|
||||||
|
// Calc 根据视图中设置的计算规则进行计算。
|
||||||
|
Calc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ColumnCalc 描述了列(字段)计算操作和结果的结构。
|
||||||
type ColumnCalc struct {
|
type ColumnCalc struct {
|
||||||
Operator CalcOperator `json:"operator"`
|
Operator CalcOperator `json:"operator"` // 计算操作符
|
||||||
Result *Value `json:"result"`
|
Result *Value `json:"result"` // 计算结果
|
||||||
}
|
}
|
||||||
|
|
||||||
type CalcOperator string
|
type CalcOperator string
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,20 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Filterable 接口定义了可过滤的视图类型。
|
||||||
type Filterable interface {
|
type Filterable interface {
|
||||||
FilterRows(attrView *AttributeView)
|
|
||||||
|
// Filter 根据视图中设置的过滤器进行过滤。
|
||||||
|
Filter(attrView *AttributeView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ViewFilter 描述了视图过滤器的结构。
|
||||||
type ViewFilter struct {
|
type ViewFilter struct {
|
||||||
Column string `json:"column"`
|
Column string `json:"column"` // 列(字段)ID
|
||||||
Operator FilterOperator `json:"operator"`
|
Operator FilterOperator `json:"operator"` // 过滤操作符
|
||||||
Value *Value `json:"value"`
|
Value *Value `json:"value"` // 过滤值
|
||||||
RelativeDate *RelativeDate `json:"relativeDate"`
|
RelativeDate *RelativeDate `json:"relativeDate"` // 相对时间
|
||||||
RelativeDate2 *RelativeDate `json:"relativeDate2"`
|
RelativeDate2 *RelativeDate `json:"relativeDate2"` // 第二个相对时间,用于某些操作符,比如 FilterOperatorIsBetween
|
||||||
}
|
}
|
||||||
|
|
||||||
type RelativeDateUnit int
|
type RelativeDateUnit int
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ func (table *Table) GetColumn(id string) *TableColumn {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *Table) GetType() LayoutType {
|
func (*Table) GetType() LayoutType {
|
||||||
return LayoutTypeTable
|
return LayoutTypeTable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,7 +134,7 @@ func (table *Table) GetID() string {
|
||||||
return table.ID
|
return table.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *Table) SortRows(attrView *AttributeView) {
|
func (table *Table) Sort(attrView *AttributeView) {
|
||||||
if 1 > len(table.Sorts) {
|
if 1 > len(table.Sorts) {
|
||||||
return
|
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) {
|
if 1 > len(table.Filters) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (table *Table) CalcCols() {
|
func (table *Table) Calc() {
|
||||||
for i, col := range table.Columns {
|
for i, col := range table.Columns {
|
||||||
if nil == col.Calc {
|
if nil == col.Calc {
|
||||||
continue
|
continue
|
||||||
|
|
@ -24,12 +24,16 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Sortable 接口定义了可排序的视图类型。
|
||||||
type Sortable interface {
|
type Sortable interface {
|
||||||
SortRows(attrView *AttributeView)
|
|
||||||
|
// Sort 根据视图中设置的排序规则进行排序。
|
||||||
|
Sort(attrView *AttributeView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ViewSort 描述了视图排序规则的结构。
|
||||||
type ViewSort struct {
|
type ViewSort struct {
|
||||||
Column string `json:"column"` // 列 ID
|
Column string `json:"column"` // 列(字段)ID
|
||||||
Order SortOrder `json:"order"` // 排序顺序
|
Order SortOrder `json:"order"` // 排序顺序
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,8 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
||||||
table := sql.RenderAttributeViewTable(attrView, view, "")
|
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
|
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
|
||||||
table.FilterRows(attrView)
|
table.Filter(attrView)
|
||||||
table.SortRows(attrView)
|
table.Sort(attrView)
|
||||||
|
|
||||||
exportFolder := filepath.Join(util.TempDir, "export", "csv", name)
|
exportFolder := filepath.Join(util.TempDir, "export", "csv", name)
|
||||||
if err = os.MkdirAll(exportFolder, 0755); err != nil {
|
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, "")
|
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
|
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
|
||||||
table.FilterRows(attrView)
|
table.Filter(attrView)
|
||||||
table.SortRows(attrView)
|
table.Sort(attrView)
|
||||||
|
|
||||||
var aligns []int
|
var aligns []int
|
||||||
for range table.Columns {
|
for range table.Columns {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue