mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
Improve API listDocsByPath param sort (#8156)
* `listDocsByPath` API `sort` param backend * `listDocsByPath` API `sort` param frontend * `listDocsByPath` API `sort` param
This commit is contained in:
parent
cb527d7765
commit
6b62a69299
8 changed files with 21 additions and 22 deletions
|
|
@ -588,7 +588,6 @@ export class Files extends Model {
|
||||||
fetchPost("/api/filetree/listDocsByPath", {
|
fetchPost("/api/filetree/listDocsByPath", {
|
||||||
notebook: toURL,
|
notebook: toURL,
|
||||||
path: toDir === "/" ? "/" : toDir + ".sy",
|
path: toDir === "/" ? "/" : toDir + ".sy",
|
||||||
sort: window.siyuan.config.fileTree.sort,
|
|
||||||
}, response => {
|
}, response => {
|
||||||
if (response.data.path === "/" && response.data.files.length === 0) {
|
if (response.data.path === "/" && response.data.files.length === 0) {
|
||||||
showMessage(window.siyuan.languages.emptyContent);
|
showMessage(window.siyuan.languages.emptyContent);
|
||||||
|
|
@ -883,8 +882,7 @@ export class Files extends Model {
|
||||||
} else if (filePath.startsWith(item.path.replace(".sy", ""))) {
|
} else if (filePath.startsWith(item.path.replace(".sy", ""))) {
|
||||||
fetchPost("/api/filetree/listDocsByPath", {
|
fetchPost("/api/filetree/listDocsByPath", {
|
||||||
notebook: data.box,
|
notebook: data.box,
|
||||||
path: item.path,
|
path: item.path
|
||||||
sort: window.siyuan.config.fileTree.sort
|
|
||||||
}, response => {
|
}, response => {
|
||||||
this.selectItem(response.data.box, filePath, response.data);
|
this.selectItem(response.data.box, filePath, response.data);
|
||||||
});
|
});
|
||||||
|
|
@ -926,7 +924,6 @@ export class Files extends Model {
|
||||||
fetchPost("/api/filetree/listDocsByPath", {
|
fetchPost("/api/filetree/listDocsByPath", {
|
||||||
notebook: notebookId,
|
notebook: notebookId,
|
||||||
path: liElement.getAttribute("data-path"),
|
path: liElement.getAttribute("data-path"),
|
||||||
sort: window.siyuan.config.fileTree.sort,
|
|
||||||
}, response => {
|
}, response => {
|
||||||
if (response.data.path === "/" && response.data.files.length === 0) {
|
if (response.data.path === "/" && response.data.files.length === 0) {
|
||||||
showMessage(window.siyuan.languages.emptyContent);
|
showMessage(window.siyuan.languages.emptyContent);
|
||||||
|
|
@ -966,8 +963,7 @@ export class Files extends Model {
|
||||||
} else {
|
} else {
|
||||||
fetchPost("/api/filetree/listDocsByPath", {
|
fetchPost("/api/filetree/listDocsByPath", {
|
||||||
notebook: notebookId,
|
notebook: notebookId,
|
||||||
path: currentPath,
|
path: currentPath
|
||||||
sort: window.siyuan.config.fileTree.sort
|
|
||||||
}, response => {
|
}, response => {
|
||||||
this.onLsSelect(response.data, filePath);
|
this.onLsSelect(response.data, filePath);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -510,8 +510,7 @@ export class MobileFiles extends Model {
|
||||||
} else if (filePath.startsWith(item.path.replace(".sy", ""))) {
|
} else if (filePath.startsWith(item.path.replace(".sy", ""))) {
|
||||||
fetchPost("/api/filetree/listDocsByPath", {
|
fetchPost("/api/filetree/listDocsByPath", {
|
||||||
notebook: data.box,
|
notebook: data.box,
|
||||||
path: item.path,
|
path: item.path
|
||||||
sort: window.siyuan.config.fileTree.sort
|
|
||||||
}, response => {
|
}, response => {
|
||||||
this.selectItem(response.data.box, filePath, response.data);
|
this.selectItem(response.data.box, filePath, response.data);
|
||||||
});
|
});
|
||||||
|
|
@ -555,8 +554,7 @@ export class MobileFiles extends Model {
|
||||||
}
|
}
|
||||||
fetchPost("/api/filetree/listDocsByPath", {
|
fetchPost("/api/filetree/listDocsByPath", {
|
||||||
notebook: notebookId,
|
notebook: notebookId,
|
||||||
path: liElement.getAttribute("data-path"),
|
path: liElement.getAttribute("data-path")
|
||||||
sort: window.siyuan.config.fileTree.sort,
|
|
||||||
}, response => {
|
}, response => {
|
||||||
if (response.data.path === "/" && response.data.files.length === 0) {
|
if (response.data.path === "/" && response.data.files.length === 0) {
|
||||||
showMessage(window.siyuan.languages.emptyContent);
|
showMessage(window.siyuan.languages.emptyContent);
|
||||||
|
|
@ -596,8 +594,7 @@ export class MobileFiles extends Model {
|
||||||
} else {
|
} else {
|
||||||
fetchPost("/api/filetree/listDocsByPath", {
|
fetchPost("/api/filetree/listDocsByPath", {
|
||||||
notebook: notebookId,
|
notebook: notebookId,
|
||||||
path: currentPath,
|
path: currentPath
|
||||||
sort: window.siyuan.config.fileTree.sort
|
|
||||||
}, response => {
|
}, response => {
|
||||||
this.onLsSelect(response.data, filePath);
|
this.onLsSelect(response.data, filePath);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -454,7 +454,6 @@ const getLeaf = (liElement: HTMLElement, flashcard:boolean) => {
|
||||||
fetchPost("/api/filetree/listDocsByPath", {
|
fetchPost("/api/filetree/listDocsByPath", {
|
||||||
notebook: notebookId,
|
notebook: notebookId,
|
||||||
path: liElement.getAttribute("data-path"),
|
path: liElement.getAttribute("data-path"),
|
||||||
sort: window.siyuan.config.fileTree.sort,
|
|
||||||
flashcard,
|
flashcard,
|
||||||
}, response => {
|
}, response => {
|
||||||
if (response.data.path === "/" && response.data.files.length === 0) {
|
if (response.data.path === "/" && response.data.files.length === 0) {
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ func heading2Doc(c *gin.Context) {
|
||||||
|
|
||||||
name := path.Base(targetPath)
|
name := path.Base(targetPath)
|
||||||
box := model.Conf.Box(targetNotebook)
|
box := model.Conf.Box(targetNotebook)
|
||||||
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount)
|
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), util.SortModeUnassigned, false, model.Conf.FileTree.MaxListCount)
|
||||||
evt := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast)
|
evt := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast)
|
||||||
evt.Data = map[string]interface{}{
|
evt.Data = map[string]interface{}{
|
||||||
"box": box,
|
"box": box,
|
||||||
|
|
@ -141,7 +141,7 @@ func li2Doc(c *gin.Context) {
|
||||||
|
|
||||||
name := path.Base(targetPath)
|
name := path.Base(targetPath)
|
||||||
box := model.Conf.Box(targetNotebook)
|
box := model.Conf.Box(targetNotebook)
|
||||||
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount)
|
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), util.SortModeUnassigned, false, model.Conf.FileTree.MaxListCount)
|
||||||
evt := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast)
|
evt := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast)
|
||||||
evt.Data = map[string]interface{}{
|
evt.Data = map[string]interface{}{
|
||||||
"box": box,
|
"box": box,
|
||||||
|
|
@ -449,7 +449,7 @@ func createDailyNote(c *gin.Context) {
|
||||||
evt.AppId = app
|
evt.AppId = app
|
||||||
|
|
||||||
name := path.Base(p)
|
name := path.Base(p)
|
||||||
files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount)
|
files, _, _ := model.ListDocTree(box.ID, path.Dir(p), util.SortModeUnassigned, false, model.Conf.FileTree.MaxListCount)
|
||||||
evt.Data = map[string]interface{}{
|
evt.Data = map[string]interface{}{
|
||||||
"box": box,
|
"box": box,
|
||||||
"path": p,
|
"path": p,
|
||||||
|
|
@ -618,7 +618,7 @@ func listDocsByPath(c *gin.Context) {
|
||||||
notebook := arg["notebook"].(string)
|
notebook := arg["notebook"].(string)
|
||||||
p := arg["path"].(string)
|
p := arg["path"].(string)
|
||||||
sortParam := arg["sort"]
|
sortParam := arg["sort"]
|
||||||
sortMode := model.Conf.FileTree.Sort
|
sortMode := util.SortModeUnassigned
|
||||||
if nil != sortParam {
|
if nil != sortParam {
|
||||||
sortMode = int(sortParam.(float64))
|
sortMode = int(sortParam.(float64))
|
||||||
}
|
}
|
||||||
|
|
@ -733,7 +733,7 @@ func getDoc(c *gin.Context) {
|
||||||
func pushCreate(box *model.Box, p, treeID string, arg map[string]interface{}) {
|
func pushCreate(box *model.Box, p, treeID string, arg map[string]interface{}) {
|
||||||
evt := util.NewCmdResult("create", 0, util.PushModeBroadcast)
|
evt := util.NewCmdResult("create", 0, util.PushModeBroadcast)
|
||||||
name := path.Base(p)
|
name := path.Base(p)
|
||||||
files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount)
|
files, _, _ := model.ListDocTree(box.ID, path.Dir(p), util.SortModeUnassigned, false, model.Conf.FileTree.MaxListCount)
|
||||||
evt.Data = map[string]interface{}{
|
evt.Data = map[string]interface{}{
|
||||||
"box": box,
|
"box": box,
|
||||||
"path": p,
|
"path": p,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mergeSubDocs(rootTree *parse.Tree) (ret *parse.Tree, err error) {
|
func mergeSubDocs(rootTree *parse.Tree) (ret *parse.Tree, err error) {
|
||||||
|
|
@ -110,7 +111,7 @@ func loadTreeNodes(box string, p string, level int) (ret []*ast.Node, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildBlockChildren(block *Block) (err error) {
|
func buildBlockChildren(block *Block) (err error) {
|
||||||
files, _, err := ListDocTree(block.Box, block.Path, Conf.FileTree.Sort, false, Conf.FileTree.MaxListCount)
|
files, _, err := ListDocTree(block.Box, block.Path, util.SortModeUnassigned, false, Conf.FileTree.MaxListCount)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -244,9 +244,13 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount
|
||||||
}
|
}
|
||||||
|
|
||||||
boxConf := box.GetConf()
|
boxConf := box.GetConf()
|
||||||
|
|
||||||
|
if util.SortModeUnassigned == sortMode {
|
||||||
|
sortMode = Conf.FileTree.Sort
|
||||||
if util.SortModeFileTree != boxConf.SortMode {
|
if util.SortModeFileTree != boxConf.SortMode {
|
||||||
sortMode = boxConf.SortMode
|
sortMode = boxConf.SortMode
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var files []*FileInfo
|
var files []*FileInfo
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ func Mount(boxID string) (alreadyMount bool, err error) {
|
||||||
|
|
||||||
box.Index()
|
box.Index()
|
||||||
// 缓存根一级的文档树展开
|
// 缓存根一级的文档树展开
|
||||||
ListDocTree(box.ID, "/", Conf.FileTree.Sort, false, Conf.FileTree.MaxListCount)
|
ListDocTree(box.ID, "/", util.SortModeUnassigned, false, Conf.FileTree.MaxListCount)
|
||||||
treenode.SaveBlockTree(false)
|
treenode.SaveBlockTree(false)
|
||||||
util.ClearPushProgress(100)
|
util.ClearPushProgress(100)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,4 +69,6 @@ const (
|
||||||
SortModeSubDocCountASC // 13:子文档数升序
|
SortModeSubDocCountASC // 13:子文档数升序
|
||||||
SortModeSubDocCountDESC // 14:子文档数降序
|
SortModeSubDocCountDESC // 14:子文档数降序
|
||||||
SortModeFileTree // 15:使用文档树排序规则
|
SortModeFileTree // 15:使用文档树排序规则
|
||||||
|
|
||||||
|
SortModeUnassigned = 256 // 256:未指定排序规则,按照笔记本优先于文档树获取排序规则
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue