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

This commit is contained in:
Vanessa 2025-07-25 23:18:53 +08:00
commit ddb20a368d
2 changed files with 84 additions and 6 deletions

View file

@ -107,7 +107,7 @@ func removeAttributeViewGroup(avID, blockID string) (err error) {
return err return err
} }
view.Group, view.Groups, view.GroupUpdated = nil, nil, 0 removeAttributeViewGroup0(view)
err = av.SaveAttributeView(attrView) err = av.SaveAttributeView(attrView)
if err != nil { if err != nil {
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err) logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
@ -116,6 +116,10 @@ func removeAttributeViewGroup(avID, blockID string) (err error) {
return nil return nil
} }
func removeAttributeViewGroup0(view *av.View) {
view.Group, view.Groups, view.GroupUpdated = nil, nil, 0
}
func (tx *Transaction) doSyncAttrViewTableColWidth(operation *Operation) (ret *TxErr) { func (tx *Transaction) doSyncAttrViewTableColWidth(operation *Operation) (ret *TxErr) {
err := syncAttrViewTableColWidth(operation) err := syncAttrViewTableColWidth(operation)
if err != nil { if err != nil {
@ -202,6 +206,43 @@ func hideAttributeViewGroup(avID, blockID, groupID string, hidden int) (err erro
return nil return nil
} }
func (tx *Transaction) doFoldAttrViewGroup(operation *Operation) (ret *TxErr) {
if err := foldAttrViewGroup(operation.AvID, operation.BlockID, operation.ID, operation.Data.(bool)); nil != err {
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
}
return
}
func foldAttrViewGroup(avID, blockID, groupID string, folded bool) (err error) {
attrView, err := av.ParseAttributeView(avID)
if err != nil {
return err
}
view, err := getAttrViewViewByBlockID(attrView, blockID)
if err != nil {
return err
}
if nil == view.Group {
return
}
for _, group := range view.Groups {
if group.ID == groupID {
group.GroupFolded = folded
break
}
}
err = av.SaveAttributeView(attrView)
if err != nil {
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
return err
}
return nil
}
func (tx *Transaction) doSetAttrViewGroup(operation *Operation) (ret *TxErr) { func (tx *Transaction) doSetAttrViewGroup(operation *Operation) (ret *TxErr) {
data, err := gulu.JSON.MarshalJSON(operation.Data) data, err := gulu.JSON.MarshalJSON(operation.Data)
if nil != err { if nil != err {
@ -1634,17 +1675,18 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
// 过去 30 天、过去 7 天、昨天、今天、明天、未来 7 天、未来 30 天 // 过去 30 天、过去 7 天、昨天、今天、明天、未来 7 天、未来 30 天
// 未来 30 天之后的按月分组 // 未来 30 天之后的按月分组
now := time.Now() now := time.Now()
now = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
if contentTime.Before(now.AddDate(0, 0, -30)) { if contentTime.Before(now.AddDate(0, 0, -30)) {
groupName = contentTime.Format("2006-01") groupName = contentTime.Format("2006-01")
} else if contentTime.Before(now.AddDate(0, 0, -7)) { } else if contentTime.Before(now.AddDate(0, 0, -7)) {
groupName = groupNameLast30Days groupName = groupNameLast30Days
} else if contentTime.Before(now.AddDate(0, 0, -1)) { } else if contentTime.Before(now.AddDate(0, 0, -1)) {
groupName = groupNameLast7Days groupName = groupNameLast7Days
} else if contentTime.Equal(now.AddDate(0, 0, -1)) { } else if contentTime.Before(now) {
groupName = groupNameYesterday groupName = groupNameYesterday
} else if contentTime.Equal(now) { } else if contentTime.After(now) && contentTime.Before(now.AddDate(0, 0, 1)) {
groupName = groupNameToday groupName = groupNameToday
} else if contentTime.Equal(now.AddDate(0, 0, 1)) { } else if contentTime.After(now.AddDate(0, 0, 1)) || contentTime.Equal(now.AddDate(0, 0, 1)) {
groupName = groupNameTomorrow groupName = groupNameTomorrow
} else if contentTime.After(now.AddDate(0, 0, 30)) { } else if contentTime.After(now.AddDate(0, 0, 30)) {
groupName = contentTime.Format("2006-01") groupName = contentTime.Format("2006-01")
@ -1652,8 +1694,6 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
groupName = groupNameNext30Days groupName = groupNameNext30Days
} else if contentTime.After(now.AddDate(0, 0, 1)) { } else if contentTime.After(now.AddDate(0, 0, 1)) {
groupName = groupNameNext7Days groupName = groupNameNext7Days
} else {
groupName = notInRange
} }
} }
} }
@ -2130,6 +2170,7 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
} }
destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, srcVal.BlockID) destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, srcVal.BlockID)
destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs) destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs)
regenAttrViewViewGroups(srcAv, destVal.KeyID)
destKeyValues.Values = append(destKeyValues.Values, destVal) destKeyValues.Values = append(destKeyValues.Values, destVal)
} }
} }
@ -3911,6 +3952,10 @@ func RemoveAttributeViewKey(avID, keyID string, removeRelationDest bool) (err er
} }
} }
for _, view := range attrView.Views {
removeAttributeViewGroup0(view)
}
err = av.SaveAttributeView(attrView) err = av.SaveAttributeView(attrView)
return return
} }
@ -3959,6 +4004,7 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
content = util.UnescapeHTML(content) content = util.UnescapeHTML(content)
value.Block.Icon, value.Block.Content = icon, content value.Block.Icon, value.Block.Content = icon, content
value.UpdatedAt = now value.UpdatedAt = now
regenAttrViewViewGroups(attrView, value.KeyID)
err = av.SaveAttributeView(attrView) err = av.SaveAttributeView(attrView)
} }
return return
@ -4291,6 +4337,8 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
} }
val.SetUpdatedAt(now) val.SetUpdatedAt(now)
regenAttrViewViewGroups(attrView, keyID)
if nil != key && av.KeyTypeRelation == key.Type && nil != key.Relation && key.Relation.IsTwoWay { if nil != key && av.KeyTypeRelation == key.Type && nil != key.Relation && key.Relation.IsTwoWay {
// 双向关联需要同时更新目标字段的值 // 双向关联需要同时更新目标字段的值
@ -4327,6 +4375,7 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, rowID) destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, rowID)
destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs) destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs)
regenAttrViewViewGroups(destAv, key.Relation.BackKeyID)
break break
} }
} }
@ -4346,6 +4395,7 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
if value.BlockID == blockID { if value.BlockID == blockID {
value.Relation.BlockIDs = gulu.Str.RemoveElem(value.Relation.BlockIDs, rowID) value.Relation.BlockIDs = gulu.Str.RemoveElem(value.Relation.BlockIDs, rowID)
value.SetUpdatedAt(now) value.SetUpdatedAt(now)
regenAttrViewViewGroups(destAv, key.Relation.BackKeyID)
break break
} }
} }
@ -4361,6 +4411,31 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
return return
} }
func regenAttrViewViewGroups(attrView *av.AttributeView, keyID string) {
for _, view := range attrView.Views {
if nil != view.Group && view.Group.Field == keyID {
groupKey, _ := attrView.GetKey(view.Group.Field)
if nil == groupKey {
return
}
genAttrViewViewGroups(view, attrView)
for _, g := range view.Groups {
if view.Group.HideEmpty {
if 2 != g.GroupHidden && 1 > len(g.GroupItemIDs) {
g.GroupHidden = 1
}
} else {
if 2 != g.GroupHidden {
g.GroupHidden = 0
}
}
}
}
}
}
func unbindBlockAv(tx *Transaction, avID, blockID string) { func unbindBlockAv(tx *Transaction, avID, blockID string) {
node, tree, err := getNodeByBlockID(tx, blockID) node, tree, err := getNodeByBlockID(tx, blockID)
if err != nil { if err != nil {
@ -4755,6 +4830,7 @@ func replaceRelationAvValues(avID, previousID, nextID string) (changedSrcAvID []
srcAvChanged := false srcAvChanged := false
srcValue.Relation.BlockIDs, srcAvChanged = util.ReplaceStr(srcValue.Relation.BlockIDs, previousID, nextID) srcValue.Relation.BlockIDs, srcAvChanged = util.ReplaceStr(srcValue.Relation.BlockIDs, previousID, nextID)
if srcAvChanged { if srcAvChanged {
regenAttrViewViewGroups(srcAv, srcValue.KeyID)
changed = true changed = true
} }
} }

View file

@ -301,6 +301,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSetAttrViewGroup(op) ret = tx.doSetAttrViewGroup(op)
case "hideAttrViewGroup": case "hideAttrViewGroup":
ret = tx.doHideAttrViewGroup(op) ret = tx.doHideAttrViewGroup(op)
case "foldAttrViewGroup":
ret = tx.doFoldAttrViewGroup(op)
case "syncAttrViewTableColWidth": case "syncAttrViewTableColWidth":
ret = tx.doSyncAttrViewTableColWidth(op) ret = tx.doSyncAttrViewTableColWidth(op)
case "removeAttrViewGroup": case "removeAttrViewGroup":