🎨 显示本地数据快照文件类型计数 Fix https://github.com/siyuan-note/siyuan/issues/6870

This commit is contained in:
Liang Ding 2022-12-14 15:39:05 +08:00
parent 26a11dc3d0
commit e73f38390b
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 49 additions and 42 deletions

View file

@ -110,11 +110,16 @@ const renderRepoItem = (response: IWebSocketData, element: Element, type: string
<div> <div>
<span class="ft__smaller ft__on-surface">${item.hCreated}</span> <span class="ft__smaller ft__on-surface">${item.hCreated}</span>
<span class="b3-list-item__meta">${window.siyuan.languages.fileSize} ${item.hSize}</span> <span class="b3-list-item__meta">${window.siyuan.languages.fileSize} ${item.hSize}</span>
<span class="b3-list-item__meta">${window.siyuan.languages.fileCount} ${item.count}</span> <span class="b3-list-item__meta">${window.siyuan.languages.fileCount} ${item.count}</span>`
let statHTML = "";
if (item.typesCount && 0 < item.typesCount.length) {
statHTML += `
<span class="b3-list-item__meta"> <span class="b3-list-item__meta">
${item.typesCount.map((type: { type: string, count: number }) => { ${item.typesCount.map((type: { type: string, count: number }) => {
return `${type.type} ${type.count}`; return `${type.type} ${type.count}`;
}).join(" ")} }).join("&nbsp;&nbsp;")}`
}
repoHTML += `${statHTML}
</span> </span>
</div> </div>
</div> </div>

View file

@ -38,7 +38,7 @@ require (
github.com/panjf2000/ants/v2 v2.7.0 github.com/panjf2000/ants/v2 v2.7.0
github.com/patrickmn/go-cache v2.1.0+incompatible github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/radovskyb/watcher v1.0.7 github.com/radovskyb/watcher v1.0.7
github.com/siyuan-note/dejavu v0.0.0-20221214062838-c08423e72b57 github.com/siyuan-note/dejavu v0.0.0-20221214071109-67333a5acbcb
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da
github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e

View file

@ -361,12 +361,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
github.com/siyuan-note/dejavu v0.0.0-20221214060041-f7b64a7eb12a h1:9sAurbeois47ROtvJ9EcQFWfJIdL7C6fPZm29PhTBXg= github.com/siyuan-note/dejavu v0.0.0-20221214071109-67333a5acbcb h1:fS8iB5d7x57eyfvNjqlDOTL9XglVCSBtGoa5e3nQTkY=
github.com/siyuan-note/dejavu v0.0.0-20221214060041-f7b64a7eb12a/go.mod h1:aarwJw3uJaqNoIGVLmyhZjMCjI+xAzwrMIg05scqmtc= github.com/siyuan-note/dejavu v0.0.0-20221214071109-67333a5acbcb/go.mod h1:aarwJw3uJaqNoIGVLmyhZjMCjI+xAzwrMIg05scqmtc=
github.com/siyuan-note/dejavu v0.0.0-20221214062510-12058008827b h1:ACydDbRC5n76G843HaW+mx86hm3CZya/VUZlB0dtFnU=
github.com/siyuan-note/dejavu v0.0.0-20221214062510-12058008827b/go.mod h1:aarwJw3uJaqNoIGVLmyhZjMCjI+xAzwrMIg05scqmtc=
github.com/siyuan-note/dejavu v0.0.0-20221214062838-c08423e72b57 h1:luEVy9oqVB8yAlxVdwIMFoI53mVvSRG3N1rJ/+U6p3I=
github.com/siyuan-note/dejavu v0.0.0-20221214062838-c08423e72b57/go.mod h1:aarwJw3uJaqNoIGVLmyhZjMCjI+xAzwrMIg05scqmtc=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90= github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=

View file

@ -88,7 +88,11 @@ func GetRepoSnapshots(page int) (ret []*Snapshot, pageCount, totalCount int, err
return return
} }
// 数据快照 - 本地快照显示文件类型 https://github.com/siyuan-note/siyuan/issues/6870 ret = buildSnapshots(logs)
return
}
func buildSnapshots(logs []*dejavu.Log) (ret []*Snapshot) {
for _, l := range logs { for _, l := range logs {
typesCount := statTypesByPath(l.Files) typesCount := statTypesByPath(l.Files)
ret = append(ret, &Snapshot{ ret = append(ret, &Snapshot{
@ -100,36 +104,34 @@ func GetRepoSnapshots(page int) (ret []*Snapshot, pageCount, totalCount int, err
} }
func statTypesByPath(files []*entity.File) (ret []*TypeCount) { func statTypesByPath(files []*entity.File) (ret []*TypeCount) {
m := map[string]int{}
for _, f := range files { for _, f := range files {
ext := path.Ext(f.Path) ext := path.Ext(f.Path)
m[ext]++
}
var stated []string found := false
for ext, count := range m { for _, tc := range ret {
ret = append(ret, &TypeCount{ if tc.Type == ext {
Type: ext, tc.Count++
Count: count, found = true
})
stated = append(stated, ext)
if 10 < len(ret) {
break break
} }
} }
if !found {
ret = append(ret, &TypeCount{Type: ext, Count: 1})
}
}
sort.Slice(ret, func(i, j int) bool { return ret[i].Count > ret[j].Count }) sort.Slice(ret, func(i, j int) bool { return ret[i].Count > ret[j].Count })
for _, s := range stated { if 10 < len(ret) {
delete(m, s)
}
otherCount := 0 otherCount := 0
for _, count := range m { for _, tc := range ret[10:] {
otherCount += count tc.Count += otherCount
} }
ret = append(ret, &TypeCount{ other := &TypeCount{
Type: "Other", Type: "Other",
Count: otherCount, Count: otherCount,
}) }
ret = append(ret[:10], other)
}
return return
} }
@ -388,6 +390,7 @@ func RemoveCloudRepoTag(tag string) (err error) {
} }
func GetCloudRepoTagSnapshots() (ret []*dejavu.Log, err error) { func GetCloudRepoTagSnapshots() (ret []*dejavu.Log, err error) {
ret = []*dejavu.Log{}
if 1 > len(Conf.Repo.Key) { if 1 > len(Conf.Repo.Key) {
err = errors.New(Conf.Language(26)) err = errors.New(Conf.Language(26))
return return
@ -398,14 +401,16 @@ func GetCloudRepoTagSnapshots() (ret []*dejavu.Log, err error) {
return return
} }
ret, err = repo.GetCloudRepoTagLogs(map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}) logs, err := repo.GetCloudRepoTagLogs(map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar})
if 1 > len(ret) { if nil != err {
ret = []*dejavu.Log{} return
} }
ret = logs
return return
} }
func GetTagSnapshots() (ret []*dejavu.Log, err error) { func GetTagSnapshots() (ret []*Snapshot, err error) {
ret = []*Snapshot{}
if 1 > len(Conf.Repo.Key) { if 1 > len(Conf.Repo.Key) {
err = errors.New(Conf.Language(26)) err = errors.New(Conf.Language(26))
return return
@ -416,10 +421,11 @@ func GetTagSnapshots() (ret []*dejavu.Log, err error) {
return return
} }
ret, err = repo.GetTagLogs() logs, err := repo.GetTagLogs()
if 1 > len(ret) { if nil != err {
ret = []*dejavu.Log{} return
} }
ret = buildSnapshots(logs)
return return
} }