Browse Source

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

Vanessa 1 year ago
parent
commit
77350cc6fa
5 changed files with 31 additions and 15 deletions
  1. 24 9
      kernel/av/sort.go
  2. 2 2
      kernel/av/table.go
  3. 2 2
      kernel/model/attribute_view.go
  4. 2 2
      kernel/model/export.go
  5. 1 0
      kernel/model/upload.go

+ 24 - 9
kernel/av/sort.go

@@ -25,7 +25,7 @@ import (
 )
 )
 
 
 type Sortable interface {
 type Sortable interface {
-	SortRows()
+	SortRows(attrView *AttributeView)
 }
 }
 
 
 type ViewSort struct {
 type ViewSort struct {
@@ -40,7 +40,7 @@ const (
 	SortOrderDesc SortOrder = "DESC"
 	SortOrderDesc SortOrder = "DESC"
 )
 )
 
 
-func (value *Value) Compare(other *Value) int {
+func (value *Value) Compare(other *Value, attrView *AttributeView) int {
 	switch value.Type {
 	switch value.Type {
 	case KeyTypeBlock:
 	case KeyTypeBlock:
 		if nil != value.Block && nil != other.Block {
 		if nil != value.Block && nil != other.Block {
@@ -112,14 +112,29 @@ func (value *Value) Compare(other *Value) int {
 			return 0
 			return 0
 		}
 		}
 	case KeyTypeSelect, KeyTypeMSelect:
 	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)
 			return strings.Compare(v1, v2)
 		}
 		}

+ 2 - 2
kernel/av/table.go

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

+ 2 - 2
kernel/model/attribute_view.go

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

+ 2 - 2
kernel/model/export.go

@@ -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
 	// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
 	table.FilterRows(attrView)
 	table.FilterRows(attrView)
-	table.SortRows()
+	table.SortRows(attrView)
 
 
 	exportFolder := filepath.Join(util.TempDir, "export", "csv", name)
 	exportFolder := filepath.Join(util.TempDir, "export", "csv", name)
 	if err = os.MkdirAll(exportFolder, 0755); nil != err {
 	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
 		// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
 		table.FilterRows(attrView)
 		table.FilterRows(attrView)
-		table.SortRows()
+		table.SortRows(attrView)
 
 
 		var aligns []int
 		var aligns []int
 		for range table.Columns {
 		for range table.Columns {

+ 1 - 0
kernel/model/upload.go

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