import TabAwareWidget from "./tab_aware_widget.js"; import treeService from "../services/tree.js"; import linkService from "../services/link.js"; import hoistedNoteService from "../services/hoisted_note.js"; const TPL = `
`; export default class NotePathsWidget extends TabAwareWidget { doRender() { this.$widget = $(TPL); this.overflowing(); this.$currentPath = this.$widget.find('.current-path'); this.$dropdown = this.$widget.find(".dropdown"); this.$notePathList = this.$dropdown.find(".note-path-list"); this.$dropdown.on('show.bs.dropdown', () => this.renderDropdown()); } async refreshWithNote(note) { const noteIdsPath = treeService.parseNotePath(this.notePath); this.$currentPath.empty(); let parentNoteId = 'root'; let curPath = ''; let passedHoistedNote = false; for (let i = 0; i < noteIdsPath.length; i++) { const noteId = noteIdsPath[i]; curPath += (curPath ? '/' : '') + noteId; if (noteId === hoistedNoteService.getHoistedNoteId()) { passedHoistedNote = true; } if (passedHoistedNote && (noteId !== hoistedNoteService.getHoistedNoteId() || noteIdsPath.length - i < 3)) { this.$currentPath.append( $("") .attr('href', '#' + curPath) .attr('data-note-path', curPath) .addClass('no-tooltip-preview') .text(await treeService.getNoteTitle(noteId, parentNoteId)) ); if (i !== noteIdsPath.length - 1) { this.$currentPath.append(' / '); } } parentNoteId = noteId; } } async renderDropdown() { this.$notePathList.empty(); this.$notePathList.append( $("
") .addClass("dropdown-header") .text('This note is placed into the following paths:') ); if (this.noteId === 'root') { await this.addPath('root', true); return; } const pathSegments = treeService.parseNotePath(this.notePath); const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent for (const parentNote of this.note.getParentNotes()) { const parentNotePath = treeService.getSomeNotePath(parentNote); // this is to avoid having root notes leading '/' const notePath = parentNotePath ? (parentNotePath + '/' + this.noteId) : this.noteId; const isCurrent = activeNoteParentNoteId === parentNote.noteId; await this.addPath(notePath, isCurrent); } const cloneLink = $("
") .addClass("dropdown-header") .append( $('