|
@@ -1777,3 +1777,48 @@ func (box *Box) removeSort(ids []string) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func (box *Box) addMinSort(parentPath, id string) {
|
|
|
+ docs, _, err := ListDocTree(box.ID, parentPath, util.SortModeUnassigned, false, false, 1)
|
|
|
+ if nil != err {
|
|
|
+ logging.LogErrorf("list doc tree failed: %s", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ sortVal := 0
|
|
|
+ if 0 < len(docs) {
|
|
|
+ sortVal = docs[0].Sort - 1
|
|
|
+ }
|
|
|
+
|
|
|
+ confDir := filepath.Join(util.DataDir, box.ID, ".siyuan")
|
|
|
+ if err = os.MkdirAll(confDir, 0755); nil != err {
|
|
|
+ logging.LogErrorf("create conf dir failed: %s", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ confPath := filepath.Join(confDir, "sort.json")
|
|
|
+ fullSortIDs := map[string]int{}
|
|
|
+ var data []byte
|
|
|
+ if filelock.IsExist(confPath) {
|
|
|
+ data, err = filelock.ReadFile(confPath)
|
|
|
+ if nil != err {
|
|
|
+ logging.LogErrorf("read sort conf failed: %s", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); nil != err {
|
|
|
+ logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fullSortIDs[id] = sortVal
|
|
|
+
|
|
|
+ data, err = gulu.JSON.MarshalJSON(fullSortIDs)
|
|
|
+ if nil != err {
|
|
|
+ logging.LogErrorf("marshal sort conf failed: %s", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if err = filelock.WriteFile(confPath, data); nil != err {
|
|
|
+ logging.LogErrorf("write sort conf failed: %s", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+}
|