import NoteContextAwareWidget from "../note_context_aware_widget.js"; import server from "../../services/server.js"; const TPL = `
`; export default class NoteInfoWidget extends NoteContextAwareWidget { get name() { return "noteInfo"; } get toggleCommand() { return "toggleRibbonTabNoteInfo"; } isEnabled() { return this.note; } getTitle() { return { show: this.isEnabled(), title: 'Note Info', icon: 'bx bx-info-circle' }; } doRender() { this.$widget = $(TPL); this.contentSized(); this.$noteId = this.$widget.find(".note-info-note-id"); this.$dateCreated = this.$widget.find(".note-info-date-created"); this.$dateModified = this.$widget.find(".note-info-date-modified"); this.$type = this.$widget.find(".note-info-type"); this.$mime = this.$widget.find(".note-info-mime"); this.$noteSizesWrapper = this.$widget.find('.note-sizes-wrapper'); this.$noteSize = this.$widget.find(".note-size"); this.$subTreeSize = this.$widget.find(".subtree-size"); this.$calculateButton = this.$widget.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 subTreeResp = await server.get(`stats/subtree-size/${this.noteId}`); if (subTreeResp.subTreeNoteCount > 1) { this.$subTreeSize.text(`(subtree size: ${this.formatSize(subTreeResp.subTreeSize)} in ${subTreeResp.subTreeNoteCount} notes)`); } else { this.$subTreeSize.text(""); } }); } async refreshWithNote(note) { const noteComplement = await this.noteContext.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(); } } }