mirror of
https://github.com/zadam/trilium.git
synced 2025-01-17 04:27:56 +08:00
small cleanups
This commit is contained in:
parent
32d60a7eb9
commit
9797942b8e
13 changed files with 58 additions and 92 deletions
|
@ -1,4 +1,3 @@
|
|||
import cloning from './services/cloning.js';
|
||||
import contextMenu from './services/tree_context_menu.js';
|
||||
import link from './services/link.js';
|
||||
import ws from './services/ws.js';
|
||||
|
@ -9,7 +8,7 @@ import FrontendScriptApi from './services/frontend_script_api.js';
|
|||
import ScriptContext from './services/script_context.js';
|
||||
import sync from './services/sync.js';
|
||||
import treeService from './services/tree.js';
|
||||
import treeChanges from './services/branches.js';
|
||||
import branchService from './services/branches.js';
|
||||
import utils from './services/utils.js';
|
||||
import server from './services/server.js';
|
||||
import Entrypoints from './services/entrypoints.js';
|
||||
|
@ -22,7 +21,6 @@ import noteTypeService from './widgets/note_type.js';
|
|||
import linkService from './services/link.js';
|
||||
import noteAutocompleteService from './services/note_autocomplete.js';
|
||||
import macInit from './services/mac_init.js';
|
||||
import cssLoader from './services/css_loader.js';
|
||||
import dateNoteService from './services/date_notes.js';
|
||||
import importService from './services/import.js';
|
||||
import keyboardActionService from "./services/keyboard_actions.js";
|
||||
|
@ -76,7 +74,7 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {
|
|||
};
|
||||
|
||||
for (const appCssNoteId of window.appCssNoteIds) {
|
||||
cssLoader.requireCss(`api/notes/download/${appCssNoteId}`);
|
||||
libraryLoader.requireCss(`api/notes/download/${appCssNoteId}`);
|
||||
}
|
||||
|
||||
const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/";
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import noteAutocompleteService from "../services/note_autocomplete.js";
|
||||
import utils from "../services/utils.js";
|
||||
import cloningService from "../services/cloning.js";
|
||||
import treeService from "../services/tree.js";
|
||||
import toastService from "../services/toast.js";
|
||||
import treeCache from "../services/tree_cache.js";
|
||||
import branchService from "../services/branches.js";
|
||||
|
||||
const $dialog = $("#clone-to-dialog");
|
||||
const $form = $("#clone-to-form");
|
||||
|
@ -42,7 +42,7 @@ async function cloneNotesTo(notePath) {
|
|||
const targetNoteId = treeService.getNoteIdFromNotePath(notePath);
|
||||
|
||||
for (const cloneNoteId of clonedNoteIds) {
|
||||
await cloningService.cloneNoteTo(cloneNoteId, targetNoteId, $clonePrefix.val());
|
||||
await branchService.cloneNoteTo(cloneNoteId, targetNoteId, $clonePrefix.val());
|
||||
|
||||
const clonedNote = await treeCache.getNote(cloneNoteId);
|
||||
const targetNote = await treeCache.getNote(targetNoteId);
|
||||
|
|
|
@ -2,8 +2,7 @@ import noteAutocompleteService from "../services/note_autocomplete.js";
|
|||
import utils from "../services/utils.js";
|
||||
import toastService from "../services/toast.js";
|
||||
import treeCache from "../services/tree_cache.js";
|
||||
import treeChangesService from "../services/branches.js";
|
||||
import appContext from "../services/app_context.js";
|
||||
import branchService from "../services/branches.js";
|
||||
import treeService from "../services/tree.js";
|
||||
|
||||
const $dialog = $("#move-to-dialog");
|
||||
|
@ -34,7 +33,7 @@ export async function showDialog(branchIds) {
|
|||
}
|
||||
|
||||
async function moveNotesTo(parentNoteId) {
|
||||
await treeChangesService.moveToParentNote(movedBranchIds, parentNoteId);
|
||||
await branchService.moveToParentNote(movedBranchIds, parentNoteId);
|
||||
|
||||
const parentNote = await treeCache.getNote(parentNoteId);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import server from "../../services/server.js";
|
||||
import utils from "../../services/utils.js";
|
||||
import cssLoader from "../../services/css_loader.js";
|
||||
import appContext from "../../services/app_context.js";
|
||||
import libraryLoader from "../../services/library_loader.js";
|
||||
|
||||
const TPL = `
|
||||
<p><strong>Settings on this options tab are saved automatically after each change.</strong></p>
|
||||
|
@ -98,7 +98,7 @@ export default class ApperanceOptions {
|
|||
if (noteId) {
|
||||
// make sure the CSS is loaded
|
||||
// if the CSS has been loaded and then updated then the changes won't take effect though
|
||||
cssLoader.requireCss(`api/notes/download/${noteId}`);
|
||||
libraryLoader.requireCss(`api/notes/download/${noteId}`);
|
||||
}
|
||||
|
||||
this.$body.addClass("theme-" + newTheme);
|
||||
|
|
|
@ -2,7 +2,7 @@ import treeService from "./services/tree.js";
|
|||
import treeCache from "./services/tree_cache.js";
|
||||
import treeBuilder from "./services/tree_builder.js";
|
||||
import contextMenuWidget from "./services/context_menu.js";
|
||||
import treeChangesService from "./services/branches.js";
|
||||
import branchService from "./services/branches.js";
|
||||
import utils from "./services/utils.js";
|
||||
import appContext from "./services/app_context.js";
|
||||
import noteCreateService from "./services/note_create.js";
|
||||
|
@ -123,7 +123,7 @@ $detail.on("click", ".note-menu-button", async e => {
|
|||
noteCreateService.createNote(node.data.noteId);
|
||||
}
|
||||
else if (cmd === "delete") {
|
||||
if (await treeChangesService.deleteNotes([node])) {
|
||||
if (await branchService.deleteNotes([node])) {
|
||||
// move to the tree
|
||||
togglePanes();
|
||||
}
|
||||
|
|
|
@ -198,10 +198,31 @@ ws.subscribeToMessages(async message => {
|
|||
}
|
||||
});
|
||||
|
||||
async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
|
||||
const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, {
|
||||
prefix: prefix
|
||||
});
|
||||
|
||||
if (!resp.success) {
|
||||
alert(resp.message);
|
||||
}
|
||||
}
|
||||
|
||||
// beware that first arg is noteId and second is branchId!
|
||||
async function cloneNoteAfter(noteId, afterBranchId) {
|
||||
const resp = await server.put('notes/' + noteId + '/clone-after/' + afterBranchId);
|
||||
|
||||
if (!resp.success) {
|
||||
alert(resp.message);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
moveBeforeBranch,
|
||||
moveAfterBranch,
|
||||
moveToParentNote,
|
||||
deleteNotes,
|
||||
moveNodeUpInHierarchy
|
||||
moveNodeUpInHierarchy,
|
||||
cloneNoteAfter,
|
||||
cloneNoteTo
|
||||
};
|
|
@ -1,5 +1,4 @@
|
|||
import treeChangesService from "./branches.js";
|
||||
import cloningService from "./cloning.js";
|
||||
import branchService from "./branches.js";
|
||||
import toastService from "./toast.js";
|
||||
import hoistedNoteService from "./hoisted_note.js";
|
||||
import treeCache from "./tree_cache.js";
|
||||
|
@ -13,7 +12,7 @@ async function pasteAfter(afterBranchId) {
|
|||
}
|
||||
|
||||
if (clipboardMode === 'cut') {
|
||||
await treeChangesService.moveAfterBranch(clipboardBranchIds, afterBranchId);
|
||||
await branchService.moveAfterBranch(clipboardBranchIds, afterBranchId);
|
||||
|
||||
clipboardBranchIds = [];
|
||||
clipboardMode = null;
|
||||
|
@ -24,7 +23,7 @@ async function pasteAfter(afterBranchId) {
|
|||
for (const clipboardBranch of clipboardBranches) {
|
||||
const clipboardNote = await clipboardBranch.getNote();
|
||||
|
||||
await cloningService.cloneNoteAfter(clipboardNote.noteId, afterBranchId);
|
||||
await branchService.cloneNoteAfter(clipboardNote.noteId, afterBranchId);
|
||||
}
|
||||
|
||||
// copy will keep clipboardBranchIds and clipboardMode so it's possible to paste into multiple places
|
||||
|
@ -40,7 +39,7 @@ async function pasteInto(parentNoteId) {
|
|||
}
|
||||
|
||||
if (clipboardMode === 'cut') {
|
||||
await treeChangesService.moveToParentNote(clipboardBranchIds, parentNoteId);
|
||||
await branchService.moveToParentNote(clipboardBranchIds, parentNoteId);
|
||||
|
||||
clipboardBranchIds = [];
|
||||
clipboardMode = null;
|
||||
|
@ -51,7 +50,7 @@ async function pasteInto(parentNoteId) {
|
|||
for (const clipboardBranch of clipboardBranches) {
|
||||
const clipboardNote = await clipboardBranch.getNote();
|
||||
|
||||
await cloningService.cloneNoteTo(clipboardNote.noteId, parentNoteId);
|
||||
await branchService.cloneNoteTo(clipboardNote.noteId, parentNoteId);
|
||||
}
|
||||
|
||||
// copy will keep clipboardBranchIds and clipboardMode so it's possible to paste into multiple places
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
import treeCache from './tree_cache.js';
|
||||
import server from './server.js';
|
||||
import appContext from "./app_context.js";
|
||||
|
||||
async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
|
||||
const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, {
|
||||
prefix: prefix
|
||||
});
|
||||
|
||||
if (!resp.success) {
|
||||
alert(resp.message);
|
||||
}
|
||||
}
|
||||
|
||||
// beware that first arg is noteId and second is branchId!
|
||||
async function cloneNoteAfter(noteId, afterBranchId) {
|
||||
const resp = await server.put('notes/' + noteId + '/clone-after/' + afterBranchId);
|
||||
|
||||
if (!resp.success) {
|
||||
alert(resp.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const afterBranch = treeCache.getBranch(afterBranchId);
|
||||
}
|
||||
|
||||
export default {
|
||||
cloneNoteAfter,
|
||||
cloneNoteTo
|
||||
};
|
|
@ -1,13 +0,0 @@
|
|||
async function requireCss(url) {
|
||||
const cssLinks = Array
|
||||
.from(document.querySelectorAll('link'))
|
||||
.map(el => el.href);
|
||||
|
||||
if (!cssLinks.some(l => l.endsWith(url))) {
|
||||
$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', url));
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
requireCss
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import toastService from "./toast.js";
|
||||
import treeService from "./tree.js";
|
||||
import server from "./server.js";
|
||||
import ws from "./ws.js";
|
||||
import utils from "./utils.js";
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
class Actions {
|
||||
constructor() {
|
||||
this.JUMP_TO = "";
|
||||
}
|
||||
}
|
||||
|
||||
const actions = new Actions();
|
||||
|
||||
function bind() {
|
||||
|
||||
}
|
||||
|
||||
export default {
|
||||
actions,
|
||||
bind
|
||||
};
|
|
@ -1,5 +1,3 @@
|
|||
import cssLoader from './css_loader.js';
|
||||
|
||||
const CKEDITOR = {"js": ["libraries/ckeditor/ckeditor.js"]};
|
||||
|
||||
const CODE_MIRROR = {
|
||||
|
@ -55,7 +53,7 @@ const CALENDAR_WIDGET = {css: ["stylesheets/calendar.css"]};
|
|||
|
||||
async function requireLibrary(library) {
|
||||
if (library.css) {
|
||||
library.css.map(cssUrl => cssLoader.requireCss(cssUrl));
|
||||
library.css.map(cssUrl => requireCss(cssUrl));
|
||||
}
|
||||
|
||||
if (library.js) {
|
||||
|
@ -80,7 +78,18 @@ async function requireScript(url) {
|
|||
await loadedScriptPromises[url];
|
||||
}
|
||||
|
||||
async function requireCss(url) {
|
||||
const cssLinks = Array
|
||||
.from(document.querySelectorAll('link'))
|
||||
.map(el => el.href);
|
||||
|
||||
if (!cssLinks.some(l => l.endsWith(url))) {
|
||||
$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', url));
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
requireCss,
|
||||
requireLibrary,
|
||||
CKEDITOR,
|
||||
CODE_MIRROR,
|
||||
|
|
|
@ -5,7 +5,7 @@ import contextMenuWidget from "../services/context_menu.js";
|
|||
import treeCache from "../services/tree_cache.js";
|
||||
import treeBuilder from "../services/tree_builder.js";
|
||||
import TreeContextMenu from "../services/tree_context_menu.js";
|
||||
import treeChangesService from "../services/branches.js";
|
||||
import branchService from "../services/branches.js";
|
||||
import ws from "../services/ws.js";
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import server from "../services/server.js";
|
||||
|
@ -167,11 +167,11 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
const selectedBranchIds = this.getSelectedNodes().map(node => node.data.branchId);
|
||||
|
||||
if (data.hitMode === "before") {
|
||||
treeChangesService.moveBeforeBranch(selectedBranchIds, node.data.branchId);
|
||||
branchService.moveBeforeBranch(selectedBranchIds, node.data.branchId);
|
||||
} else if (data.hitMode === "after") {
|
||||
treeChangesService.moveAfterBranch(selectedBranchIds, node.data.branchId);
|
||||
branchService.moveAfterBranch(selectedBranchIds, node.data.branchId);
|
||||
} else if (data.hitMode === "over") {
|
||||
treeChangesService.moveToParentNote(selectedBranchIds, node.data.noteId);
|
||||
branchService.moveToParentNote(selectedBranchIds, node.data.noteId);
|
||||
} else {
|
||||
throw new Error("Unknown hitMode=" + data.hitMode);
|
||||
}
|
||||
|
@ -661,7 +661,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
async deleteNotesCommand({node}) {
|
||||
const branchIds = this.getSelectedOrActiveBranchIds(node);
|
||||
|
||||
await treeChangesService.deleteNotes(branchIds);
|
||||
await branchService.deleteNotes(branchIds);
|
||||
|
||||
this.clearSelectedNodes();
|
||||
}
|
||||
|
@ -670,26 +670,26 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
const beforeNode = node.getPrevSibling();
|
||||
|
||||
if (beforeNode !== null) {
|
||||
treeChangesService.moveBeforeBranch([node.data.branchId], beforeNode.data.branchId);
|
||||
branchService.moveBeforeBranch([node.data.branchId], beforeNode.data.branchId);
|
||||
}
|
||||
}
|
||||
|
||||
moveNoteDownCommand({node}) {
|
||||
const afterNode = node.getNextSibling();
|
||||
if (afterNode !== null) {
|
||||
treeChangesService.moveAfterBranch([node.data.branchId], afterNode.data.branchId);
|
||||
branchService.moveAfterBranch([node.data.branchId], afterNode.data.branchId);
|
||||
}
|
||||
}
|
||||
|
||||
moveNoteUpInHierarchyCommand({node}) {
|
||||
treeChangesService.moveNodeUpInHierarchy(node);
|
||||
branchService.moveNodeUpInHierarchy(node);
|
||||
}
|
||||
|
||||
moveNoteDownInHierarchyCommand({node}) {
|
||||
const toNode = node.getPrevSibling();
|
||||
|
||||
if (toNode !== null) {
|
||||
treeChangesService.moveToParentNote([node.data.branchId], toNode.data.noteId);
|
||||
branchService.moveToParentNote([node.data.branchId], toNode.data.noteId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue