From 072a55db7c7ed7f9432ca12baa535d9c1a7c9070 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Dec 2023 21:02:31 +0800 Subject: [PATCH 1/6] :art: Add Relation column to database table view https://github.com/siyuan-note/siyuan/issues/9888 --- kernel/model/attribute_view.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 3fc696aa6..3f15a2561 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -49,6 +49,7 @@ type SearchAttributeViewResult struct { AvID string `json:"avID"` AvName string `json:"avName"` BlockID string `json:"blockID"` + HPath string `json:"hPath"` } func SearchAttributeView(keyword string, page int, pageSize int) (ret []*SearchAttributeViewResult, pageCount int) { @@ -102,11 +103,19 @@ func SearchAttributeView(keyword string, page int, pageSize int) (ret []*SearchA break } } + + var hPath string + baseBlock := treenode.GetBlockTreeRootByPath(node.Box, node.Path) + if nil != baseBlock { + hPath = baseBlock.HPath + } + if !exist { ret = append(ret, &SearchAttributeViewResult{ AvID: avID, AvName: attrView.Name, BlockID: block.ID, + HPath: hPath, }) } } From c38547107833bb4ec3ef7b09bcc12dc06d8f5f35 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Dec 2023 21:05:52 +0800 Subject: [PATCH 2/6] :art: Add Relation column to database table view https://github.com/siyuan-note/siyuan/issues/9888 --- kernel/model/attribute_view.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 3f15a2561..11c734609 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -109,6 +109,10 @@ func SearchAttributeView(keyword string, page int, pageSize int) (ret []*SearchA if nil != baseBlock { hPath = baseBlock.HPath } + box := Conf.Box(node.Box) + if nil != box { + hPath = box.Name + hPath + } if !exist { ret = append(ret, &SearchAttributeViewResult{ From 4e8d045452a6b61f4e13e3f2e5fc30ee3a7f9fd0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Dec 2023 21:47:01 +0800 Subject: [PATCH 3/6] :art: Add Relation column to database table view https://github.com/siyuan-note/siyuan/issues/9888 --- kernel/model/attribute_view.go | 31 +++++++++++++++++++++++++++---- kernel/treenode/node.go | 14 ++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 11c734609..9767722aa 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -183,6 +183,20 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) { // 先处理创建时间和更新时间 for _, kv := range keyValues { switch kv.Key.Type { + case av.KeyTypeRelation: + relKey, _ := attrView.GetKey(kv.Values[0].KeyID) + if nil != relKey && nil != relKey.Relation { + destAv, _ := av.ParseAttributeView(relKey.Relation.AvID) + if nil != destAv { + blocks := map[string]string{} + for _, blockValue := range destAv.GetBlockKeyValues().Values { + blocks[blockValue.BlockID] = blockValue.Block.Content + } + for _, blockID := range kv.Values[0].Relation.BlockIDs { + kv.Values[0].Relation.Contents = append(kv.Values[0].Relation.Contents, blocks[blockID]) + } + } + } case av.KeyTypeCreated: createdStr := blockID[:len("20060102150405")] created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local) @@ -686,10 +700,19 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues) cell.Value.Template.Content = content case av.KeyTypeRelation: // 渲染关联列 - - //for _, blockID := range cell.Value.Relation.BlockIDs { - // - //} + relKey, _ := attrView.GetKey(cell.Value.KeyID) + if nil != relKey && nil != relKey.Relation { + destAv, _ := av.ParseAttributeView(relKey.Relation.AvID) + if nil != destAv { + blocks := map[string]string{} + for _, blockValue := range destAv.GetBlockKeyValues().Values { + blocks[blockValue.BlockID] = blockValue.Block.Content + } + for _, blockID := range cell.Value.Relation.BlockIDs { + cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, blocks[blockID]) + } + } + } case av.KeyTypeCreated: // 渲染创建时间 createdStr := row.ID[:len("20060102150405")] created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local) diff --git a/kernel/treenode/node.go b/kernel/treenode/node.go index f15305744..82ef223c0 100644 --- a/kernel/treenode/node.go +++ b/kernel/treenode/node.go @@ -724,6 +724,20 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a } content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues) cell.Value.Template.Content = content + case av.KeyTypeRelation: // 渲染关联列 + relKey, _ := attrView.GetKey(cell.Value.KeyID) + if nil != relKey && nil != relKey.Relation { + destAv, _ := av.ParseAttributeView(relKey.Relation.AvID) + if nil != destAv { + blocks := map[string]string{} + for _, blockValue := range destAv.GetBlockKeyValues().Values { + blocks[blockValue.BlockID] = blockValue.Block.Content + } + for _, blockID := range cell.Value.Relation.BlockIDs { + cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, blocks[blockID]) + } + } + } case av.KeyTypeCreated: // 渲染创建时间 createdStr := row.ID[:len("20060102150405")] created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local) From ad6edcae03ab9916d44c3e662d0ff7a31a73f10f Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Dec 2023 22:04:53 +0800 Subject: [PATCH 4/6] :art: Improve kernel stability https://github.com/siyuan-note/siyuan/issues/9912 --- kernel/model/path.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/kernel/model/path.go b/kernel/model/path.go index be9678ea6..0c25d6d73 100644 --- a/kernel/model/path.go +++ b/kernel/model/path.go @@ -52,9 +52,9 @@ func createDocsByHPath(boxID, hPath, content, parentID, id string /* id 参数 return } } else { + retID = ast.NewNodeID() if "" == id { - id = ast.NewNodeID() - retID = id + id = retID } } @@ -95,10 +95,12 @@ func createDocsByHPath(boxID, hPath, content, parentID, id string /* id 参数 root = hpathBtMap[hp] isNotLast := i < len(parts)-1 if nil == root { - if "" == retID { - retID = ast.NewNodeID() + rootID := ast.NewNodeID() + if i == len(parts)-1 { + rootID = retID } - pathBuilder.WriteString(retID) + + pathBuilder.WriteString(rootID) docP := pathBuilder.String() + ".sy" if isNotLast { if _, err = createDoc(boxID, docP, part, ""); nil != err { @@ -118,9 +120,6 @@ func createDocsByHPath(boxID, hPath, content, parentID, id string /* id 参数 } } } else { - if "" == retID { - retID = root.ID - } pathBuilder.WriteString(root.ID) if !isNotLast { pathBuilder.WriteString(".sy") From 6adc275cc83182257e5e7cb4f35011bac6e47fc0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Dec 2023 22:17:41 +0800 Subject: [PATCH 5/6] :art: Creating a dailynote existed no longer expands the doc tree https://github.com/siyuan-note/siyuan/issues/9959 --- kernel/api/filetree.go | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index fb92337f5..2d7371e5e 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -472,29 +472,28 @@ func createDailyNote(c *gin.Context) { return } - appArg := arg["app"] - app := "" - if nil != appArg { - app = appArg.(string) + if !existed { + // 只有创建的情况才推送,已经存在的情况不推送 + // Creating a dailynote no longer expands the doc tree https://github.com/siyuan-note/siyuan/issues/9959 + appArg := arg["app"] + app := "" + if nil != appArg { + app = appArg.(string) + } + evt := util.NewCmdResult("createdailynote", 0, util.PushModeBroadcast) + evt.AppId = app + name := path.Base(p) + files, _, _ := model.ListDocTree(box.ID, path.Dir(p), util.SortModeUnassigned, false, false, model.Conf.FileTree.MaxListCount) + evt.Data = map[string]interface{}{ + "box": box, + "path": p, + "files": files, + "name": name, + "id": tree.Root.ID, + } + evt.Callback = arg["callback"] + util.PushEvent(evt) } - pushMode := util.PushModeBroadcast - if existed && "" != app { - pushMode = util.PushModeBroadcastApp - } - evt := util.NewCmdResult("createdailynote", 0, pushMode) - evt.AppId = app - - name := path.Base(p) - files, _, _ := model.ListDocTree(box.ID, path.Dir(p), util.SortModeUnassigned, false, false, model.Conf.FileTree.MaxListCount) - evt.Data = map[string]interface{}{ - "box": box, - "path": p, - "files": files, - "name": name, - "id": tree.Root.ID, - } - evt.Callback = arg["callback"] - util.PushEvent(evt) ret.Data = map[string]interface{}{ "id": tree.Root.ID, From aa25da4cf2c64fa1e4adcc0d2f101b5d3f432a6b Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 23 Dec 2023 22:17:53 +0800 Subject: [PATCH 6/6] :art: Creating a dailynote existed no longer expands the doc tree https://github.com/siyuan-note/siyuan/issues/9959 --- kernel/api/filetree.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index 2d7371e5e..ef6efc83d 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -474,7 +474,7 @@ func createDailyNote(c *gin.Context) { if !existed { // 只有创建的情况才推送,已经存在的情况不推送 - // Creating a dailynote no longer expands the doc tree https://github.com/siyuan-note/siyuan/issues/9959 + // Creating a dailynote existed no longer expands the doc tree https://github.com/siyuan-note/siyuan/issues/9959 appArg := arg["app"] app := "" if nil != appArg {