mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🐛 Improve av https://github.com/siyuan-note/siyuan/issues/15491
This commit is contained in:
parent
7b3acc642c
commit
580ecd617d
2 changed files with 62 additions and 7 deletions
|
|
@ -202,6 +202,7 @@ type View struct {
|
||||||
GroupHidden int `json:"groupHidden"` // 分组是否隐藏,0:显示,1:空白隐藏,2:手动隐藏
|
GroupHidden int `json:"groupHidden"` // 分组是否隐藏,0:显示,1:空白隐藏,2:手动隐藏
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupValue 获取分组视图的分组值。
|
||||||
func (view *View) GetGroupValue() string {
|
func (view *View) GetGroupValue() string {
|
||||||
if nil == view.GroupVal {
|
if nil == view.GroupVal {
|
||||||
return ""
|
return ""
|
||||||
|
|
@ -209,8 +210,8 @@ func (view *View) GetGroupValue() string {
|
||||||
return view.GroupVal.String(false)
|
return view.GroupVal.String(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGroup 获取指定分组 ID 的分组视图。
|
// GetGroupByID 获取指定分组 ID 的分组视图。
|
||||||
func (view *View) GetGroup(groupID string) *View {
|
func (view *View) GetGroupByID(groupID string) *View {
|
||||||
if nil == view.Groups {
|
if nil == view.Groups {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -222,6 +223,32 @@ func (view *View) GetGroup(groupID string) *View {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupByGroupValue 获取指定分组值的分组视图。
|
||||||
|
func (view *View) GetGroupByGroupValue(groupVal string) *View {
|
||||||
|
if nil == view.Groups {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, group := range view.Groups {
|
||||||
|
if group.GetGroupValue() == groupVal {
|
||||||
|
return group
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveGroupByID 从分组视图列表中移除指定 ID 的分组视图。
|
||||||
|
func (view *View) RemoveGroupByID(groupID string) {
|
||||||
|
if nil == view.Groups {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i, group := range view.Groups {
|
||||||
|
if group.ID == groupID {
|
||||||
|
view.Groups = append(view.Groups[:i], view.Groups[i+1:]...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetGroupKey 获取分组视图的分组字段。
|
// GetGroupKey 获取分组视图的分组字段。
|
||||||
func (view *View) GetGroupKey(attrView *AttributeView) (ret *Key) {
|
func (view *View) GetGroupKey(attrView *AttributeView) (ret *Key) {
|
||||||
if nil == view.Group || "" == view.Group.Field {
|
if nil == view.Group || "" == view.Group.Field {
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func GetAttrViewAddingBlockDefaultValues(avID, viewID, groupID, previousBlockID,
|
||||||
|
|
||||||
groupView := view
|
groupView := view
|
||||||
if "" != groupID {
|
if "" != groupID {
|
||||||
groupView = view.GetGroup(groupID)
|
groupView = view.GetGroupByID(groupID)
|
||||||
}
|
}
|
||||||
if nil == groupView {
|
if nil == groupView {
|
||||||
logging.LogErrorf("group [%s] not found in view [%s] of attribute view [%s]", groupID, viewID, avID)
|
logging.LogErrorf("group [%s] not found in view [%s] of attribute view [%s]", groupID, viewID, avID)
|
||||||
|
|
@ -415,9 +415,11 @@ func SetAttributeViewGroup(avID, blockID string, group *av.ViewGroup) (err error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
oldHideEmpty := false
|
var oldHideEmpty, firstInit bool
|
||||||
if nil != view.Group {
|
if nil != view.Group {
|
||||||
oldHideEmpty = view.Group.HideEmpty
|
oldHideEmpty = view.Group.HideEmpty
|
||||||
|
} else {
|
||||||
|
firstInit = true
|
||||||
}
|
}
|
||||||
|
|
||||||
groupStates := getAttrViewGroupStates(view)
|
groupStates := getAttrViewGroupStates(view)
|
||||||
|
|
@ -442,6 +444,32 @@ func SetAttributeViewGroup(avID, blockID string, group *av.ViewGroup) (err error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if firstInit {
|
||||||
|
if groupKey := view.GetGroupKey(attrView); nil != groupKey && (av.KeyTypeSelect == groupKey.Type || av.KeyTypeMSelect == groupKey.Type) {
|
||||||
|
// 首次设置分组时,如果分组字段是单选或多选类型,则将分组方式改为手动排序,并按选项顺序排序分组视图 https://github.com/siyuan-note/siyuan/issues/15491
|
||||||
|
view.Group.Order = av.GroupOrderMan
|
||||||
|
optionSort := map[string]int{}
|
||||||
|
for i, op := range groupKey.Options {
|
||||||
|
optionSort[op.Name] = i
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultGroup := view.GetGroupByGroupValue(groupValueDefault)
|
||||||
|
if nil != defaultGroup {
|
||||||
|
view.RemoveGroupByID(defaultGroup.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(view.Groups, func(i, j int) bool {
|
||||||
|
vSort := optionSort[view.Groups[i].GetGroupValue()]
|
||||||
|
oSort := optionSort[view.Groups[j].GetGroupValue()]
|
||||||
|
return vSort < oSort
|
||||||
|
})
|
||||||
|
|
||||||
|
if nil != defaultGroup {
|
||||||
|
view.Groups = append(view.Groups, defaultGroup)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = av.SaveAttributeView(attrView)
|
err = av.SaveAttributeView(attrView)
|
||||||
ReloadAttrView(avID)
|
ReloadAttrView(avID)
|
||||||
return
|
return
|
||||||
|
|
@ -3261,7 +3289,7 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
|
||||||
|
|
||||||
groupView := view
|
groupView := view
|
||||||
if "" != groupID {
|
if "" != groupID {
|
||||||
groupView = view.GetGroup(groupID)
|
groupView = view.GetGroupByID(groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultValues := getAttrViewAddingBlockDefaultValues(attrView, view, groupView, previousBlockID, addingBlockID)
|
defaultValues := getAttrViewAddingBlockDefaultValues(attrView, view, groupView, previousBlockID, addingBlockID)
|
||||||
|
|
@ -3842,7 +3870,7 @@ func sortAttributeViewRow(operation *Operation) (err error) {
|
||||||
var idx, previousIndex int
|
var idx, previousIndex int
|
||||||
|
|
||||||
if nil != view.Group && "" != operation.GroupID {
|
if nil != view.Group && "" != operation.GroupID {
|
||||||
if groupView := view.GetGroup(operation.GroupID); nil != groupView {
|
if groupView := view.GetGroupByID(operation.GroupID); nil != groupView {
|
||||||
for i, id := range groupView.GroupItemIDs {
|
for i, id := range groupView.GroupItemIDs {
|
||||||
if id == operation.ID {
|
if id == operation.ID {
|
||||||
itemID = id
|
itemID = id
|
||||||
|
|
@ -3858,7 +3886,7 @@ 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.GetGroup(operation.TargetGroupID); nil != targetGroupView {
|
if targetGroupView := view.GetGroupByID(operation.TargetGroupID); nil != targetGroupView {
|
||||||
groupKey := view.GetGroupKey(attrView)
|
groupKey := view.GetGroupKey(attrView)
|
||||||
nearItem := getNearItem(attrView, view, targetGroupView, operation.PreviousID)
|
nearItem := getNearItem(attrView, view, targetGroupView, operation.PreviousID)
|
||||||
newValue := getNewValueByNearItem(nearItem, groupKey, operation.ID)
|
newValue := getNewValueByNearItem(nearItem, groupKey, operation.ID)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue