142 lines
3.7 KiB
JavaScript
Raw Normal View History

2021-05-29 13:06:09 +02:00
import NoteContextAwareWidget from "../note_context_aware_widget.js";
import treeService from "../../services/tree.js";
import linkService from "../../services/link.js";
const TPL = `
2021-05-29 13:06:09 +02:00
<div class="note-paths-widget">
<style>
2021-05-29 13:06:09 +02:00
.note-paths-widget {
padding: 12px;
max-height: 300px;
overflow-y: auto;
}
.note-path-list {
2021-05-29 13:06:09 +02:00
margin-top: 10px;
}
.note-path-list .path-current {
font-weight: bold;
}
.note-path-list .path-archived {
color: var(--muted-text-color) !important;
}
.note-path-list .path-search {
font-style: italic;
}
</style>
<div class="note-path-intro"></div>
2021-05-29 13:06:09 +02:00
<ul class="note-path-list"></ul>
<button class="btn btn-sm" data-trigger-command="cloneNoteIdsTo">Clone note to new location...</button>
</div>`;
2021-05-22 12:35:41 +02:00
export default class NotePathsWidget extends NoteContextAwareWidget {
2021-06-27 12:53:05 +02:00
get name() {
return "notePaths";
}
get toggleCommand() {
return "toggleRibbonTabNotePaths";
}
2021-05-29 13:06:09 +02:00
isEnabled() {
return this.note;
}
getTitle() {
return {
2021-05-29 13:24:14 +02:00
show: true,
2021-05-29 13:06:09 +02:00
title: 'Note Paths',
icon: 'bx bx-collection'
};
}
doRender() {
this.$widget = $(TPL);
2021-06-13 22:55:31 +02:00
this.contentSized();
this.$notePathIntro = this.$widget.find(".note-path-intro");
this.$notePathList = this.$widget.find(".note-path-list");
this.$widget.on('show.bs.dropdown', () => this.renderDropdown());
}
2021-05-29 13:06:09 +02:00
async refreshWithNote(note) {
this.$notePathList.empty();
if (this.noteId === 'root') {
await this.addPath('root');
return;
}
const sortedNotePaths = this.note.getSortedNotePaths(this.hoistedNoteId)
.filter(notePath => !notePath.isHidden);
if (sortedNotePaths.length > 0) {
this.$notePathIntro.text("This note is placed into the following paths:");
}
else {
this.$notePathIntro.text("This note is not yet placed into the note tree.");
}
for (const notePathRecord of sortedNotePaths) {
await this.addPath(notePathRecord);
}
}
async addPath(notePathRecord) {
const notePath = notePathRecord.notePath.join('/');
2020-01-25 09:56:08 +01:00
const title = await treeService.getNotePathTitle(notePath);
const $noteLink = await linkService.createNoteLink(notePath, {title});
$noteLink
.find('a')
.addClass("no-tooltip-preview");
const icons = [];
if (this.notePath === notePath) {
$noteLink.addClass("path-current");
}
if (notePathRecord.isInHoistedSubTree) {
$noteLink.addClass("path-in-hoisted-subtree");
}
else {
icons.push(`<span class="bx bx-trending-up" title="This path is outside of hoisted note and you would have to unhoist."></span>`);
}
if (notePathRecord.isArchived) {
$noteLink.addClass("path-archived");
icons.push(`<span class="bx bx-archive" title="Archived"></span>`);
}
if (notePathRecord.isSearch) {
$noteLink.addClass("path-search");
icons.push(`<span class="bx bx-search" title="Search"></span>`);
}
if (icons.length > 0) {
$noteLink.append(` ${icons.join(' ')}`);
}
2021-05-29 13:06:09 +02:00
this.$notePathList.append($("<li>").append($noteLink));
}
2020-02-17 22:47:50 +01:00
entitiesReloadedEvent({loadResults}) {
2020-10-21 22:45:49 +02:00
if (loadResults.getBranches().find(branch => branch.noteId === this.noteId)
|| loadResults.isNoteReloaded(this.noteId)) {
2020-02-17 22:47:50 +01:00
this.refresh();
}
}
}