1
1
Fork 0
mirror of https://github.com/zadam/trilium.git synced 2025-01-24 16:10:48 +08:00

size calculation is always on demand

This commit is contained in:
zadam 2021-01-22 15:16:08 +01:00
parent 35ea877c7d
commit 480aec1667
3 changed files with 31 additions and 17 deletions
package-lock.jsonpackage.json
src/public/app/widgets/collapsible_widgets

6
package-lock.json generated
View file

@ -2360,9 +2360,9 @@
}
},
"dayjs": {
"version": "1.10.3",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.3.tgz",
"integrity": "sha512-/2fdLN987N8Ki7Id8BUN2nhuiRyxTLumQnSQf9CNncFCyqFsSKb9TNhzRYcC8K8eJSJOKvbvkImo/MKKhNi4iw=="
"version": "1.10.4",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.4.tgz",
"integrity": "sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw=="
},
"debug": {
"version": "4.1.1",

View file

@ -32,7 +32,7 @@
"commonmark": "0.29.3",
"cookie-parser": "1.4.5",
"csurf": "1.11.0",
"dayjs": "1.10.3",
"dayjs": "1.10.4",
"ejs": "3.1.5",
"electron-debug": "3.2.0",
"electron-dl": "3.0.2",

View file

@ -43,9 +43,15 @@ const TPL = `
<th>Note size:</th>
<td colspan="3">
<span class="note-size"></span>
<button class="btn btn-sm calculate-button" style="padding: 0px 10px 0px 10px;">
<span class="bx bx-calculator"></span> calculate
</button>
(subtree size: <span class="subtree-size"></span>)
<span class="note-sizes-wrapper">
<span class="note-size"></span>
(subtree size: <span class="subtree-size"></span>)
</span>
</td>
</tr>
</table>
@ -66,8 +72,25 @@ export default class NoteInfoWidget extends CollapsibleWidget {
this.$dateModified = this.$body.find(".note-info-date-modified");
this.$type = this.$body.find(".note-info-type");
this.$mime = this.$body.find(".note-info-mime");
this.$noteSizesWrapper = this.$body.find('.note-sizes-wrapper');
this.$noteSize = this.$body.find(".note-size");
this.$subTreeSize = this.$body.find(".subtree-size");
this.$calculateButton = this.$body.find(".calculate-button");
this.$calculateButton.on('click', async () => {
this.$noteSizesWrapper.show();
this.$calculateButton.hide();
this.$noteSize.empty().append($('<span class="bx bx-loader bx-spin"></span>'));
this.$subTreeSize.empty().append($('<span class="bx bx-loader bx-spin"></span>'));
const noteSizeResp = await server.get(`stats/note-size/${this.noteId}`);
this.$noteSize.text(this.formatSize(noteSizeResp.noteSize));
const subTreeSizeResp = await server.get(`stats/subtree-size/${this.noteId}`);
this.$subTreeSize.text(this.formatSize(subTreeSizeResp.subTreeSize));
});
}
async refreshWithNote(note) {
@ -91,17 +114,8 @@ export default class NoteInfoWidget extends CollapsibleWidget {
this.$mime.empty();
}
const resp = await server.get(`stats/note-size/${note.noteId}`);
this.$noteSize.text(this.formatSize(resp.noteSize));
const $calculateLink = $('<a href="javascript:">calculate</a>')
.on('click', async () => {
const resp = await server.get(`stats/subtree-size/${note.noteId}`);
this.$subTreeSize.text(this.formatSize(resp.subTreeSize));
})
this.$subTreeSize.empty().append($calculateLink);
this.$calculateButton.show();
this.$noteSizesWrapper.hide();
}
formatSize(size) {