mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-12 20:02:28 +08:00
refactor(client/ts): port a few small files
This commit is contained in:
parent
44811f4f4b
commit
11e2dcfc64
@ -113,6 +113,8 @@ export type CommandMappings = {
|
|||||||
openNoteInNewWindow: CommandData;
|
openNoteInNewWindow: CommandData;
|
||||||
hideLeftPane: CommandData;
|
hideLeftPane: CommandData;
|
||||||
showLeftPane: CommandData;
|
showLeftPane: CommandData;
|
||||||
|
leaveProtectedSession: CommandData;
|
||||||
|
enterProtectedSession: CommandData;
|
||||||
|
|
||||||
openInTab: ContextMenuCommandData;
|
openInTab: ContextMenuCommandData;
|
||||||
openNoteInSplit: ContextMenuCommandData;
|
openNoteInSplit: ContextMenuCommandData;
|
||||||
@ -214,6 +216,9 @@ export type CommandMappings = {
|
|||||||
scrollContainerToCommand: CommandData & {
|
scrollContainerToCommand: CommandData & {
|
||||||
position: number;
|
position: number;
|
||||||
};
|
};
|
||||||
|
moveThisNoteSplit: CommandData & {
|
||||||
|
isMovingLeft: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
// Geomap
|
// Geomap
|
||||||
deleteFromMap: { noteId: string },
|
deleteFromMap: { noteId: string },
|
||||||
@ -295,6 +300,7 @@ type EventMappings = {
|
|||||||
noteContextReorderEvent: {
|
noteContextReorderEvent: {
|
||||||
oldMainNtxId: string;
|
oldMainNtxId: string;
|
||||||
newMainNtxId: string;
|
newMainNtxId: string;
|
||||||
|
ntxIdsInOrder: string[];
|
||||||
};
|
};
|
||||||
newNoteContextCreated: {
|
newNoteContextCreated: {
|
||||||
noteContext: NoteContext;
|
noteContext: NoteContext;
|
||||||
@ -303,7 +309,7 @@ type EventMappings = {
|
|||||||
ntxIds: string[];
|
ntxIds: string[];
|
||||||
};
|
};
|
||||||
exportSvg: {
|
exportSvg: {
|
||||||
ntxId: string;
|
ntxId: string | null | undefined;
|
||||||
};
|
};
|
||||||
geoMapCreateChildNote: {
|
geoMapCreateChildNote: {
|
||||||
ntxId: string | null | undefined; // TODO: deduplicate ntxId
|
ntxId: string | null | undefined; // TODO: deduplicate ntxId
|
||||||
|
@ -2,13 +2,23 @@ import SwitchWidget from "./switch.js";
|
|||||||
import server from "../services/server.js";
|
import server from "../services/server.js";
|
||||||
import toastService from "../services/toast.js";
|
import toastService from "../services/toast.js";
|
||||||
import { t } from "../services/i18n.js";
|
import { t } from "../services/i18n.js";
|
||||||
|
import type FNote from "../entities/fnote.js";
|
||||||
|
import type { EventData } from "../components/app_context.js";
|
||||||
|
|
||||||
|
// TODO: Deduplicate
|
||||||
|
type Response = {
|
||||||
|
success: true;
|
||||||
|
} | {
|
||||||
|
success: false;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default class BookmarkSwitchWidget extends SwitchWidget {
|
export default class BookmarkSwitchWidget extends SwitchWidget {
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
return (
|
return (
|
||||||
super.isEnabled() &&
|
super.isEnabled() &&
|
||||||
// it's not possible to bookmark root because that would clone it under bookmarks and thus create a cycle
|
// it's not possible to bookmark root because that would clone it under bookmarks and thus create a cycle
|
||||||
!["root", "_hidden"].includes(this.noteId)
|
!["root", "_hidden"].includes(this.noteId ?? "")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,21 +32,21 @@ export default class BookmarkSwitchWidget extends SwitchWidget {
|
|||||||
this.switchOffTooltip = t("bookmark_switch.remove_bookmark");
|
this.switchOffTooltip = t("bookmark_switch.remove_bookmark");
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggle(state) {
|
async toggle(state: boolean | null | undefined) {
|
||||||
const resp = await server.put(`notes/${this.noteId}/toggle-in-parent/_lbBookmarks/${!!state}`);
|
const resp = await server.put<Response>(`notes/${this.noteId}/toggle-in-parent/_lbBookmarks/${!!state}`);
|
||||||
|
|
||||||
if (!resp.success) {
|
if (!resp.success) {
|
||||||
toastService.showError(resp.message);
|
toastService.showError(resp.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note: FNote) {
|
||||||
const isBookmarked = !!note.getParentBranches().find((b) => b.parentNoteId === "_lbBookmarks");
|
const isBookmarked = !!note.getParentBranches().find((b) => b.parentNoteId === "_lbBookmarks");
|
||||||
|
|
||||||
this.isToggled = isBookmarked;
|
this.isToggled = isBookmarked;
|
||||||
}
|
}
|
||||||
|
|
||||||
entitiesReloadedEvent({ loadResults }) {
|
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
if (loadResults.getBranchRows().find((b) => b.noteId === this.noteId)) {
|
if (loadResults.getBranchRows().find((b) => b.noteId === this.noteId)) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
@ -19,7 +19,7 @@ export default class AbstractButtonWidget<SettingsT extends AbstractButtonWidget
|
|||||||
protected settings!: SettingsT;
|
protected settings!: SettingsT;
|
||||||
protected tooltip!: bootstrap.Tooltip;
|
protected tooltip!: bootstrap.Tooltip;
|
||||||
|
|
||||||
isEnabled() {
|
isEnabled(): boolean | null | undefined {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
import froca from "../../services/froca.js";
|
import froca from "../../services/froca.js";
|
||||||
import attributeService from "../../services/attributes.js";
|
import attributeService from "../../services/attributes.js";
|
||||||
import CommandButtonWidget from "./command_button.js";
|
import CommandButtonWidget from "./command_button.js";
|
||||||
|
import type { EventData } from "../../components/app_context.js";
|
||||||
|
|
||||||
|
export type ButtonNoteIdProvider = () => string;
|
||||||
|
|
||||||
export default class ButtonFromNoteWidget extends CommandButtonWidget {
|
export default class ButtonFromNoteWidget extends CommandButtonWidget {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.settings.buttonNoteIdProvider = null;
|
this.settings.buttonNoteIdProvider = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonNoteIdProvider(provider) {
|
buttonNoteIdProvider(provider: ButtonNoteIdProvider) {
|
||||||
this.settings.buttonNoteIdProvider = provider;
|
this.settings.buttonNoteIdProvider = provider;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -21,6 +25,11 @@ export default class ButtonFromNoteWidget extends CommandButtonWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateIcon() {
|
updateIcon() {
|
||||||
|
if (!this.settings.buttonNoteIdProvider) {
|
||||||
|
console.error(`buttonNoteId for '${this.componentId}' is not defined.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const buttonNoteId = this.settings.buttonNoteIdProvider();
|
const buttonNoteId = this.settings.buttonNoteIdProvider();
|
||||||
|
|
||||||
if (!buttonNoteId) {
|
if (!buttonNoteId) {
|
||||||
@ -29,13 +38,18 @@ export default class ButtonFromNoteWidget extends CommandButtonWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
froca.getNote(buttonNoteId).then((note) => {
|
froca.getNote(buttonNoteId).then((note) => {
|
||||||
this.settings.icon = note.getIcon();
|
const icon = note?.getIcon();
|
||||||
|
if (icon) {
|
||||||
|
this.settings.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
this.refreshIcon();
|
this.refreshIcon();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
entitiesReloadedEvent({ loadResults }) {
|
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
|
// TODO: this seems incorrect
|
||||||
|
//@ts-ignore
|
||||||
const buttonNote = froca.getNoteFromCache(this.buttonNoteIdProvider());
|
const buttonNote = froca.getNoteFromCache(this.buttonNoteIdProvider());
|
||||||
|
|
||||||
if (!buttonNote) {
|
if (!buttonNote) {
|
@ -1,3 +1,4 @@
|
|||||||
|
import type { EventData } from "../../components/app_context.js";
|
||||||
import { t } from "../../services/i18n.js";
|
import { t } from "../../services/i18n.js";
|
||||||
import OnClickButtonWidget from "./onclick_button.js";
|
import OnClickButtonWidget from "./onclick_button.js";
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ export default class ClosePaneButton extends OnClickButtonWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async noteContextReorderEvent({ ntxIdsInOrder }) {
|
async noteContextReorderEvent({ ntxIdsInOrder }: EventData<"noteContextReorderEvent">) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
import type { CommandNames } from "../../components/app_context.js";
|
import type { CommandNames } from "../../components/app_context.js";
|
||||||
import keyboardActionsService, { type Action } from "../../services/keyboard_actions.js";
|
import keyboardActionsService, { type Action } from "../../services/keyboard_actions.js";
|
||||||
import AbstractButtonWidget, { type AbstractButtonWidgetSettings } from "./abstract_button.js";
|
import AbstractButtonWidget, { type AbstractButtonWidgetSettings } from "./abstract_button.js";
|
||||||
|
import type { ButtonNoteIdProvider } from "./button_from_note.js";
|
||||||
|
|
||||||
let actions: Action[];
|
let actions: Action[];
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ type CommandOrCallback = CommandNames | (() => CommandNames);
|
|||||||
interface CommandButtonWidgetSettings extends AbstractButtonWidgetSettings {
|
interface CommandButtonWidgetSettings extends AbstractButtonWidgetSettings {
|
||||||
command?: CommandOrCallback;
|
command?: CommandOrCallback;
|
||||||
onClick?: ClickHandler;
|
onClick?: ClickHandler;
|
||||||
|
buttonNoteIdProvider?: ButtonNoteIdProvider | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CommandButtonWidget extends AbstractButtonWidget<CommandButtonWidgetSettings> {
|
export default class CommandButtonWidget extends AbstractButtonWidget<CommandButtonWidgetSettings> {
|
||||||
|
@ -3,7 +3,10 @@ import appContext from "../../components/app_context.js";
|
|||||||
import { t } from "../../services/i18n.js";
|
import { t } from "../../services/i18n.js";
|
||||||
|
|
||||||
export default class MovePaneButton extends OnClickButtonWidget {
|
export default class MovePaneButton extends OnClickButtonWidget {
|
||||||
constructor(isMovingLeft) {
|
|
||||||
|
private isMovingLeft: boolean;
|
||||||
|
|
||||||
|
constructor(isMovingLeft: boolean) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.isMovingLeft = isMovingLeft;
|
this.isMovingLeft = isMovingLeft;
|
@ -2,9 +2,13 @@ import OnClickButtonWidget from "./onclick_button.js";
|
|||||||
import linkContextMenuService from "../../menus/link_context_menu.js";
|
import linkContextMenuService from "../../menus/link_context_menu.js";
|
||||||
import utils from "../../services/utils.js";
|
import utils from "../../services/utils.js";
|
||||||
import appContext from "../../components/app_context.js";
|
import appContext from "../../components/app_context.js";
|
||||||
|
import type FNote from "../../entities/fnote.js";
|
||||||
|
|
||||||
export default class OpenNoteButtonWidget extends OnClickButtonWidget {
|
export default class OpenNoteButtonWidget extends OnClickButtonWidget {
|
||||||
constructor(noteToOpen) {
|
|
||||||
|
private noteToOpen: FNote;
|
||||||
|
|
||||||
|
constructor(noteToOpen: FNote) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.noteToOpen = noteToOpen;
|
this.noteToOpen = noteToOpen;
|
||||||
@ -13,10 +17,14 @@ export default class OpenNoteButtonWidget extends OnClickButtonWidget {
|
|||||||
.icon(() => this.noteToOpen.getIcon())
|
.icon(() => this.noteToOpen.getIcon())
|
||||||
.onClick((widget, evt) => this.launch(evt))
|
.onClick((widget, evt) => this.launch(evt))
|
||||||
.onAuxClick((widget, evt) => this.launch(evt))
|
.onAuxClick((widget, evt) => this.launch(evt))
|
||||||
.onContextMenu((evt) => linkContextMenuService.openContextMenu(this.noteToOpen.noteId, evt));
|
.onContextMenu((evt) => {
|
||||||
|
if (evt) {
|
||||||
|
linkContextMenuService.openContextMenu(this.noteToOpen.noteId, evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async launch(evt) {
|
async launch(evt: JQuery.ClickEvent | JQuery.TriggeredEvent | JQuery.ContextMenuEvent) {
|
||||||
if (evt.which === 3) {
|
if (evt.which === 3) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ const TPL = `
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
${t("password_not_set.body1")}
|
${t("password_not_set.body1")}
|
||||||
|
|
||||||
${t("password_not_set.body2")}
|
${t("password_not_set.body2")}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -21,8 +21,13 @@ const TPL = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export default class PasswordNoteSetDialog extends BasicWidget {
|
export default class PasswordNoteSetDialog extends BasicWidget {
|
||||||
|
|
||||||
|
private modal!: bootstrap.Modal;
|
||||||
|
private $openPasswordOptionsButton!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
|
//@ts-ignore fix once bootstrap is imported via JQuery.
|
||||||
this.modal = bootstrap.Modal.getOrCreateInstance(this.$widget);
|
this.modal = bootstrap.Modal.getOrCreateInstance(this.$widget);
|
||||||
this.$openPasswordOptionsButton = this.$widget.find(".open-password-options-button");
|
this.$openPasswordOptionsButton = this.$widget.find(".open-password-options-button");
|
||||||
this.$openPasswordOptionsButton.on("click", () => {
|
this.$openPasswordOptionsButton.on("click", () => {
|
@ -8,13 +8,16 @@ const TPL = `
|
|||||||
class="copy-image-reference-button"
|
class="copy-image-reference-button"
|
||||||
title="${t("copy_image_reference_button.button_title")}">
|
title="${t("copy_image_reference_button.button_title")}">
|
||||||
<span class="bx bx-copy"></span>
|
<span class="bx bx-copy"></span>
|
||||||
|
|
||||||
<div class="hidden-image-copy"></div>
|
<div class="hidden-image-copy"></div>
|
||||||
</button>`;
|
</button>`;
|
||||||
|
|
||||||
export default class CopyImageReferenceButton extends NoteContextAwareWidget {
|
export default class CopyImageReferenceButton extends NoteContextAwareWidget {
|
||||||
|
|
||||||
|
private $hiddenImageCopy!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
return super.isEnabled() && ["mermaid", "canvas", "mindMap"].includes(this.note?.type) && this.note.isContentAvailable() && this.noteContext?.viewScope.viewMode === "default";
|
return super.isEnabled() && ["mermaid", "canvas", "mindMap"].includes(this.note?.type ?? "") && this.note?.isContentAvailable() && this.noteContext?.viewScope?.viewMode === "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
@ -24,6 +27,10 @@ export default class CopyImageReferenceButton extends NoteContextAwareWidget {
|
|||||||
this.$hiddenImageCopy = this.$widget.find(".hidden-image-copy");
|
this.$hiddenImageCopy = this.$widget.find(".hidden-image-copy");
|
||||||
|
|
||||||
this.$widget.on("click", () => {
|
this.$widget.on("click", () => {
|
||||||
|
if (!this.note) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.$hiddenImageCopy.empty().append($("<img>").attr("src", utils.createImageSrcUrl(this.note)));
|
this.$hiddenImageCopy.empty().append($("<img>").attr("src", utils.createImageSrcUrl(this.note)));
|
||||||
|
|
||||||
imageService.copyImageReferenceToClipboard(this.$hiddenImageCopy);
|
imageService.copyImageReferenceToClipboard(this.$hiddenImageCopy);
|
@ -11,7 +11,7 @@ const TPL = `
|
|||||||
|
|
||||||
export default class SvgExportButton extends NoteContextAwareWidget {
|
export default class SvgExportButton extends NoteContextAwareWidget {
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
return super.isEnabled() && ["mermaid", "mindMap"].includes(this.note?.type) && this.note.isContentAvailable() && this.noteContext?.viewScope.viewMode === "default";
|
return super.isEnabled() && ["mermaid", "mindMap"].includes(this.note?.type ?? "") && this.note?.isContentAvailable() && this.noteContext?.viewScope?.viewMode === "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
doRender() {
|
doRender() {
|
@ -1,3 +1,5 @@
|
|||||||
|
import type { EventData } from "../components/app_context.js";
|
||||||
|
import type FNote from "../entities/fnote.js";
|
||||||
import { t } from "../services/i18n.js";
|
import { t } from "../services/i18n.js";
|
||||||
import protectedSessionService from "../services/protected_session.js";
|
import protectedSessionService from "../services/protected_session.js";
|
||||||
import SwitchWidget from "./switch.js";
|
import SwitchWidget from "./switch.js";
|
||||||
@ -14,18 +16,22 @@ export default class ProtectedNoteSwitchWidget extends SwitchWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switchOn() {
|
switchOn() {
|
||||||
protectedSessionService.protectNote(this.noteId, true, false);
|
if (this.noteId) {
|
||||||
|
protectedSessionService.protectNote(this.noteId, true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switchOff() {
|
switchOff() {
|
||||||
protectedSessionService.protectNote(this.noteId, false, false);
|
if (this.noteId) {
|
||||||
|
protectedSessionService.protectNote(this.noteId, false, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note: FNote) {
|
||||||
this.isToggled = note.isProtected;
|
this.isToggled = note.isProtected;
|
||||||
}
|
}
|
||||||
|
|
||||||
entitiesReloadedEvent({ loadResults }) {
|
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
if (loadResults.isNoteReloaded(this.noteId)) {
|
if (loadResults.isNoteReloaded(this.noteId)) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
@ -10,7 +10,10 @@ import QuickSearchWidget from "./quick_search.js";
|
|||||||
* - Hiding the widget on mobile.
|
* - Hiding the widget on mobile.
|
||||||
*/
|
*/
|
||||||
export default class QuickSearchLauncherWidget extends QuickSearchWidget {
|
export default class QuickSearchLauncherWidget extends QuickSearchWidget {
|
||||||
constructor(isHorizontalLayout) {
|
|
||||||
|
private isHorizontalLayout: boolean;
|
||||||
|
|
||||||
|
constructor(isHorizontalLayout: boolean) {
|
||||||
super();
|
super();
|
||||||
this.isHorizontalLayout = isHorizontalLayout;
|
this.isHorizontalLayout = isHorizontalLayout;
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
import type FNote from "../../entities/fnote.js";
|
||||||
import { t } from "../../services/i18n.js";
|
import { t } from "../../services/i18n.js";
|
||||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||||
|
|
||||||
@ -19,6 +20,9 @@ const TPL = `
|
|||||||
* TODO: figure out better name or conceptualize better.
|
* TODO: figure out better name or conceptualize better.
|
||||||
*/
|
*/
|
||||||
export default class NotePropertiesWidget extends NoteContextAwareWidget {
|
export default class NotePropertiesWidget extends NoteContextAwareWidget {
|
||||||
|
|
||||||
|
private $pageUrl!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
return this.note && !!this.note.getLabelValue("pageUrl");
|
return this.note && !!this.note.getLabelValue("pageUrl");
|
||||||
}
|
}
|
||||||
@ -39,9 +43,9 @@ export default class NotePropertiesWidget extends NoteContextAwareWidget {
|
|||||||
this.$pageUrl = this.$widget.find(".page-url");
|
this.$pageUrl = this.$widget.find(".page-url");
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note: FNote) {
|
||||||
const pageUrl = note.getLabelValue("pageUrl");
|
const pageUrl = note.getLabelValue("pageUrl");
|
||||||
|
|
||||||
this.$pageUrl.attr("href", pageUrl).attr("title", pageUrl).text(pageUrl);
|
this.$pageUrl.attr("href", pageUrl).attr("title", pageUrl).text(pageUrl ?? "");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ export default class Debug extends AbstractSearchOption {
|
|||||||
return "label";
|
return "label";
|
||||||
}
|
}
|
||||||
|
|
||||||
static async create(noteId) {
|
static async create(noteId: string) {
|
||||||
await AbstractSearchOption.setAttribute(noteId, "label", "debug");
|
await AbstractSearchOption.setAttribute(noteId, "label", "debug");
|
||||||
}
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ const TPL = `
|
|||||||
<span class="bx bx-help-circle icon-action" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>
|
<span class="bx bx-help-circle icon-action" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>
|
||||||
<div class="dropdown-menu dropdown-menu-right p-4">
|
<div class="dropdown-menu dropdown-menu-right p-4">
|
||||||
${t("fast_search.description")}
|
${t("fast_search.description")}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span class="bx bx-x icon-action search-option-del"></span>
|
<span class="bx bx-x icon-action search-option-del"></span>
|
||||||
</td>
|
</td>
|
||||||
@ -26,7 +26,7 @@ export default class FastSearch extends AbstractSearchOption {
|
|||||||
return "label";
|
return "label";
|
||||||
}
|
}
|
||||||
|
|
||||||
static async create(noteId) {
|
static async create(noteId: string) {
|
||||||
await AbstractSearchOption.setAttribute(noteId, "label", "fastSearch");
|
await AbstractSearchOption.setAttribute(noteId, "label", "fastSearch");
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ export default class IncludeArchivedNotes extends AbstractSearchOption {
|
|||||||
return "label";
|
return "label";
|
||||||
}
|
}
|
||||||
|
|
||||||
static async create(noteId) {
|
static async create(noteId: string) {
|
||||||
await AbstractSearchOption.setAttribute(noteId, "label", "includeArchivedNotes");
|
await AbstractSearchOption.setAttribute(noteId, "label", "includeArchivedNotes");
|
||||||
}
|
}
|
||||||
|
|
@ -123,13 +123,13 @@ export default class SwitchWidget extends NoteContextAwareWidget {
|
|||||||
private $switchButton!: JQuery<HTMLElement>;
|
private $switchButton!: JQuery<HTMLElement>;
|
||||||
private $switchToggle!: JQuery<HTMLElement>;
|
private $switchToggle!: JQuery<HTMLElement>;
|
||||||
private $switchName!: JQuery<HTMLElement>;
|
private $switchName!: JQuery<HTMLElement>;
|
||||||
private $helpButton!: JQuery<HTMLElement>;
|
protected $helpButton!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
private switchOnName = "";
|
protected switchOnName = "";
|
||||||
private switchOnTooltip = "";
|
protected switchOnTooltip = "";
|
||||||
|
|
||||||
private switchOffName = "";
|
protected switchOffName = "";
|
||||||
private switchOffTooltip = "";
|
protected switchOffTooltip = "";
|
||||||
|
|
||||||
private disabledTooltip = "";
|
private disabledTooltip = "";
|
||||||
|
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
import SwitchWidget from "./switch.js";
|
import SwitchWidget from "./switch.js";
|
||||||
import attributeService from "../services/attributes.js";
|
import attributeService from "../services/attributes.js";
|
||||||
import { t } from "../services/i18n.js";
|
import { t } from "../services/i18n.js";
|
||||||
|
import type { EventData } from "../components/app_context.js";
|
||||||
|
import type FNote from "../entities/fnote.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch for the basic properties widget which allows the user to select whether the note is a template or not, which toggles the `#template` attribute.
|
* Switch for the basic properties widget which allows the user to select whether the note is a template or not, which toggles the `#template` attribute.
|
||||||
*/
|
*/
|
||||||
export default class TemplateSwitchWidget extends SwitchWidget {
|
export default class TemplateSwitchWidget extends SwitchWidget {
|
||||||
|
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
return super.isEnabled() && !this.noteId.startsWith("_options");
|
return super.isEnabled() && !this.noteId?.startsWith("_options");
|
||||||
}
|
}
|
||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
@ -23,21 +26,25 @@ export default class TemplateSwitchWidget extends SwitchWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async switchOn() {
|
async switchOn() {
|
||||||
await attributeService.setLabel(this.noteId, "template");
|
if (this.noteId) {
|
||||||
}
|
await attributeService.setLabel(this.noteId, "template");
|
||||||
|
|
||||||
async switchOff() {
|
|
||||||
for (const templateAttr of this.note.getOwnedLabels("template")) {
|
|
||||||
await attributeService.removeAttributeById(this.noteId, templateAttr.attributeId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async switchOff() {
|
||||||
|
if (this.note && this.noteId) {
|
||||||
|
for (const templateAttr of this.note.getOwnedLabels("template")) {
|
||||||
|
await attributeService.removeAttributeById(this.noteId, templateAttr.attributeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async refreshWithNote(note: FNote) {
|
||||||
const isTemplate = note.hasLabel("template");
|
const isTemplate = note.hasLabel("template");
|
||||||
this.isToggled = isTemplate;
|
this.isToggled = isTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
entitiesReloadedEvent({ loadResults }) {
|
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
if (loadResults.getAttributeRows().find((attr) => attr.type === "label" && attr.name === "template" && attr.noteId === this.noteId)) {
|
if (loadResults.getAttributeRows().find((attr) => attr.type === "label" && attr.name === "template" && attr.noteId === this.noteId)) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import TypeWidget from "./type_widget.js";
|
import TypeWidget from "./type_widget.js";
|
||||||
import { t } from "../../services/i18n.js";
|
import { t } from "../../services/i18n.js";
|
||||||
|
import type FNote from "../../entities/fnote.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="note-detail-book note-detail-printable">
|
<div class="note-detail-book note-detail-printable">
|
||||||
@ -19,6 +20,9 @@ const TPL = `
|
|||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
export default class BookTypeWidget extends TypeWidget {
|
export default class BookTypeWidget extends TypeWidget {
|
||||||
|
|
||||||
|
private $helpNoChildren!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
static getType() {
|
static getType() {
|
||||||
return "book";
|
return "book";
|
||||||
}
|
}
|
||||||
@ -30,7 +34,7 @@ export default class BookTypeWidget extends TypeWidget {
|
|||||||
super.doRender();
|
super.doRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note) {
|
async doRefresh(note: FNote) {
|
||||||
this.$helpNoChildren.toggle(!this.note.hasChildren());
|
this.$helpNoChildren.toggle(!this.note?.hasChildren());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,13 @@
|
|||||||
import TypeWidget from "./type_widget.js";
|
import TypeWidget from "./type_widget.js";
|
||||||
import NoteMapWidget from "../note_map.js";
|
import NoteMapWidget from "../note_map.js";
|
||||||
|
import type FNote from "../../entities/fnote.js";
|
||||||
|
|
||||||
const TPL = `<div class="note-detail-note-map note-detail-printable"></div>`;
|
const TPL = `<div class="note-detail-note-map note-detail-printable"></div>`;
|
||||||
|
|
||||||
export default class NoteMapTypeWidget extends TypeWidget {
|
export default class NoteMapTypeWidget extends TypeWidget {
|
||||||
|
|
||||||
|
private noteMapWidget: NoteMapWidget;
|
||||||
|
|
||||||
static getType() {
|
static getType() {
|
||||||
return "noteMap";
|
return "noteMap";
|
||||||
}
|
}
|
||||||
@ -22,7 +26,7 @@ export default class NoteMapTypeWidget extends TypeWidget {
|
|||||||
super.doRender();
|
super.doRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note) {
|
async doRefresh(note: FNote) {
|
||||||
await this.noteMapWidget.refresh();
|
await this.noteMapWidget.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user