import CollapsibleWidget from "../collapsible_widget.js"; import server from "../../services/server.js"; const TPL = `
Note ID: Type:
Created: Modified:
Note size: (subtree size: )
`; export default class NoteInfoWidget extends CollapsibleWidget { isEnabled() { return super.isEnabled() && !this.note.hasLabel('noteInfoWidgetDisabled'); } get widgetTitle() { return "Note info"; } async doRenderBody() { this.$body.html(TPL); this.$noteId = this.$body.find(".note-info-note-id"); this.$dateCreated = this.$body.find(".note-info-date-created"); 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($('')); this.$subTreeSize.empty().append($('')); 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) { const noteComplement = await this.tabContext.getNoteComplement(); this.$noteId.text(note.noteId); this.$dateCreated .text(noteComplement.dateCreated.substr(0, 16)) .attr("title", noteComplement.dateCreated); this.$dateModified .text(noteComplement.combinedDateModified.substr(0, 16)) .attr("title", noteComplement.combinedDateModified); this.$type.text(note.type); if (note.mime) { this.$mime.text('(' + note.mime + ')'); } else { this.$mime.empty(); } this.$calculateButton.show(); this.$noteSizesWrapper.hide(); } formatSize(size) { size = Math.max(Math.round(size / 1024), 1); if (size < 1024) { return `${size} KiB`; } else { return `${Math.round(size / 102.4) / 10} MiB`; } } entitiesReloadedEvent({loadResults}) { if (loadResults.isNoteReloaded(this.noteId) || loadResults.isNoteContentReloaded(this.noteId)) { this.refresh(); } } }