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

This commit is contained in:
Vanessa 2024-03-21 10:14:29 +08:00
commit 77350cc6fa
5 changed files with 31 additions and 15 deletions

View file

@ -25,7 +25,7 @@ import (
)
type Sortable interface {
SortRows()
SortRows(attrView *AttributeView)
}
type ViewSort struct {
@ -40,7 +40,7 @@ const (
SortOrderDesc SortOrder = "DESC"
)
func (value *Value) Compare(other *Value) int {
func (value *Value) Compare(other *Value, attrView *AttributeView) int {
switch value.Type {
case KeyTypeBlock:
if nil != value.Block && nil != other.Block {
@ -112,14 +112,29 @@ func (value *Value) Compare(other *Value) int {
return 0
}
case KeyTypeSelect, KeyTypeMSelect:
if nil != value.MSelect && nil != other.MSelect {
var v1 string
for _, v := range value.MSelect {
v1 += v.Content
if 0 < len(value.MSelect) && 0 < len(other.MSelect) {
v1 := value.MSelect[0].Content
v2 := other.MSelect[0].Content
if v1 == v2 {
return 0
}
var v2 string
for _, v := range other.MSelect {
v2 += v.Content
key, _ := attrView.GetKey(value.KeyID)
if nil != key {
optionSort := map[string]int{}
for i, op := range key.Options {
optionSort[op.Name] = i
}
v1Sort := optionSort[v1]
v2Sort := optionSort[v2]
if v1Sort > v2Sort {
return 1
}
if v1Sort < v2Sort {
return -1
}
return 0
}
return strings.Compare(v1, v2)
}

View file

@ -153,7 +153,7 @@ func (table *Table) GetID() string {
return table.ID
}
func (table *Table) SortRows() {
func (table *Table) SortRows(attrView *AttributeView) {
if 1 > len(table.Sorts) {
return
}
@ -220,7 +220,7 @@ func (table *Table) SortRows() {
return colIndexSort.Order != SortOrderAsc
}
result := val1.Compare(val2)
result := val1.Compare(val2, attrView)
if 0 == result {
sorted = false
continue

View file

@ -724,7 +724,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
}
viewable.FilterRows(attrView)
viewable.SortRows()
viewable.SortRows(attrView)
viewable.CalcCols()
// 分页
@ -2010,7 +2010,7 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string,
if nil != view && 0 < len(view.Table.Filters) && !ignoreFillFilter {
viewable, _ := renderAttributeViewTable(attrView, view, "")
viewable.FilterRows(attrView)
viewable.SortRows()
viewable.SortRows(attrView)
var nearRow *av.TableRow
if 0 < len(viewable.Rows) {

View file

@ -87,7 +87,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
// 遵循视图过滤和排序规则 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()
table.SortRows(attrView)
exportFolder := filepath.Join(util.TempDir, "export", "csv", name)
if err = os.MkdirAll(exportFolder, 0755); nil != err {
@ -2284,7 +2284,7 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
// 遵循视图过滤和排序规则 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()
table.SortRows(attrView)
var aligns []int
for range table.Columns {

View file

@ -188,6 +188,7 @@ func Upload(c *gin.Context) {
succMap[baseName] = existAsset.Path
} else {
if skipIfDuplicated {
// https://github.com/siyuan-note/siyuan/issues/10666
matches, globErr := filepath.Glob(assetsDirPath + string(os.PathSeparator) + strings.TrimSuffix(fName, ext) + "*")
if nil != globErr {
logging.LogErrorf("glob failed: %s", globErr)