2020-01-18 19:46:30 +01:00
|
|
|
import TabAwareWidget from "./tab_aware_widget.js";
|
|
|
|
import treeService from "../services/tree.js";
|
|
|
|
import linkService from "../services/link.js";
|
|
|
|
|
|
|
|
const TPL = `
|
2021-02-13 22:47:06 +01:00
|
|
|
<div class="dropdown note-paths-widget">
|
2020-01-18 19:46:30 +01:00
|
|
|
<style>
|
2020-04-07 22:53:03 +02:00
|
|
|
.note-path-list-button {
|
2021-02-13 22:47:06 +01:00
|
|
|
font-size: 120% !important;
|
2020-04-07 22:53:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.note-path-list-button::after {
|
|
|
|
display: none !important; // disabling the standard caret
|
|
|
|
}
|
|
|
|
|
2020-09-15 22:46:51 +02:00
|
|
|
.note-path-list {
|
2021-03-08 22:04:52 +01:00
|
|
|
max-height: 700px;
|
2020-09-15 22:46:51 +02:00
|
|
|
overflow-y: auto;
|
|
|
|
}
|
2021-03-08 00:07:00 +01:00
|
|
|
|
2021-03-08 22:04:52 +01:00
|
|
|
.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;
|
2021-03-08 00:07:00 +01:00
|
|
|
}
|
2020-01-18 19:46:30 +01:00
|
|
|
</style>
|
2021-02-13 22:47:06 +01:00
|
|
|
|
|
|
|
<button class="btn dropdown-toggle note-path-list-button bx bx-collection" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Note paths"></button>
|
|
|
|
<ul class="note-path-list dropdown-menu dropdown-menu-right" aria-labelledby="note-path-list-button">
|
|
|
|
</ul>
|
2020-01-18 19:46:30 +01:00
|
|
|
</div>`;
|
|
|
|
|
|
|
|
export default class NotePathsWidget extends TabAwareWidget {
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
2020-08-26 16:50:16 +02:00
|
|
|
this.overflowing();
|
2020-01-18 19:46:30 +01:00
|
|
|
|
2021-02-13 22:47:06 +01:00
|
|
|
this.$notePathList = this.$widget.find(".note-path-list");
|
|
|
|
this.$widget.on('show.bs.dropdown', () => this.renderDropdown());
|
2020-02-03 21:16:33 +01:00
|
|
|
}
|
2020-01-18 19:46:30 +01:00
|
|
|
|
2020-02-03 21:16:33 +01:00
|
|
|
async renderDropdown() {
|
|
|
|
this.$notePathList.empty();
|
2020-04-08 10:13:11 +02:00
|
|
|
this.$notePathList.append(
|
|
|
|
$("<div>")
|
|
|
|
.addClass("dropdown-header")
|
|
|
|
.text('This note is placed into the following paths:')
|
|
|
|
);
|
2020-01-18 19:46:30 +01:00
|
|
|
|
2020-02-03 21:16:33 +01:00
|
|
|
if (this.noteId === 'root') {
|
2021-03-08 22:04:52 +01:00
|
|
|
await this.addPath('root');
|
2020-02-03 21:16:33 +01:00
|
|
|
return;
|
2020-01-18 19:46:30 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:04:52 +01:00
|
|
|
for (const notePathRecord of this.note.getSortedNotePaths(this.hoistedNoteId)) {
|
|
|
|
await this.addPath(notePathRecord);
|
2020-02-03 21:16:33 +01:00
|
|
|
}
|
2020-01-18 19:46:30 +01:00
|
|
|
|
2020-02-03 21:16:33 +01:00
|
|
|
const cloneLink = $("<div>")
|
2020-04-08 10:13:11 +02:00
|
|
|
.addClass("dropdown-header")
|
2020-02-03 21:16:33 +01:00
|
|
|
.append(
|
|
|
|
$('<button class="btn btn-sm">')
|
|
|
|
.text('Clone note to new location...')
|
|
|
|
.on('click', () => import("../dialogs/clone_to.js").then(d => d.showDialog([this.noteId])))
|
|
|
|
);
|
2020-01-18 19:46:30 +01:00
|
|
|
|
2020-02-03 21:16:33 +01:00
|
|
|
this.$notePathList.append(cloneLink);
|
2020-01-18 19:46:30 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:04:52 +01:00
|
|
|
async addPath(notePathRecord) {
|
|
|
|
const notePath = notePathRecord.notePath.join('/');
|
|
|
|
|
2020-01-25 09:56:08 +01:00
|
|
|
const title = await treeService.getNotePathTitle(notePath);
|
2020-01-18 19:46:30 +01:00
|
|
|
|
2021-01-27 20:44:58 +01:00
|
|
|
const $noteLink = await linkService.createNoteLink(notePath, {title});
|
2020-01-18 19:46:30 +01:00
|
|
|
|
2021-01-27 20:44:58 +01:00
|
|
|
$noteLink
|
2020-01-18 19:46:30 +01:00
|
|
|
.addClass("dropdown-item");
|
|
|
|
|
2021-01-27 20:44:58 +01:00
|
|
|
$noteLink
|
2020-02-03 21:16:33 +01:00
|
|
|
.find('a')
|
|
|
|
.addClass("no-tooltip-preview");
|
|
|
|
|
2021-03-10 23:11:48 +01:00
|
|
|
const icons = [];
|
2021-03-08 22:04:52 +01:00
|
|
|
|
|
|
|
if (this.notePath === notePath) {
|
|
|
|
$noteLink.addClass("path-current");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notePathRecord.isInHoistedSubTree) {
|
|
|
|
$noteLink.addClass("path-in-hoisted-subtree");
|
|
|
|
}
|
|
|
|
else {
|
2021-03-10 23:11:48 +01:00
|
|
|
icons.push(`<span class="bx bx-trending-up" title="This path is outside of hoisted note and you would have to unhoist."></span>`);
|
2021-03-08 22:04:52 +01:00
|
|
|
}
|
|
|
|
|
2021-05-18 20:56:49 +02:00
|
|
|
if (notePathRecord.isArchived) {
|
2021-03-08 22:04:52 +01:00
|
|
|
$noteLink.addClass("path-archived");
|
|
|
|
|
2021-03-10 23:11:48 +01:00
|
|
|
icons.push(`<span class="bx bx-archive" title="Archived"></span>`);
|
2021-03-08 22:04:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (notePathRecord.isSearch) {
|
|
|
|
$noteLink.addClass("path-search");
|
|
|
|
|
2021-03-10 23:11:48 +01:00
|
|
|
icons.push(`<span class="bx bx-search" title="Search"></span>`);
|
2021-03-08 22:04:52 +01:00
|
|
|
}
|
|
|
|
|
2021-03-10 23:11:48 +01:00
|
|
|
if (icons.length > 0) {
|
|
|
|
$noteLink.append(` ${icons.join(' ')}`);
|
2020-01-18 19:46:30 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 20:44:58 +01:00
|
|
|
this.$notePathList.append($noteLink);
|
2020-01-18 19:46:30 +01:00
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
}
|
2021-03-08 00:04:43 +01:00
|
|
|
|
|
|
|
async refresh() {
|
|
|
|
await super.refresh();
|
|
|
|
|
|
|
|
this.$widget.find('.dropdown-toggle').dropdown('hide');
|
|
|
|
}
|
2020-05-09 14:25:27 +02:00
|
|
|
}
|