mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
🎨 Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
This commit is contained in:
parent
05f4d2995c
commit
8ade9ddb5f
3 changed files with 82 additions and 8 deletions
|
|
@ -198,6 +198,7 @@ type View struct {
|
||||||
GroupName string `json:"groupName,omitempty"` // 分组名称
|
GroupName string `json:"groupName,omitempty"` // 分组名称
|
||||||
GroupFolded bool `json:"groupFolded,omitempty"` // 分组是否折叠
|
GroupFolded bool `json:"groupFolded,omitempty"` // 分组是否折叠
|
||||||
GroupHidden bool `json:"groupHidden,omitempty"` // 分组是否隐藏
|
GroupHidden bool `json:"groupHidden,omitempty"` // 分组是否隐藏
|
||||||
|
GroupHideEmpty bool `json:"groupHideEmpty,omitempty"` // 分组是否隐藏空分组
|
||||||
GroupDefault bool `json:"groupDefault,omitempty"` // 是否为默认分组
|
GroupDefault bool `json:"groupDefault,omitempty"` // 是否为默认分组
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,75 @@ import (
|
||||||
"github.com/xrash/smetrics"
|
"github.com/xrash/smetrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (tx *Transaction) doSetGroupHideEmpty(operation *Operation) (ret *TxErr) {
|
||||||
|
if err := SetGroupHideEmpty(operation.AvID, operation.BlockID, operation.Data.(bool)); nil != err {
|
||||||
|
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetGroupHideEmpty(avID, blockID string, hidden 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
|
||||||
|
}
|
||||||
|
|
||||||
|
view.GroupHideEmpty = hidden
|
||||||
|
|
||||||
|
err = av.SaveAttributeView(attrView)
|
||||||
|
if err != nil {
|
||||||
|
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Transaction) doHideAttrViewGroup(operation *Operation) (ret *TxErr) {
|
||||||
|
if err := HideAttributeViewGroup(operation.AvID, operation.BlockID, operation.ID, operation.Data.(bool)); nil != err {
|
||||||
|
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func HideAttributeViewGroup(avID, blockID, groupID string, hidden 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.GroupHidden = hidden
|
||||||
|
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 {
|
||||||
|
|
@ -62,7 +131,7 @@ func (tx *Transaction) doSetAttrViewGroup(operation *Operation) (ret *TxErr) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetAttributeViewGroup(avID, blockID string, group *av.ViewGroup) error {
|
func SetAttributeViewGroup(avID, blockID string, group *av.ViewGroup) (err error) {
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -299,6 +299,10 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
||||||
ret = tx.doSetAttrViewCardAspectRatio(op)
|
ret = tx.doSetAttrViewCardAspectRatio(op)
|
||||||
case "setAttrViewGroup":
|
case "setAttrViewGroup":
|
||||||
ret = tx.doSetAttrViewGroup(op)
|
ret = tx.doSetAttrViewGroup(op)
|
||||||
|
case "hideAttrViewGroup":
|
||||||
|
ret = tx.doHideAttrViewGroup(op)
|
||||||
|
case "setGroupHideEmpty":
|
||||||
|
ret = tx.doSetGroupHideEmpty(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != ret {
|
if nil != ret {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue