🎨 Improve database field default filling https://github.com/siyuan-note/siyuan/issues/15549

This commit is contained in:
Daniel 2025-08-12 21:32:27 +08:00
parent ff077158dc
commit 8ba02f517c
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -2961,12 +2961,10 @@ func fillDefaultValue(attrView *av.AttributeView, view, groupView *av.View, prev
continue continue
} }
if (av.KeyTypeSelect == newValue.Type || av.KeyTypeMSelect == newValue.Type) && 1 > len(newValue.MSelect) { if (av.KeyTypeSelect == newValue.Type || av.KeyTypeMSelect == newValue.Type) && 1 > len(newValue.MSelect) && groupValueDefault != groupView.GetGroupValue() {
// 单选或多选类型的值可能需要从分组条件中获取默认值 // 单选或多选类型的值可能需要从分组条件中获取默认值
if groupValueDefault != groupView.GetGroupValue() { if opt := keyValues.Key.GetOption(groupView.GetGroupValue()); nil != opt {
if opt := keyValues.Key.GetOption(groupView.GetGroupValue()); nil != opt { newValue.MSelect = append(newValue.MSelect, &av.ValueSelect{Content: opt.Name, Color: opt.Color})
newValue.MSelect = append(newValue.MSelect, &av.ValueSelect{Content: opt.Name, Color: opt.Color})
}
} }
} }
@ -3486,18 +3484,16 @@ func sortAttributeViewRow(operation *Operation) (err error) {
groupView.GroupItemIDs = append(groupView.GroupItemIDs[:idx], groupView.GroupItemIDs[idx+1:]...) groupView.GroupItemIDs = append(groupView.GroupItemIDs[:idx], groupView.GroupItemIDs[idx+1:]...)
if operation.GroupID != operation.TargetGroupID { // 跨分组排序 if operation.GroupID != operation.TargetGroupID { // 跨分组排序
if targetGroupView := view.GetGroupByID(operation.TargetGroupID); nil != targetGroupView { if targetGroupView := view.GetGroupByID(operation.TargetGroupID); nil != targetGroupView && !gulu.Str.Contains(itemID, targetGroupView.GroupItemIDs) {
if !gulu.Str.Contains(itemID, targetGroupView.GroupItemIDs) { fillDefaultValue(attrView, view, targetGroupView, operation.PreviousID, itemID)
fillDefaultValue(attrView, view, targetGroupView, operation.PreviousID, itemID)
for i, r := range targetGroupView.GroupItemIDs { for i, r := range targetGroupView.GroupItemIDs {
if r == operation.PreviousID { if r == operation.PreviousID {
previousIndex = i + 1 previousIndex = i + 1
break break
}
} }
targetGroupView.GroupItemIDs = util.InsertElem(targetGroupView.GroupItemIDs, previousIndex, itemID)
} }
targetGroupView.GroupItemIDs = util.InsertElem(targetGroupView.GroupItemIDs, previousIndex, itemID)
} }
} else { // 同分组内排序 } else { // 同分组内排序
for i, r := range groupView.GroupItemIDs { for i, r := range groupView.GroupItemIDs {