From 3d3b2df07ac55c9a7ba4c787abda4fd28de825ab Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 00:28:34 +0800 Subject: [PATCH 1/2] :art: Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958 --- kernel/model/import.go | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/kernel/model/import.go b/kernel/model/import.go index 04116b306..ffb1d1e41 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -217,30 +217,32 @@ func ImportSY(zipPath, boxID, toPath string) (err error) { newPath := filepath.Join(filepath.Dir(path), newAvID+".json") renameAvPaths[path] = newPath avIDs[oldAvID] = newAvID - - // 将数据库文件中的块 ID 替换为新的块 ID - data, readErr := os.ReadFile(path) - if nil != readErr { - logging.LogErrorf("read av file [%s] failed: %s", path, readErr) - return nil - } - var newData []byte - newData = data - for oldID, newID := range avBlockIDs { - newData = bytes.ReplaceAll(newData, []byte(oldID), []byte(newID)) - } - newData = bytes.ReplaceAll(newData, []byte(oldAvID), []byte(newAvID)) - if !bytes.Equal(data, newData) { - if writeErr := os.WriteFile(path, newData, 0644); nil != writeErr { - logging.LogErrorf("write av file [%s] failed: %s", path, writeErr) - return nil - } - } return nil }) // 重命名数据库文件 for oldPath, newPath := range renameAvPaths { + data, readErr := os.ReadFile(oldPath) + if nil != readErr { + logging.LogErrorf("read av file [%s] failed: %s", oldPath, readErr) + return nil + } + + // 将数据库文件中的块 ID 替换为新的块 ID + newData := data + for oldAvID, newAvID := range avIDs { + for oldID, newID := range avBlockIDs { + newData = bytes.ReplaceAll(newData, []byte(oldID), []byte(newID)) + } + newData = bytes.ReplaceAll(newData, []byte(oldAvID), []byte(newAvID)) + } + if !bytes.Equal(data, newData) { + if writeErr := os.WriteFile(oldPath, newData, 0644); nil != writeErr { + logging.LogErrorf("write av file [%s] failed: %s", oldPath, writeErr) + return nil + } + } + if err = os.Rename(oldPath, newPath); nil != err { logging.LogErrorf("rename av file from [%s] to [%s] failed: %s", oldPath, newPath, err) return From 333cba07f4c214395cf8fcdf7131eeefcaf22537 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 00:46:00 +0800 Subject: [PATCH 2/2] :art: Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958 --- kernel/av/value.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/kernel/av/value.go b/kernel/av/value.go index 46ab870f9..64b724dff 100644 --- a/kernel/av/value.go +++ b/kernel/av/value.go @@ -597,5 +597,37 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { } } r.Contents = []string{strconv.FormatFloat(max-min, 'f', -1, 64)} + case CalcOperatorChecked: + countChecked := 0 + for _, v := range r.Contents { + if "√" == v { + countChecked++ + } + } + r.Contents = []string{strconv.Itoa(countChecked)} + case CalcOperatorUnchecked: + countUnchecked := 0 + for _, v := range r.Contents { + if "√" != v { + countUnchecked++ + } + } + r.Contents = []string{strconv.Itoa(countUnchecked)} + case CalcOperatorPercentChecked: + countChecked := 0 + for _, v := range r.Contents { + if "√" == v { + countChecked++ + } + } + r.Contents = []string{strconv.Itoa(countChecked*100/len(r.Contents)) + "%"} + case CalcOperatorPercentUnchecked: + countUnchecked := 0 + for _, v := range r.Contents { + if "√" != v { + countUnchecked++ + } + } + r.Contents = []string{strconv.Itoa(countUnchecked*100/len(r.Contents)) + "%"} } }