From 9a98ba015fe06adb0d586e1f0bc36d589749034b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 6 Apr 2023 18:22:41 +0800 Subject: [PATCH 1/5] :art: Add a new API `Move block` https://github.com/siyuan-note/siyuan/issues/7903 --- kernel/api/block_op.go | 48 ++++++++++++++++++++++++++++++++++++++++++ kernel/api/router.go | 1 + 2 files changed, 49 insertions(+) diff --git a/kernel/api/block_op.go b/kernel/api/block_op.go index 364ccd295..f5df3a91d 100644 --- a/kernel/api/block_op.go +++ b/kernel/api/block_op.go @@ -29,6 +29,54 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func moveBlock(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + id := arg["id"].(string) + if util.InvalidIDPattern(id, ret) { + return + } + + var parentID, previousID string + if nil != arg["parentID"] { + parentID = arg["parentID"].(string) + if util.InvalidIDPattern(parentID, ret) { + return + } + } + if nil != arg["previousID"] { + previousID = arg["previousID"].(string) + if util.InvalidIDPattern(previousID, ret) { + return + } + } + + transactions := []*model.Transaction{ + { + DoOperations: []*model.Operation{ + { + Action: "move", + ID: id, + PreviousID: previousID, + ParentID: parentID, + }, + }, + }, + } + + model.PerformTransactions(&transactions) + model.WaitForWritingFiles() + + ret.Data = transactions + broadcastTransactions(transactions) +} + func appendBlock(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/api/router.go b/kernel/api/router.go index e8e14c4a1..089efaf4a 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -164,6 +164,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/block/appendBlock", model.CheckAuth, model.CheckReadonly, appendBlock) ginServer.Handle("POST", "/api/block/updateBlock", model.CheckAuth, model.CheckReadonly, updateBlock) ginServer.Handle("POST", "/api/block/deleteBlock", model.CheckAuth, model.CheckReadonly, deleteBlock) + ginServer.Handle("POST", "/api/block/moveBlock", model.CheckAuth, model.CheckReadonly, moveBlock) ginServer.Handle("POST", "/api/block/setBlockReminder", model.CheckAuth, model.CheckReadonly, setBlockReminder) ginServer.Handle("POST", "/api/block/getHeadingLevelTransaction", model.CheckAuth, getHeadingLevelTransaction) ginServer.Handle("POST", "/api/block/getHeadingDeleteTransaction", model.CheckAuth, getHeadingDeleteTransaction) From 1a09c04b92cd7404caa4521c454f0db7d8e7ca86 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 6 Apr 2023 18:29:44 +0800 Subject: [PATCH 2/5] :art: Add a new API `Move block` https://github.com/siyuan-note/siyuan/issues/7903 --- API.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ API_zh_CN.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/API.md b/API.md index 741f9ef11..d812967e6 100644 --- a/API.md +++ b/API.md @@ -27,6 +27,7 @@ * [Append blocks](#Append-blocks) * [Update a block](#Update-a-block) * [Delete a block](#Delete-a-block) + * [Move a block](#Move-a-block) * [Get a block kramdown](#Get-a-block-kramdown) * [Attributes](#Attributes) * [Set block attributes](#Set-block-attributes) @@ -696,6 +697,50 @@ View API token in Settings - About, request header: `Authorization: T } ``` +### Move a block + +* `/api/block/moveBlock` +* Parameters + + ```json + { + "id": "20230406180530-3o1rqkc", + "previousID": "20230406152734-if5kyx6", + "parentID": "20230404183855-woe52ko" + } + ``` + + * `id`: Block ID to move + * `previousID`: The ID of the previous block, used to anchor the insertion position + * `parentID`: The ID of the parent block, used to anchor the insertion position, `previousID` and `parentID` cannot be empty at the same time, if they exist at the same time, `previousID` will be used first +* Return value + + ```json + { + "code": 0, + "msg": "", + "data": [ + { + "doOperations": [ + { + "action": "move", + "data": null, + "id": "20230406180530-3o1rqkc", + "parentID": "20230404183855-woe52ko", + "previousID": "20230406152734-if5kyx6", + "nextID": "", + "retData": null, + "srcIDs": null, + "name": "", + "type": "" + } + ], + "undoOperations": null + } + ] + } + ``` + ### Get a block kramdown * `/api/block/getBlockKramdown` diff --git a/API_zh_CN.md b/API_zh_CN.md index d159064be..340f155ad 100644 --- a/API_zh_CN.md +++ b/API_zh_CN.md @@ -27,6 +27,7 @@ * [插入后置子块](#插入后置子块) * [更新块](#更新块) * [删除块](#删除块) + * [移动块](#移动块) * [获取块 kramdown 源码](#获取块-kramdown-源码) * [属性](#属性) * [设置块属性](#设置块属性) @@ -690,6 +691,50 @@ } ``` +### 移动块 + +* `/api/block/moveBlock` +* 参数 + + ```json + { + "id": "20230406180530-3o1rqkc", + "previousID": "20230406152734-if5kyx6", + "parentID": "20230404183855-woe52ko" + } + ``` + + * `id`:待移动块 ID + * `previousID`:前一个块的 ID,用于锚定插入位置 + * `parentID`:父块的 ID,用于锚定插入位置,`previousID` 和 `parentID` 不能同时为空,同时存在的话优先使用 `previousID` +* 返回值 + + ```json + { + "code": 0, + "msg": "", + "data": [ + { + "doOperations": [ + { + "action": "move", + "data": null, + "id": "20230406180530-3o1rqkc", + "parentID": "20230404183855-woe52ko", + "previousID": "20230406152734-if5kyx6", + "nextID": "", + "retData": null, + "srcIDs": null, + "name": "", + "type": "" + } + ], + "undoOperations": null + } + ] + } + ``` + ### 获取块 kramdown 源码 * `/api/block/getBlockKramdown` From 831baf5ca0c2db8adeb665f2f43f5dd3fb1a3726 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 6 Apr 2023 19:10:25 +0800 Subject: [PATCH 3/5] :memo: Move CHANGELOG.md to changelogs dir https://github.com/siyuan-note/siyuan/issues/7904 --- CHANGELOG.md => changelogs/v0.1.0-v2.8.3.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CHANGELOG.md => changelogs/v0.1.0-v2.8.3.md (100%) diff --git a/CHANGELOG.md b/changelogs/v0.1.0-v2.8.3.md similarity index 100% rename from CHANGELOG.md rename to changelogs/v0.1.0-v2.8.3.md From e980d34548d3437e219676680d59cad223757139 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 6 Apr 2023 19:10:44 +0800 Subject: [PATCH 4/5] :memo: Create a separate changelog file for each release https://github.com/siyuan-note/siyuan/issues/7906 --- changelogs/v2.8.4.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 changelogs/v2.8.4.md diff --git a/changelogs/v2.8.4.md b/changelogs/v2.8.4.md new file mode 100644 index 000000000..e69de29bb From bebc7eb2c3049bc84a35516aa07a61134ed1355e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 6 Apr 2023 19:10:55 +0800 Subject: [PATCH 5/5] :memo: Add zh_CN changelog https://github.com/siyuan-note/siyuan/issues/7905 --- changelogs/v2.8.4_zh_CN.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 changelogs/v2.8.4_zh_CN.md diff --git a/changelogs/v2.8.4_zh_CN.md b/changelogs/v2.8.4_zh_CN.md new file mode 100644 index 000000000..e69de29bb