This commit is contained in:
Daniel 2025-07-01 17:56:32 +08:00
parent e98dcf65b6
commit 2fe3c80ab2
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 55 additions and 0 deletions

View file

@ -44,6 +44,59 @@ import (
"github.com/xrash/smetrics"
)
func (tx *Transaction) doSetAttrViewGroup(operation *Operation) (ret *TxErr) {
err := setAttrViewGroup(operation)
if err != nil {
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
}
return
}
func setAttrViewGroup(operation *Operation) error {
attrView, err := av.ParseAttributeView(operation.AvID)
if err != nil {
return err
}
view, err := getAttrViewViewByBlockID(attrView, operation.BlockID)
if err != nil {
return err
}
group := operation.Data.(*av.ViewGroup)
view.Group = group
// TODO Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
// 生成分组数据
switch view.LayoutType {
case av.LayoutTypeTable:
table := sql.RenderAttributeViewTable(attrView, view, "")
groupRows := map[string][]*av.TableRow{}
for _, row := range table.Rows {
value := row.GetValue(group.Field)
switch group.Method {
case av.GroupMethodValue:
strVal := value.String(false)
groupRows[strVal] = append(groupRows[strVal], row)
}
}
for _, rows := range groupRows {
v := av.NewTableView()
v.Table = av.NewLayoutTable()
for _, row := range rows {
v.Table.RowIDs = append(v.Table.RowIDs, row.ID)
}
view.Groups = append(view.Groups, v)
}
case av.LayoutTypeGallery:
}
err = av.SaveAttributeView(attrView)
return err
}
func (tx *Transaction) doSetAttrViewCardAspectRatio(operation *Operation) (ret *TxErr) {
err := setAttrViewCardAspectRatio(operation)
if err != nil {

View file

@ -296,6 +296,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSetAttrViewBlockView(op)
case "setAttrViewCardAspectRatio":
ret = tx.doSetAttrViewCardAspectRatio(op)
case "doSetAttrViewGroup":
ret = tx.doSetAttrViewGroup(op)
}
if nil != ret {