Skip to content

Commit

Permalink
🎨 Add statistics on selected blocks and total blocks #13235
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 23, 2024
1 parent adb942b commit 14bb850
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/appearance/langs/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"linkCount": "Links",
"imgCount": "Bilder",
"refCount": "Referenzen",
"blockCount": "Blöcke",
"kbd": "Tastatur",
"errorStyle": "Fehlerstil",
"successStyle": "Erfolg-Stil",
Expand Down
1 change: 1 addition & 0 deletions app/appearance/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"linkCount": "Links",
"imgCount": "Images",
"refCount": "Refs",
"blockCount": "Blocks",
"kbd": "Keyboard",
"errorStyle": "Error Style",
"successStyle": "Success Style",
Expand Down
1 change: 1 addition & 0 deletions app/appearance/langs/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"linkCount": "Enlaces",
"imgCount": "Imágenes",
"refCount": "Referencias",
"blockCount": "Bloques",
"kbd": "Teclado",
"errorStyle": "Estilo de error",
"successStyle": "Estilo de éxito",
Expand Down
1 change: 1 addition & 0 deletions app/appearance/langs/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"linkCount": "Liens",
"imgCount": "Images",
"refCount": "Réfs",
"blockCount": "Blocs",
"kbd": "Clavier",
"errorStyle": "Style d'Erreur",
"successStyle": "Style de Réussite",
Expand Down
1 change: 1 addition & 0 deletions app/appearance/langs/he_IL.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"linkCount": "קישורים",
"imgCount": "תמונות",
"refCount": "יחוסים",
"blockCount": "בלוקים",
"kbd": "מקלדת",
"errorStyle": "סגנון שגיאה",
"successStyle": "סגנון הצלחה",
Expand Down
1 change: 1 addition & 0 deletions app/appearance/langs/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"linkCount": "Link",
"imgCount": "Immagini",
"refCount": "Riferimenti",
"blockCount": "Blocchi",
"kbd": "Tastiera",
"errorStyle": "Stile Errore",
"successStyle": "Stile Successo",
Expand Down
1 change: 1 addition & 0 deletions app/appearance/langs/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"linkCount": "リンク数",
"imgCount": "画像数",
"refCount": "参照数",
"blockCount": "ブロック",
"kbd": "キーボード",
"errorStyle": "エラースタイル",
"successStyle": "成功スタイル",
Expand Down
1 change: 1 addition & 0 deletions app/appearance/langs/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"linkCount": "Linki",
"imgCount": "Obrazy",
"refCount": "Refs",
"blockCount": "bloki",
"kbd": "Klawiatura",
"errorStyle": "Styl błędu",
"successStyle": "Styl sukcesu",
Expand Down
1 change: 1 addition & 0 deletions app/appearance/langs/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"linkCount": "Ссылки",
"imgCount": "Изображения",
"refCount": "Ссылки",
"blockCount": "блоки",
"kbd": "Клавиатура",
"errorStyle": "Стиль ошибки",
"successStyle": "Стиль успеха",
Expand Down
5 changes: 3 additions & 2 deletions app/appearance/langs/zh_CHT.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,12 @@
"vLayout": "垂直佈局",
"hLayout": "水平佈局",
"merge": "合併",
"wordCount": "字數",
"runeCount": "字符數",
"wordCount": "",
"runeCount": "字符",
"linkCount": "連結",
"imgCount": "圖片",
"refCount": "引用",
"blockCount": "",
"kbd": "鍵盤",
"errorStyle": "錯誤樣式",
"successStyle": "成功樣式",
Expand Down
5 changes: 3 additions & 2 deletions app/appearance/langs/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,12 @@
"vLayout": "垂直布局",
"hLayout": "水平布局",
"merge": "合并",
"wordCount": "字数",
"runeCount": "字符数",
"wordCount": "",
"runeCount": "字符",
"linkCount": "链接",
"imgCount": "图片",
"refCount": "引用",
"blockCount": "",
"kbd": "键盘",
"errorStyle": "错误样式",
"successStyle": "成功样式",
Expand Down
5 changes: 4 additions & 1 deletion app/src/layout/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ export const renderStatusbarCounter = (stat: {
wordCount: number,
linkCount: number,
imageCount: number,
refCount: number
refCount: number,
blockCount: number,
}) => {
if (!stat) {
return;
Expand All @@ -209,6 +210,8 @@ export const renderStatusbarCounter = (stat: {
}
if (0 < stat.refCount) {
html += `<span class="ft__on-surface">${window.siyuan.languages.refCount}</span>&nbsp;${stat.refCount}<span class="fn__space"></span>`;
}if (0 < stat.blockCount) {
html += `<span class="ft__on-surface">${window.siyuan.languages.blockCount}</span>&nbsp;${stat.blockCount}<span class="fn__space"></span>`;
}
document.querySelector("#status .status__counter").innerHTML = html;
};
2 changes: 1 addition & 1 deletion app/src/protyle/breadcrumb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ ${padHTML}
iconHTML: "",
type: "readonly",
// 不能换行,否则移动端间距过大
label: `<div class="fn__flex">${window.siyuan.languages.runeCount}<span class="fn__space fn__flex-1"></span>${response.data.runeCount}</div><div class="fn__flex">${window.siyuan.languages.wordCount}<span class="fn__space fn__flex-1"></span>${response.data.wordCount}</div><div class="fn__flex">${window.siyuan.languages.linkCount}<span class="fn__space fn__flex-1"></span>${response.data.linkCount}</div><div class="fn__flex">${window.siyuan.languages.imgCount}<span class="fn__space fn__flex-1"></span>${response.data.imageCount}</div><div class="fn__flex">${window.siyuan.languages.refCount}<span class="fn__space fn__flex-1"></span>${response.data.refCount}</div>`,
label: `<div class="fn__flex">${window.siyuan.languages.runeCount}<span class="fn__space fn__flex-1"></span>${response.data.runeCount}</div><div class="fn__flex">${window.siyuan.languages.wordCount}<span class="fn__space fn__flex-1"></span>${response.data.wordCount}</div><div class="fn__flex">${window.siyuan.languages.linkCount}<span class="fn__space fn__flex-1"></span>${response.data.linkCount}</div><div class="fn__flex">${window.siyuan.languages.imgCount}<span class="fn__space fn__flex-1"></span>${response.data.imageCount}</div><div class="fn__flex">${window.siyuan.languages.refCount}<span class="fn__space fn__flex-1"></span>${response.data.refCount}</div><div class="fn__flex">${window.siyuan.languages.blockCount}<span class="fn__space fn__flex-1"></span>${response.data.blockCount}</div>`,
}).element);
/// #if MOBILE
window.siyuan.menus.menu.fullscreen();
Expand Down
13 changes: 12 additions & 1 deletion kernel/model/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ func BlocksWordCount(ids []string) (ret *util.BlockStatResult) {
ret.ImageCount += imgCnt
ret.RefCount += refCnt
}
ret.BlockCount = len(ids)
return
}

Expand All @@ -491,9 +492,18 @@ func StatTree(id string) (ret *util.BlockStatResult) {
return
}

blockCount := 0
var databaseBlockNodes []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || ast.NodeAttributeView != n.Type {
if !entering {
return ast.WalkContinue
}

if n.IsBlock() {
blockCount++
}

if ast.NodeAttributeView != n.Type {
return ast.WalkContinue
}

Expand Down Expand Up @@ -585,6 +595,7 @@ func StatTree(id string) (ret *util.BlockStatResult) {
LinkCount: linkCnt,
ImageCount: imgCnt,
RefCount: refCnt,
BlockCount: blockCount,
}
}

Expand Down
1 change: 1 addition & 0 deletions kernel/util/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ type BlockStatResult struct {
LinkCount int `json:"linkCount"`
ImageCount int `json:"imageCount"`
RefCount int `json:"refCount"`
BlockCount int `json:"blockCount"`
}

func ContextPushMsg(context map[string]interface{}, msg string) {
Expand Down

0 comments on commit 14bb850

Please sign in to comment.