This commit is contained in:
Daniel 2025-07-06 17:41:43 +08:00
parent 05f4d2995c
commit 8ade9ddb5f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 82 additions and 8 deletions

View file

@ -44,6 +44,75 @@ import (
"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) {
data, err := gulu.JSON.MarshalJSON(operation.Data)
if nil != err {
@ -62,7 +131,7 @@ func (tx *Transaction) doSetAttrViewGroup(operation *Operation) (ret *TxErr) {
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)
if err != nil {
return err