Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964

Daniel2fe3c80ab2c6
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 339e270f43..7ec39eacff 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -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 {
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 3a122efcc9..0c1530c313 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -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 {