Przeglądaj źródła

:bug: Database filtering does not work after change the field type https://github.com/siyuan-note/siyuan/issues/10519

Daniel 1 rok temu
rodzic
commit
3207a5a8a1
2 zmienionych plików z 18 dodań i 24 usunięć
  1. 2 1
      kernel/api/av.go
  2. 16 23
      kernel/model/attribute_view.go

+ 2 - 1
kernel/api/av.go

@@ -225,8 +225,9 @@ func getAttributeViewFilterSort(c *gin.Context) {
 	}
 
 	avID := arg["id"].(string)
+	blockID := arg["blockID"].(string)
 
-	filters, sorts := model.GetAttributeViewFilterSort(avID)
+	filters, sorts := model.GetAttributeViewFilterSort(avID, blockID)
 	ret.Data = map[string]interface{}{
 		"filters": filters,
 		"sorts":   sorts,

+ 16 - 23
kernel/model/attribute_view.go

@@ -101,23 +101,30 @@ func GetAttributeViewPrimaryKeyValues(avID string, page, pageSize int) (attribut
 	return
 }
 
-func GetAttributeViewFilterSort(id string) (filters []*av.ViewFilter, sorts []*av.ViewSort) {
+func GetAttributeViewFilterSort(avID, blockID string) (filters []*av.ViewFilter, sorts []*av.ViewSort) {
 	waitForSyncingStorages()
 
-	attrView, err := av.ParseAttributeView(id)
+	attrView, err := av.ParseAttributeView(avID)
 	if nil != err {
-		logging.LogErrorf("parse attribute view [%s] failed: %s", id, err)
+		logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
 		return
 	}
 
+	view, err := getAttrViewViewByBlockID(attrView, blockID)
+	if nil == view {
+		view, err = attrView.GetCurrentView(attrView.ViewID)
+		if nil != err {
+			logging.LogErrorf("get current view failed: %s", err)
+			return
+		}
+	}
+
 	filters = []*av.ViewFilter{}
 	sorts = []*av.ViewSort{}
-	for _, view := range attrView.Views {
-		switch view.LayoutType {
-		case av.LayoutTypeTable:
-			filters = view.Table.Filters
-			sorts = view.Table.Sorts
-		}
+	switch view.LayoutType {
+	case av.LayoutTypeTable:
+		filters = view.Table.Filters
+		sorts = view.Table.Sorts
 	}
 	return
 }
@@ -1911,20 +1918,6 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string,
 	return
 }
 
-func GetLastSortRow(rows []*av.TableRow) *av.TableRow {
-	for i := len(rows) - 1; i >= 0; i-- {
-		row := rows[i]
-		blockVal := row.GetBlockValue()
-		if nil != blockVal {
-			if !blockVal.IsEdited() {
-				continue
-			}
-			return row
-		}
-	}
-	return nil
-}
-
 func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr) {
 	err := removeAttributeViewBlock(operation.SrcIDs, operation.AvID, tx)
 	if nil != err {