mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
✨ Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
This commit is contained in:
parent
e98dcf65b6
commit
2fe3c80ab2
2 changed files with 55 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue