Selaa lähdekoodia

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

Vanessa 1 vuosi sitten
vanhempi
commit
2d636992d5
4 muutettua tiedostoa jossa 96 lisäystä ja 89 poistoa
  1. 17 1
      kernel/av/av.go
  2. 27 22
      kernel/av/table.go
  3. 11 0
      kernel/av/value.go
  4. 41 66
      kernel/model/attribute_view.go

+ 17 - 1
kernel/av/av.go

@@ -269,7 +269,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
 					}
 				}
 				if 0 == v.Block.Updated {
-					v.Block.Updated = now
+					v.Block.Updated = v.Block.Created
 				}
 			}
 		case KeyTypeNumber:
@@ -302,6 +302,22 @@ func SaveAttributeView(av *AttributeView) (err error) {
 					}
 				}
 			}
+
+			// 补全值的创建时间和更新时间
+			if "" == v.ID {
+				v.ID = ast.NewNodeID()
+			}
+			createdStr := v.ID[:len("20060102150405")]
+			created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
+			if nil == parseErr {
+				v.CreatedAt = created.UnixMilli()
+			} else {
+				v.CreatedAt = now
+			}
+
+			if 0 == v.UpdatedAt {
+				v.UpdatedAt = v.CreatedAt
+			}
 		}
 	}
 

+ 27 - 22
kernel/av/table.go

@@ -84,12 +84,20 @@ const (
 
 func (value *Value) Compare(other *Value) int {
 	if nil == value {
-		return -1
+		return 1
 	}
 	if nil == other {
+		return -1
+	}
+
+	if !value.IsEdited() {
 		return 1
 	}
 
+	if !other.IsEdited() {
+		return -1
+	}
+
 	switch value.Type {
 	case KeyTypeBlock:
 		if nil != value.Block && nil != other.Block {
@@ -105,20 +113,19 @@ func (value *Value) Compare(other *Value) int {
 				if !other.Number.IsNotEmpty {
 					return 1
 				}
-				return 0
+
+				if value.Number.Content > other.Number.Content {
+					return 1
+				} else if value.Number.Content < other.Number.Content {
+					return -1
+				} else {
+					return 0
+				}
 			} else {
 				if other.Number.IsNotEmpty {
 					return -1
 				}
-				return 0
-			}
-
-			if value.Number.Content > other.Number.Content {
-				return 1
-			} else if value.Number.Content < other.Number.Content {
-				return -1
-			} else {
-				return 0
+				return int(value.CreatedAt - other.CreatedAt)
 			}
 		}
 	case KeyTypeDate:
@@ -127,20 +134,18 @@ func (value *Value) Compare(other *Value) int {
 				if !other.Date.IsNotEmpty {
 					return 1
 				}
-				return 0
+				if value.Date.Content > other.Date.Content {
+					return 1
+				} else if value.Date.Content < other.Date.Content {
+					return -1
+				} else {
+					return 0
+				}
 			} else {
 				if other.Date.IsNotEmpty {
 					return -1
 				}
-				return 0
-			}
-
-			if value.Date.Content > other.Date.Content {
-				return 1
-			} else if value.Date.Content < other.Date.Content {
-				return -1
-			} else {
-				return 0
+				return int(value.CreatedAt - other.CreatedAt)
 			}
 		}
 	case KeyTypeCreated:
@@ -263,7 +268,7 @@ func (value *Value) Compare(other *Value) int {
 			return strings.Compare(vContent, oContent)
 		}
 	}
-	return 0
+	return int(value.CreatedAt - other.CreatedAt)
 }
 
 func (value *Value) CompareOperator(filter *ViewFilter, attrView *AttributeView, rowID string) bool {

+ 11 - 0
kernel/av/value.go

@@ -37,6 +37,9 @@ type Value struct {
 	Type       KeyType `json:"type,omitempty"`
 	IsDetached bool    `json:"isDetached,omitempty"`
 
+	CreatedAt int64 `json:"createdAt,omitempty"`
+	UpdatedAt int64 `json:"updatedAt,omitempty"`
+
 	Block    *ValueBlock    `json:"block,omitempty"`
 	Text     *ValueText     `json:"text,omitempty"`
 	Number   *ValueNumber   `json:"number,omitempty"`
@@ -180,6 +183,14 @@ func (value *Value) Clone() (ret *Value) {
 	return
 }
 
+func (value *Value) IsEdited() bool {
+	if value.CreatedAt == value.UpdatedAt {
+		// 说明是刚刚创建的块
+		return false
+	}
+	return true
+}
+
 type ValueBlock struct {
 	ID      string `json:"id"`
 	Content string `json:"content"`

+ 41 - 66
kernel/model/attribute_view.go

@@ -605,10 +605,29 @@ func renderAttributeView(attrView *av.AttributeView, viewID string, page, pageSi
 					}
 				}
 				if 0 == v.Block.Updated {
-					v.Block.Updated = currentTimeMillis
+					v.Block.Updated = v.Block.Created
 				}
 			}
 		}
+
+		// 补全值的创建时间和更新时间
+		for _, v := range kv.Values {
+			if "" == v.ID {
+				v.ID = ast.NewNodeID()
+			}
+
+			createdStr := v.ID[:len("20060102150405")]
+			created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
+			if nil == parseErr {
+				v.CreatedAt = created.UnixMilli()
+			} else {
+				v.CreatedAt = currentTimeMillis
+			}
+
+			if 0 == v.UpdatedAt {
+				v.UpdatedAt = v.CreatedAt
+			}
+		}
 	}
 
 	switch view.LayoutType {
@@ -1698,78 +1717,35 @@ func addAttributeViewBlock(avID, previousBlockID, blockID string, isDetached boo
 		content = getNodeRefText(node)
 	}
 	now := time.Now().UnixMilli()
-	blockValue := &av.Value{ID: ast.NewNodeID(), KeyID: blockValues.Key.ID, BlockID: blockID, Type: av.KeyTypeBlock, IsDetached: isDetached, Block: &av.ValueBlock{ID: blockID, Content: content, Created: now, Updated: now}}
+	blockValue := &av.Value{
+		ID:         ast.NewNodeID(),
+		KeyID:      blockValues.Key.ID,
+		BlockID:    blockID,
+		Type:       av.KeyTypeBlock,
+		IsDetached: isDetached,
+		CreatedAt:  now,
+		UpdatedAt:  now,
+		Block:      &av.ValueBlock{ID: blockID, Content: content, Created: now, Updated: now}}
 	blockValues.Values = append(blockValues.Values, blockValue)
 
-	// 如果存在排序和过滤条件,则将排序和过滤条件应用到新添加的块上
+	// 如果存在过滤条件,则将过滤条件应用到新添加的块上
 	view, _ := attrView.GetCurrentView()
 	if nil != view && (0 < len(view.Table.Filters) || 0 < len(view.Table.Sorts)) {
 		viewable, _ := renderAttributeViewTable(attrView, view)
 		viewable.FilterRows(attrView)
-		viewable.SortRows()
 
-		affectKeyIDs := map[string]bool{}
-		for _, f := range view.Table.Filters {
-			affectKeyIDs[f.Column] = true
-		}
-		for _, s := range view.Table.Sorts {
-			affectKeyIDs[s.Column] = true
-		}
-
-		addedValues := map[string]bool{}
-		if 0 < len(viewable.Rows) {
-			row := GetLastSortRow(viewable.Rows)
-			if nil != row {
-				for affectKeyID := range affectKeyIDs {
-					for _, cell := range row.Cells {
-						if nil != cell.Value && cell.Value.KeyID == affectKeyID {
-							if av.KeyTypeBlock == cell.ValueType {
-								blockValue.Block.Content = cell.Value.Block.Content
-								continue
-							}
-
-							newValue := cell.Value.Clone()
-							newValue.ID = ast.NewNodeID()
-							newValue.BlockID = blockID
-							newValue.IsDetached = isDetached
-							values, _ := attrView.GetKeyValues(affectKeyID)
-							values.Values = append(values.Values, newValue)
-							addedValues[affectKeyID] = true
-							break
-						}
-					}
-				}
-			}
-		}
-
-		notAddedValues := map[string]bool{}
-		for affectKeyID := range affectKeyIDs {
-			if !addedValues[affectKeyID] {
-				notAddedValues[affectKeyID] = true
-				break
-			}
-		}
-
-		if 0 < len(notAddedValues) {
-			for _, filter := range view.Table.Filters {
-				if !notAddedValues[filter.Column] {
-					continue
-				}
-
-				for _, keyValues := range attrView.KeyValues {
-					if keyValues.Key.ID == filter.Column {
-						newValue := filter.GetAffectValue(keyValues.Key)
-						newValue.ID = ast.NewNodeID()
-						newValue.KeyID = keyValues.Key.ID
-						newValue.BlockID = blockID
-						newValue.IsDetached = isDetached
-						keyValues.Values = append(keyValues.Values, newValue)
-						break
-					}
+		for _, filter := range view.Table.Filters {
+			for _, keyValues := range attrView.KeyValues {
+				if keyValues.Key.ID == filter.Column {
+					newValue := filter.GetAffectValue(keyValues.Key)
+					newValue.ID = ast.NewNodeID()
+					newValue.KeyID = keyValues.Key.ID
+					newValue.BlockID = blockID
+					newValue.IsDetached = isDetached
+					keyValues.Values = append(keyValues.Values, newValue)
+					break
 				}
 			}
-
-			// 仅使用上面的过滤条件计算受影响的值并插入兜底,受影响的排序条件不进行计算值插入
 		}
 	}
 
@@ -1826,8 +1802,7 @@ func GetLastSortRow(rows []*av.TableRow) *av.TableRow {
 		row := rows[i]
 		blockVal := row.GetBlockValue()
 		if nil != blockVal {
-			if nil != blockVal.Block && blockVal.Block.Created == blockVal.Block.Updated {
-				// 说明是刚刚创建的块,跳过
+			if !blockVal.IsEdited() {
 				continue
 			}
 			return row