|
@@ -141,9 +141,18 @@ func (box *Box) moveCorruptedData(filePath string) {
|
|
logging.LogWarnf("moved corrupted data file [%s] to [%s]", filePath, to)
|
|
logging.LogWarnf("moved corrupted data file [%s] to [%s]", filePath, to)
|
|
}
|
|
}
|
|
|
|
|
|
-func SearchDocsByKeyword(keyword string) (ret []map[string]string) {
|
|
|
|
|
|
+func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]string) {
|
|
ret = []map[string]string{}
|
|
ret = []map[string]string{}
|
|
|
|
|
|
|
|
+ var deckBlockIDs []string
|
|
|
|
+ if flashcard {
|
|
|
|
+ deck := Decks[builtinDeckID]
|
|
|
|
+ if nil != deck {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ deckBlockIDs = deck.GetBlockIDs()
|
|
|
|
+ }
|
|
|
|
+
|
|
openedBoxes := Conf.GetOpenedBoxes()
|
|
openedBoxes := Conf.GetOpenedBoxes()
|
|
boxes := map[string]*Box{}
|
|
boxes := map[string]*Box{}
|
|
for _, box := range openedBoxes {
|
|
for _, box := range openedBoxes {
|
|
@@ -154,7 +163,13 @@ func SearchDocsByKeyword(keyword string) (ret []map[string]string) {
|
|
if "" != keyword {
|
|
if "" != keyword {
|
|
for _, box := range boxes {
|
|
for _, box := range boxes {
|
|
if strings.Contains(box.Name, keyword) {
|
|
if strings.Contains(box.Name, keyword) {
|
|
- ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon})
|
|
|
|
|
|
+ if flashcard {
|
|
|
|
+ if isBoxContainFlashcard(box.ID, deckBlockIDs) {
|
|
|
|
+ ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon})
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon})
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -168,17 +183,29 @@ func SearchDocsByKeyword(keyword string) (ret []map[string]string) {
|
|
rootBlocks = sql.QueryRootBlockByCondition(condition)
|
|
rootBlocks = sql.QueryRootBlockByCondition(condition)
|
|
} else {
|
|
} else {
|
|
for _, box := range boxes {
|
|
for _, box := range boxes {
|
|
- ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon})
|
|
|
|
|
|
+ if flashcard {
|
|
|
|
+ if isBoxContainFlashcard(box.ID, deckBlockIDs) {
|
|
|
|
+ ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon})
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon})
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- for _, block := range rootBlocks {
|
|
|
|
- b := boxes[block.Box]
|
|
|
|
|
|
+ for _, rootBlock := range rootBlocks {
|
|
|
|
+ b := boxes[rootBlock.Box]
|
|
if nil == b {
|
|
if nil == b {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- hPath := b.Name + block.HPath
|
|
|
|
- ret = append(ret, map[string]string{"path": block.Path, "hPath": hPath, "box": block.Box, "boxIcon": b.Icon})
|
|
|
|
|
|
+ hPath := b.Name + rootBlock.HPath
|
|
|
|
+ if flashcard {
|
|
|
|
+ if isTreeContainFlashcard(rootBlock.ID, deckBlockIDs) {
|
|
|
|
+ ret = append(ret, map[string]string{"path": rootBlock.Path, "hPath": hPath, "box": rootBlock.Box, "boxIcon": b.Icon})
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ret = append(ret, map[string]string{"path": rootBlock.Path, "hPath": hPath, "box": rootBlock.Box, "boxIcon": b.Icon})
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
sort.Slice(ret, func(i, j int) bool {
|
|
sort.Slice(ret, func(i, j int) bool {
|
|
@@ -194,7 +221,7 @@ type FileInfo struct {
|
|
isdir bool
|
|
isdir bool
|
|
}
|
|
}
|
|
|
|
|
|
-func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err error) {
|
|
|
|
|
|
+func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount int) (ret []*File, totals int, err error) {
|
|
//os.MkdirAll("pprof", 0755)
|
|
//os.MkdirAll("pprof", 0755)
|
|
//cpuProfile, _ := os.Create("pprof/cpu_profile_list_doc_tree")
|
|
//cpuProfile, _ := os.Create("pprof/cpu_profile_list_doc_tree")
|
|
//pprof.StartCPUProfile(cpuProfile)
|
|
//pprof.StartCPUProfile(cpuProfile)
|
|
@@ -202,6 +229,15 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|
|
|
|
|
ret = []*File{}
|
|
ret = []*File{}
|
|
|
|
|
|
|
|
+ var deckBlockIDs []string
|
|
|
|
+ if flashcard {
|
|
|
|
+ deck := Decks[builtinDeckID]
|
|
|
|
+ if nil != deck {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ deckBlockIDs = deck.GetBlockIDs()
|
|
|
|
+ }
|
|
|
|
+
|
|
box := Conf.Box(boxID)
|
|
box := Conf.Box(boxID)
|
|
if nil == box {
|
|
if nil == box {
|
|
return nil, 0, errors.New(Conf.Language(0))
|
|
return nil, 0, errors.New(Conf.Language(0))
|
|
@@ -247,7 +283,15 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- docs = append(docs, doc)
|
|
|
|
|
|
+
|
|
|
|
+ if flashcard {
|
|
|
|
+ rootID := strings.TrimSuffix(filepath.Base(parentDocPath), ".sy")
|
|
|
|
+ if isTreeContainFlashcard(rootID, deckBlockIDs) {
|
|
|
|
+ docs = append(docs, doc)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ docs = append(docs, doc)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
@@ -259,8 +303,15 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|
|
|
|
|
if ial := box.docIAL(file.path); nil != ial {
|
|
if ial := box.docIAL(file.path); nil != ial {
|
|
doc := box.docFromFileInfo(file, ial)
|
|
doc := box.docFromFileInfo(file, ial)
|
|
- docs = append(docs, doc)
|
|
|
|
- continue
|
|
|
|
|
|
+
|
|
|
|
+ if flashcard {
|
|
|
|
+ rootID := strings.TrimSuffix(filepath.Base(file.path), ".sy")
|
|
|
|
+ if isTreeContainFlashcard(rootID, deckBlockIDs) {
|
|
|
|
+ docs = append(docs, doc)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ docs = append(docs, doc)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
elapsed = time.Now().Sub(start).Milliseconds()
|
|
elapsed = time.Now().Sub(start).Milliseconds()
|
|
@@ -312,8 +363,8 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|
return fileTreeFiles[i].Sort < fileTreeFiles[j].Sort
|
|
return fileTreeFiles[i].Sort < fileTreeFiles[j].Sort
|
|
})
|
|
})
|
|
ret = append(ret, fileTreeFiles...)
|
|
ret = append(ret, fileTreeFiles...)
|
|
- if Conf.FileTree.MaxListCount < len(ret) {
|
|
|
|
- ret = ret[:Conf.FileTree.MaxListCount]
|
|
|
|
|
|
+ if maxListCount < len(ret) {
|
|
|
|
+ ret = ret[:maxListCount]
|
|
}
|
|
}
|
|
ret = ret[:]
|
|
ret = ret[:]
|
|
return
|
|
return
|
|
@@ -339,8 +390,8 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|
ret = append(ret, docs...)
|
|
ret = append(ret, docs...)
|
|
}
|
|
}
|
|
|
|
|
|
- if Conf.FileTree.MaxListCount < len(ret) {
|
|
|
|
- ret = ret[:Conf.FileTree.MaxListCount]
|
|
|
|
|
|
+ if maxListCount < len(ret) {
|
|
|
|
+ ret = ret[:maxListCount]
|
|
}
|
|
}
|
|
ret = ret[:]
|
|
ret = ret[:]
|
|
|
|
|