This commit is contained in:
Liang Ding 2022-11-04 15:35:22 +08:00
parent 89166ca0d5
commit 75925c9e4f
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 25 additions and 10 deletions

View file

@ -1028,12 +1028,6 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
} }
func MoveDocs(fromPaths []string, toPath string) (err error) { func MoveDocs(fromPaths []string, toPath string) (err error) {
util.PushEndlessProgress(Conf.Language(116))
WaitForWritingFiles()
fromPaths = util.FilterMoveDocFromPaths(fromPaths, toPath)
pathsBoxes := getBoxesByPaths(fromPaths)
toID := strings.TrimSuffix(path.Base(toPath), ".sy") toID := strings.TrimSuffix(path.Base(toPath), ".sy")
toBlock := treenode.GetBlockTree(toID) toBlock := treenode.GetBlockTree(toID)
if nil == toBlock { if nil == toBlock {
@ -1047,6 +1041,14 @@ func MoveDocs(fromPaths []string, toPath string) (err error) {
return return
} }
fromPaths = util.FilterMoveDocFromPaths(fromPaths, toPath)
pathsBoxes := getBoxesByPaths(fromPaths)
needShowProgress := 32 < len(fromPaths)
if needShowProgress {
util.PushEndlessProgress(Conf.Language(116))
}
WaitForWritingFiles()
for fromPath, fromBox := range pathsBoxes { for fromPath, fromBox := range pathsBoxes {
_, err = moveDoc(fromBox, fromPath, toBox, toPath) _, err = moveDoc(fromBox, fromPath, toBox, toPath)
if nil != err { if nil != err {
@ -1056,9 +1058,11 @@ func MoveDocs(fromPaths []string, toPath string) (err error) {
cache.ClearDocsIAL() cache.ClearDocsIAL()
IncSync() IncSync()
util.PushEndlessProgress(Conf.Language(113)) if needShowProgress {
sql.WaitForWritingDatabase() util.PushEndlessProgress(Conf.Language(113))
util.ReloadUI() sql.WaitForWritingDatabase()
util.ReloadUI()
}
return return
} }
@ -1167,6 +1171,16 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string) (newPath
moveTree(tree) moveTree(tree)
moveSorts(tree.ID, fromBox.ID, toBox.ID) moveSorts(tree.ID, fromBox.ID, toBox.ID)
} }
evt := util.NewCmdResult("moveDoc", 0, util.PushModeBroadcast, util.PushModeNone)
evt.Data = map[string]interface{}{
"fromNotebook": fromBox.ID,
"fromPath": fromPath,
"toNotebook": toBox.ID,
"toPath": toPath,
"newPath": newPath,
}
util.PushEvent(evt)
return return
} }

View file

@ -178,11 +178,12 @@ func NormalizeEndpoint(endpoint string) string {
func FilterMoveDocFromPaths(fromPaths []string, toPath string) (retFromPaths []string) { func FilterMoveDocFromPaths(fromPaths []string, toPath string) (retFromPaths []string) {
fromPaths = append(fromPaths, toPath) fromPaths = append(fromPaths, toPath)
retFromPaths = FilterSelfChildDocs(fromPaths) retFromPaths = FilterSelfChildDocs(fromPaths)
retFromPaths = gulu.Str.ExcludeElem(retFromPaths, []string{toPath})
return return
} }
func FilterSelfChildDocs(paths []string) (ret []string) { func FilterSelfChildDocs(paths []string) (ret []string) {
sort.Slice(paths, func(i, j int) bool { return len(paths[i]) < len(paths[j]) }) sort.Slice(paths, func(i, j int) bool { return strings.Count(paths[i], "/") < strings.Count(paths[j], "/") })
dirs := map[string]string{} dirs := map[string]string{}
for _, fromPath := range paths { for _, fromPath := range paths {