renamed service variables to conform to new naming scheme

This commit is contained in:
azivner 2018-03-25 13:41:29 -04:00
parent d746d707b5
commit 297a2cd9da
31 changed files with 121 additions and 176 deletions

View file

@ -1,9 +1,7 @@
"use strict"; import treeService from '../services/tree.js';
import cloningService from '../services/cloning.js';
import treeService from '../services/tree_service.js'; import linkService from '../services/link.js';
import cloning from '../services/cloning.js'; import noteDetailService from '../services/note_detail.js';
import link from '../services/link.js';
import noteDetail from '../services/note_detail.js';
import treeUtils from '../services/tree_utils.js'; import treeUtils from '../services/tree_utils.js';
const $dialog = $("#add-link-dialog"); const $dialog = $("#add-link-dialog");
@ -27,7 +25,7 @@ function setLinkType(linkType) {
async function showDialog() { async function showDialog() {
glob.activeDialog = $dialog; glob.activeDialog = $dialog;
if (noteDetail.getCurrentNoteType() === 'text') { if (noteDetailService.getCurrentNoteType() === 'text') {
$linkTypeHtml.prop('disabled', false); $linkTypeHtml.prop('disabled', false);
setLinkType('html'); setLinkType('html');
@ -58,7 +56,7 @@ async function showDialog() {
minLength: 0, minLength: 0,
change: () => { change: () => {
const val = $autoComplete.val(); const val = $autoComplete.val();
const notePath = link.getNodePathFromLabel(val); const notePath = linkService.getNodePathFromLabel(val);
if (!notePath) { if (!notePath) {
return; return;
} }
@ -72,7 +70,7 @@ async function showDialog() {
// this is called when user goes through autocomplete list with keyboard // this is called when user goes through autocomplete list with keyboard
// at this point the item isn't selected yet so we use supplied ui.item to see WHERE the cursor is // at this point the item isn't selected yet so we use supplied ui.item to see WHERE the cursor is
focus: (event, ui) => { focus: (event, ui) => {
const notePath = link.getNodePathFromLabel(ui.item.value); const notePath = linkService.getNodePathFromLabel(ui.item.value);
const noteId = treeUtils.getNoteIdFromNotePath(notePath); const noteId = treeUtils.getNoteIdFromNotePath(notePath);
setDefaultLinkTitle(noteId); setDefaultLinkTitle(noteId);
@ -83,7 +81,7 @@ async function showDialog() {
$form.submit(() => { $form.submit(() => {
const value = $autoComplete.val(); const value = $autoComplete.val();
const notePath = link.getNodePathFromLabel(value); const notePath = linkService.getNodePathFromLabel(value);
const noteId = treeUtils.getNoteIdFromNotePath(notePath); const noteId = treeUtils.getNoteIdFromNotePath(notePath);
if (notePath) { if (notePath) {
@ -94,19 +92,19 @@ $form.submit(() => {
$dialog.dialog("close"); $dialog.dialog("close");
link.addLinkToEditor(linkTitle, '#' + notePath); linkService.addLinkToEditor(linkTitle, '#' + notePath);
} }
else if (linkType === 'selected-to-current') { else if (linkType === 'selected-to-current') {
const prefix = $clonePrefix.val(); const prefix = $clonePrefix.val();
cloning.cloneNoteTo(noteId, noteDetail.getCurrentNoteId(), prefix); cloningService.cloneNoteTo(noteId, noteDetailService.getCurrentNoteId(), prefix);
$dialog.dialog("close"); $dialog.dialog("close");
} }
else if (linkType === 'current-to-selected') { else if (linkType === 'current-to-selected') {
const prefix = $clonePrefix.val(); const prefix = $clonePrefix.val();
cloning.cloneNoteTo(noteDetail.getCurrentNoteId(), noteId, prefix); cloningService.cloneNoteTo(noteDetailService.getCurrentNoteId(), noteId, prefix);
$dialog.dialog("close"); $dialog.dialog("close");
} }

View file

@ -1,6 +1,4 @@
"use strict"; import treeService from '../services/tree.js';
import treeService from '../services/tree_service.js';
const $dialog = $("#edit-tree-prefix-dialog"); const $dialog = $("#edit-tree-prefix-dialog");
const $form = $("#edit-tree-prefix-form"); const $form = $("#edit-tree-prefix-form");

View file

@ -1,6 +1,4 @@
"use strict"; import linkService from '../services/link.js';
import link from '../services/link.js';
import utils from '../services/utils.js'; import utils from '../services/utils.js';
const $dialog = $("#event-log-dialog"); const $dialog = $("#event-log-dialog");
@ -23,7 +21,7 @@ async function showDialog() {
const dateTime = utils.formatDateTime(utils.parseDate(event.dateAdded)); const dateTime = utils.formatDateTime(utils.parseDate(event.dateAdded));
if (event.noteId) { if (event.noteId) {
const noteLink = link.createNoteLink(event.noteId).prop('outerHTML'); const noteLink = linkService.createNoteLink(event.noteId).prop('outerHTML');
event.comment = event.comment.replace('<note>', noteLink); event.comment = event.comment.replace('<note>', noteLink);
} }

View file

@ -1,7 +1,5 @@
"use strict"; import treeService from '../services/tree.js';
import linkService from '../services/link.js';
import treeService from '../services/tree_service.js';
import link from '../services/link.js';
import utils from '../services/utils.js'; import utils from '../services/utils.js';
const $showDialogButton = $("#jump-to-note-button"); const $showDialogButton = $("#jump-to-note-button");
@ -27,7 +25,7 @@ async function showDialog() {
function getSelectedNotePath() { function getSelectedNotePath() {
const val = $autoComplete.val(); const val = $autoComplete.val();
return link.getNodePathFromLabel(val); return linkService.getNodePathFromLabel(val);
} }
function goToNote() { function goToNote() {

View file

@ -1,6 +1,4 @@
"use strict"; import noteDetailService from '../services/note_detail.js';
import noteDetail from '../services/note_detail.js';
import utils from '../services/utils.js'; import utils from '../services/utils.js';
const $showDialogButton = $(".show-labels-button"); const $showDialogButton = $(".show-labels-button");
@ -17,7 +15,7 @@ function LabelsModel() {
this.labels = ko.observableArray(); this.labels = ko.observableArray();
this.loadLabels = async function() { this.loadLabels = async function() {
const noteId = noteDetail.getCurrentNoteId(); const noteId = noteDetailService.getCurrentNoteId();
const labels = await server.get('notes/' + noteId + '/labels'); const labels = await server.get('notes/' + noteId + '/labels');
@ -81,7 +79,7 @@ function LabelsModel() {
return; return;
} }
const noteId = noteDetail.getCurrentNoteId(); const noteId = noteDetailService.getCurrentNoteId();
const labelsToSave = self.labels() const labelsToSave = self.labels()
.map(attr => attr()) .map(attr => attr())
@ -95,7 +93,7 @@ function LabelsModel() {
utils.showMessage("Labels have been saved."); utils.showMessage("Labels have been saved.");
noteDetail.loadLabelList(); noteDetailService.loadLabelList();
}; };
function addLastEmptyRow() { function addLastEmptyRow() {

View file

@ -1,6 +1,4 @@
"use strict"; import noteDetailService from '../services/note_detail.js';
import noteDetail from '../services/note_detail.js';
import utils from '../services/utils.js'; import utils from '../services/utils.js';
const $showDialogButton = $("#show-history-button"); const $showDialogButton = $("#show-history-button");
@ -12,7 +10,7 @@ const $title = $("#note-history-title");
let historyItems = []; let historyItems = [];
async function showCurrentNoteHistory() { async function showCurrentNoteHistory() {
await showNoteHistoryDialog(noteDetail.getCurrentNoteId()); await showNoteHistoryDialog(noteDetailService.getCurrentNoteId());
} }
async function showNoteHistoryDialog(noteId, noteRevisionId) { async function showNoteHistoryDialog(noteId, noteRevisionId) {

View file

@ -1,6 +1,4 @@
"use strict"; import noteDetailService from '../services/note_detail.js';
import noteDetail from '../services/note_detail.js';
const $showDialogButton = $("#show-source-button"); const $showDialogButton = $("#show-source-button");
const $dialog = $("#note-source-dialog"); const $dialog = $("#note-source-dialog");
@ -15,7 +13,7 @@ function showDialog() {
height: 500 height: 500
}); });
const noteText = noteDetail.getCurrentNote().detail.content; const noteText = noteDetailService.getCurrentNote().detail.content;
$noteSource.text(formatHtml(noteText)); $noteSource.text(formatHtml(noteText));
} }

View file

@ -1,6 +1,4 @@
"use strict"; import linkService from '../services/link.js';
import link from '../services/link.js';
import utils from '../services/utils.js'; import utils from '../services/utils.js';
const $showDialogButton = $("#recent-changes-button"); const $showDialogButton = $("#recent-changes-button");
@ -42,7 +40,7 @@ async function showDialog() {
noteLink = change.current_title; noteLink = change.current_title;
} }
else { else {
noteLink = link.createNoteLink(change.noteId, change.title); noteLink = linkService.createNoteLink(change.noteId, change.title);
} }
changesListEl.append($('<li>') changesListEl.append($('<li>')

View file

@ -1,8 +1,6 @@
"use strict"; import treeService from '../services/tree.js';
import messagingService from '../services/messaging.js';
import treeService from '../services/tree_service.js';
import server from '../services/server.js'; import server from '../services/server.js';
import messaging from '../services/messaging.js';
const $showDialogButton = $("#recent-notes-button"); const $showDialogButton = $("#recent-notes-button");
const $dialog = $("#recent-notes-dialog"); const $dialog = $("#recent-notes-dialog");
@ -53,7 +51,7 @@ function showDialog() {
catch (e) { catch (e) {
noteTitle = "[error - can't find note title]"; noteTitle = "[error - can't find note title]";
messaging.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack); messagingService.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack);
} }
return { return {

View file

@ -1,6 +1,6 @@
"use strict"; "use strict";
import protected_session from '../services/protected_session.js'; import protectedSessionService from '../services/protected_session.js';
import utils from '../services/utils.js'; import utils from '../services/utils.js';
import server from '../services/server.js'; import server from '../services/server.js';
@ -81,7 +81,7 @@ addModule((function() {
alert("Password has been changed. Trilium will be reloaded after you press OK."); alert("Password has been changed. Trilium will be reloaded after you press OK.");
// password changed so current protected session is invalid and needs to be cleared // password changed so current protected session is invalid and needs to be cleared
protected_session.resetProtectedSession(); protectedSessionService.resetProtectedSession();
} }
else { else {
utils.showError(result.message); utils.showError(result.message);
@ -109,7 +109,7 @@ addModule((function() {
const protectedSessionTimeout = $protectedSessionTimeout.val(); const protectedSessionTimeout = $protectedSessionTimeout.val();
settings.saveSettings(settingName, protectedSessionTimeout).then(() => { settings.saveSettings(settingName, protectedSessionTimeout).then(() => {
protected_session.setProtectedSessionTimeout(protectedSessionTimeout); protectedSessionService.setProtectedSessionTimeout(protectedSessionTimeout);
}); });
return false; return false;

View file

@ -1,5 +1,3 @@
"use strict";
import utils from '../services/utils.js'; import utils from '../services/utils.js';
const $dialog = $("#sql-console-dialog"); const $dialog = $("#sql-console-dialog");

View file

@ -28,7 +28,7 @@ import utils from './utils.js';
import searchTreeService from './search_tree.js'; import searchTreeService from './search_tree.js';
import './init.js'; import './init.js';
import treeService from './tree_service.js'; import treeService from './tree.js';
const $toggleSearchButton = $("#toggle-search-button"); const $toggleSearchButton = $("#toggle-search-button");
$toggleSearchButton.click(searchTreeService.toggleSearch); $toggleSearchButton.click(searchTreeService.toggleSearch);

View file

@ -1,6 +1,4 @@
"use strict"; import treeService from './tree.js';
import treeService from './tree_service.js';
async function cloneNoteTo(childNoteId, parentNoteId, prefix) { async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, { const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, {

View file

@ -1,11 +1,9 @@
"use strict"; import treeService from './tree.js';
import cloningService from './cloning.js';
import treeService from './tree_service.js';
import cloning from './cloning.js';
import exportService from './export.js'; import exportService from './export.js';
import messaging from './messaging.js'; import messagingService from './messaging.js';
import protected_session from './protected_session.js'; import protectedSessionService from './protected_session.js';
import treeChanges from './tree_changes.js'; import treeChangesService from './tree_changes.js';
import treeUtils from './tree_utils.js'; import treeUtils from './tree_utils.js';
import utils from './utils.js'; import utils from './utils.js';
@ -18,14 +16,14 @@ async function pasteAfter(node) {
if (clipboardMode === 'cut') { if (clipboardMode === 'cut') {
const nodes = clipboardIds.map(nodeKey => treeUtils.getNodeByKey(nodeKey)); const nodes = clipboardIds.map(nodeKey => treeUtils.getNodeByKey(nodeKey));
await treeChanges.moveAfterNode(nodes, node); await treeChangesService.moveAfterNode(nodes, node);
clipboardIds = []; clipboardIds = [];
clipboardMode = null; clipboardMode = null;
} }
else if (clipboardMode === 'copy') { else if (clipboardMode === 'copy') {
for (const noteId of clipboardIds) { for (const noteId of clipboardIds) {
await cloning.cloneNoteAfter(noteId, node.data.branchId); await cloningService.cloneNoteAfter(noteId, node.data.branchId);
} }
// copy will keep clipboardIds and clipboardMode so it's possible to paste into multiple places // copy will keep clipboardIds and clipboardMode so it's possible to paste into multiple places
@ -42,14 +40,14 @@ async function pasteInto(node) {
if (clipboardMode === 'cut') { if (clipboardMode === 'cut') {
const nodes = clipboardIds.map(nodeKey => treeUtils.getNodeByKey(nodeKey)); const nodes = clipboardIds.map(nodeKey => treeUtils.getNodeByKey(nodeKey));
await treeChanges.moveToNode(nodes, node); await treeChangesService.moveToNode(nodes, node);
clipboardIds = []; clipboardIds = [];
clipboardMode = null; clipboardMode = null;
} }
else if (clipboardMode === 'copy') { else if (clipboardMode === 'copy') {
for (const noteId of clipboardIds) { for (const noteId of clipboardIds) {
await cloning.cloneNoteTo(noteId, node.data.noteId); await cloningService.cloneNoteTo(noteId, node.data.noteId);
} }
// copy will keep clipboardIds and clipboardMode so it's possible to paste into multiple places // copy will keep clipboardIds and clipboardMode so it's possible to paste into multiple places
} }
@ -138,10 +136,10 @@ const contextMenuSettings = {
editTreePrefix.showDialog(node); editTreePrefix.showDialog(node);
} }
else if (ui.cmd === "protectSubTree") { else if (ui.cmd === "protectSubTree") {
protected_session.protectSubTree(node.data.noteId, true); protectedSessionService.protectSubTree(node.data.noteId, true);
} }
else if (ui.cmd === "unprotectSubTree") { else if (ui.cmd === "unprotectSubTree") {
protected_session.protectSubTree(node.data.noteId, false); protectedSessionService.protectSubTree(node.data.noteId, false);
} }
else if (ui.cmd === "copy") { else if (ui.cmd === "copy") {
copy(treeService.getSelectedNodes()); copy(treeService.getSelectedNodes());
@ -156,7 +154,7 @@ const contextMenuSettings = {
pasteInto(node); pasteInto(node);
} }
else if (ui.cmd === "delete") { else if (ui.cmd === "delete") {
treeChanges.deleteNodes(treeService.getSelectedNodes(true)); treeChangesService.deleteNodes(treeService.getSelectedNodes(true));
} }
else if (ui.cmd === "exportSubTree") { else if (ui.cmd === "exportSubTree") {
exportService.exportSubTree(node.data.noteId); exportService.exportSubTree(node.data.noteId);
@ -174,7 +172,7 @@ const contextMenuSettings = {
treeService.sortAlphabetically(node.data.noteId); treeService.sortAlphabetically(node.data.noteId);
} }
else { else {
messaging.logError("Unknown command: " + ui.cmd); messagingService.logError("Unknown command: " + ui.cmd);
} }
} }
}; };

View file

@ -1,7 +1,5 @@
"use strict"; import treeService from './tree.js';
import treeChangesService from './tree_changes.js';
import treeService from './tree_service.js';
import treeChanges from './tree_changes.js';
const dragAndDropSetup = { const dragAndDropSetup = {
autoExpandMS: 600, autoExpandMS: 600,
@ -55,13 +53,13 @@ const dragAndDropSetup = {
const selectedNodes = treeService.getSelectedNodes(); const selectedNodes = treeService.getSelectedNodes();
if (data.hitMode === "before") { if (data.hitMode === "before") {
treeChanges.moveBeforeNode(selectedNodes, node); treeChangesService.moveBeforeNode(selectedNodes, node);
} }
else if (data.hitMode === "after") { else if (data.hitMode === "after") {
treeChanges.moveAfterNode(selectedNodes, node); treeChangesService.moveAfterNode(selectedNodes, node);
} }
else if (data.hitMode === "over") { else if (data.hitMode === "over") {
treeChanges.moveToNode(selectedNodes, node); treeChangesService.moveToNode(selectedNodes, node);
} }
else { else {
throw new Exception("Unknown hitMode=" + data.hitMode); throw new Exception("Unknown hitMode=" + data.hitMode);

View file

@ -1,12 +1,10 @@
"use strict"; import treeService from './tree.js';
import protectedSessionService from './protected_session.js';
import treeService from './tree_service.js';
import protected_session from './protected_session.js';
import utils from './utils.js'; import utils from './utils.js';
function exportSubTree(noteId) { function exportSubTree(noteId) {
const url = utils.getHost() + "/api/export/" + noteId + "?protectedSessionId=" const url = utils.getHost() + "/api/export/" + noteId + "?protectedSessionId="
+ encodeURIComponent(protected_session.getProtectedSessionId()); + encodeURIComponent(protectedSessionService.getProtectedSessionId());
utils.download(url); utils.download(url);
} }

View file

@ -1,9 +1,7 @@
"use strict"; import treeService from './tree.js';
import linkService from './link.js';
import treeService from './tree_service.js'; import messagingService from './messaging.js';
import link from './link.js'; import noteDetailService from './note_detail.js';
import messaging from './messaging.js';
import noteDetail from './note_detail.js';
import treeUtils from './tree_utils.js'; import treeUtils from './tree_utils.js';
import utils from './utils.js'; import utils from './utils.js';
import server from './server.js'; import server from './server.js';
@ -24,7 +22,7 @@ $(document).bind('keydown', 'alt+t', e => {
const date = new Date(); const date = new Date();
const dateString = utils.formatDateTime(date); const dateString = utils.formatDateTime(date);
link.addTextToEditor(dateString); linkService.addTextToEditor(dateString);
e.preventDefault(); e.preventDefault();
}); });
@ -107,7 +105,7 @@ $("#note-title").bind('keydown', 'return', () => $("#note-detail").focus());
$(window).on('beforeunload', () => { $(window).on('beforeunload', () => {
// this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved // this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved
// this sends the request asynchronously and doesn't wait for result // this sends the request asynchronously and doesn't wait for result
noteDetail.saveNoteIfChanged(); noteDetailService.saveNoteIfChanged();
}); });
// Overrides the default autocomplete filter function to search for matched on atleast 1 word in each of the input term's words // Overrides the default autocomplete filter function to search for matched on atleast 1 word in each of the input term's words
@ -159,12 +157,12 @@ $.ui.autocomplete.filter = (array, terms) => {
$(document).tooltip({ $(document).tooltip({
items: "#note-detail a", items: "#note-detail a",
content: function(callback) { content: function(callback) {
const notePath = link.getNotePathFromLink($(this).attr("href")); const notePath = linkService.getNotePathFromLink($(this).attr("href"));
if (notePath !== null) { if (notePath !== null) {
const noteId = treeUtils.getNoteIdFromNotePath(notePath); const noteId = treeUtils.getNoteIdFromNotePath(notePath);
noteDetail.loadNote(noteId).then(note => callback(note.detail.content)); noteDetailService.loadNote(noteId).then(note => callback(note.detail.content));
} }
}, },
close: function(event, ui) close: function(event, ui)
@ -201,7 +199,7 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {
].join(' - '); ].join(' - ');
} }
messaging.logError(message); messagingService.logError(message);
return false; return false;
}; };
@ -244,7 +242,7 @@ $("#attachment-upload").change(async function() {
formData.append('upload', this.files[0]); formData.append('upload', this.files[0]);
const resp = await $.ajax({ const resp = await $.ajax({
url: baseApiUrl + 'attachments/upload/' + noteDetail.getCurrentNoteId(), url: baseApiUrl + 'attachments/upload/' + noteDetailService.getCurrentNoteId(),
headers: server.getHeaders(), headers: server.getHeaders(),
data: formData, data: formData,
type: 'POST', type: 'POST',

View file

@ -1,7 +1,5 @@
"use strict"; import treeService from './tree.js';
import noteDetailService from './note_detail.js';
import treeService from './tree_service.js';
import noteDetail from './note_detail.js';
import treeUtils from './tree_utils.js'; import treeUtils from './tree_utils.js';
function getNotePathFromLink(url) { function getNotePathFromLink(url) {
@ -77,14 +75,14 @@ function goToLink(e) {
} }
function addLinkToEditor(linkTitle, linkHref) { function addLinkToEditor(linkTitle, linkHref) {
const editor = noteDetail.getEditor(); const editor = noteDetailService.getEditor();
const doc = editor.document; const doc = editor.document;
doc.enqueueChanges(() => editor.data.insertLink(linkTitle, linkHref), doc.selection); doc.enqueueChanges(() => editor.data.insertLink(linkTitle, linkHref), doc.selection);
} }
function addTextToEditor(text) { function addTextToEditor(text) {
const editor = noteDetail.getEditor(); const editor = noteDetailService.getEditor();
const doc = editor.document; const doc = editor.document;
doc.enqueueChanges(() => editor.data.insertText(text), doc.selection); doc.enqueueChanges(() => editor.data.insertText(text), doc.selection);

View file

@ -1,9 +1,7 @@
"use strict"; import treeService from './tree.js';
import treeService from './tree_service.js';
import noteDetailService from './note_detail.js'; import noteDetailService from './note_detail.js';
import utils from './utils.js'; import utils from './utils.js';
import recentNotes from '../dialogs/recent_notes.js'; import recentNotesDialog from '../dialogs/recent_notes.js';
const $changesToPushCount = $("#changes-to-push-count"); const $changesToPushCount = $("#changes-to-push-count");
@ -54,7 +52,7 @@ function messageHandler(event) {
if (syncData.some(sync => sync.entityName === 'recent_notes')) { if (syncData.some(sync => sync.entityName === 'recent_notes')) {
console.log(utils.now(), "Reloading recent notes because of background changes"); console.log(utils.now(), "Reloading recent notes because of background changes");
recentNotes.reload(); recentNotesDialog.reload();
} }
// we don't detect image changes here since images themselves are immutable and references should be // we don't detect image changes here since images themselves are immutable and references should be

View file

@ -1,8 +1,6 @@
"use strict"; import treeService from './tree.js';
import noteTypeService from './note_type.js';
import treeService from './tree_service.js'; import protectedSessionService from './protected_session.js';
import noteType from './note_type.js';
import protected_session from './protected_session.js';
import utils from './utils.js'; import utils from './utils.js';
import server from './server.js'; import server from './server.js';
@ -80,7 +78,7 @@ async function saveNoteIfChanged() {
await saveNoteToServer(note); await saveNoteToServer(note);
if (note.detail.isProtected) { if (note.detail.isProtected) {
protected_session.touchProtectedSession(); protectedSessionService.touchProtectedSession();
} }
} }
@ -221,15 +219,15 @@ async function loadNoteToEditor(noteId) {
$noteIdDisplay.html(noteId); $noteIdDisplay.html(noteId);
await protected_session.ensureProtectedSession(currentNote.detail.isProtected, false); await protectedSessionService.ensureProtectedSession(currentNote.detail.isProtected, false);
if (currentNote.detail.isProtected) { if (currentNote.detail.isProtected) {
protected_session.touchProtectedSession(); protectedSessionService.touchProtectedSession();
} }
// this might be important if we focused on protected note when not in protected note and we got a dialog // this might be important if we focused on protected note when not in protected note and we got a dialog
// to login, but we chose instead to come to another node - at that point the dialog is still visible and this will close it. // to login, but we chose instead to come to another node - at that point the dialog is still visible and this will close it.
protected_session.ensureDialogIsClosed(); protectedSessionService.ensureDialogIsClosed();
$noteDetailWrapper.show(); $noteDetailWrapper.show();
@ -237,8 +235,8 @@ async function loadNoteToEditor(noteId) {
$noteTitle.val(currentNote.detail.title); $noteTitle.val(currentNote.detail.title);
noteType.setNoteType(currentNote.detail.type); noteTypeService.setNoteType(currentNote.detail.type);
noteType.setNoteMime(currentNote.detail.mime); noteTypeService.setNoteMime(currentNote.detail.mime);
$noteDetail.hide(); $noteDetail.hide();
$noteDetailSearch.hide(); $noteDetailSearch.hide();
@ -362,7 +360,7 @@ $attachmentOpen.click(() => {
function getAttachmentUrl() { function getAttachmentUrl() {
// electron needs absolute URL so we extract current host, port, protocol // electron needs absolute URL so we extract current host, port, protocol
return utils.getHost() + "/api/attachments/download/" + getCurrentNoteId() return utils.getHost() + "/api/attachments/download/" + getCurrentNoteId()
+ "?protectedSessionId=" + encodeURIComponent(protected_session.getProtectedSessionId()); + "?protectedSessionId=" + encodeURIComponent(protectedSessionService.getProtectedSessionId());
} }
$(document).ready(() => { $(document).ready(() => {

View file

@ -1,6 +1,4 @@
"use strict"; import treeService from './tree.js';
import treeService from './tree_service.js';
import noteDetail from './note_detail.js'; import noteDetail from './note_detail.js';
import utils from './utils.js'; import utils from './utils.js';

View file

@ -1,6 +1,4 @@
"use strict"; import treeService from './tree.js';
import treeService from './tree_service.js';
import noteDetail from './note_detail.js'; import noteDetail from './note_detail.js';
import utils from './utils.js'; import utils from './utils.js';
import server from './server.js'; import server from './server.js';

View file

@ -1,4 +1,4 @@
import treeService from './tree_service.js'; import treeService from './tree.js';
function ScriptApi(startNote, currentNote) { function ScriptApi(startNote, currentNote) {
const $pluginButtons = $("#plugin-buttons"); const $pluginButtons = $("#plugin-buttons");

View file

@ -1,5 +1,3 @@
"use strict";
import ScriptApi from './script_api.js'; import ScriptApi from './script_api.js';
import utils from './utils.js'; import utils from './utils.js';

View file

@ -1,6 +1,4 @@
"use strict"; import treeService from './tree.js';
import treeService from './tree_service.js';
const $tree = $("#tree"); const $tree = $("#tree");
const $searchInput = $("input[name='search-text']"); const $searchInput = $("input[name='search-text']");

View file

@ -1,13 +1,11 @@
"use strict"; import protectedSessionService from './protected_session.js';
import protected_session from './protected_session.js';
import utils from './utils.js'; import utils from './utils.js';
function getHeaders() { function getHeaders() {
let protectedSessionId = null; let protectedSessionId = null;
try { // this is because protected session might not be declared in some cases - like when it's included in migration page try { // this is because protected session might not be declared in some cases - like when it's included in migration page
protectedSessionId = protected_session.getProtectedSessionId(); protectedSessionId = protectedSessionService.getProtectedSessionId();
} }
catch(e) {} catch(e) {}

View file

@ -1,5 +1,3 @@
"use strict";
import utils from './utils.js'; import utils from './utils.js';
async function syncNow() { async function syncNow() {

View file

@ -1,16 +1,14 @@
"use strict"; import contextMenuService from './context_menu.js';
import contextMenu from './context_menu.js';
import dragAndDropSetup from './drag_and_drop.js'; import dragAndDropSetup from './drag_and_drop.js';
import link from './link.js'; import linkService from './link.js';
import messaging from './messaging.js'; import messagingService from './messaging.js';
import noteDetail from './note_detail.js'; import noteDetailService from './note_detail.js';
import protected_session from './protected_session.js'; import protectedSessionService from './protected_session.js';
import treeChanges from './tree_changes.js'; import treeChangesService from './tree_changes.js';
import treeUtils from './tree_utils.js'; import treeUtils from './tree_utils.js';
import utils from './utils.js'; import utils from './utils.js';
import server from './server.js'; import server from './server.js';
import recentNotes from '../dialogs/recent_notes.js'; import recentNotesDialog from '../dialogs/recent_notes.js';
import treeCache from './tree_cache.js'; import treeCache from './tree_cache.js';
const $tree = $("#tree"); const $tree = $("#tree");
@ -146,7 +144,7 @@ async function prepareBranchInner(parentNote) {
const childBranches = await parentNote.getChildBranches(); const childBranches = await parentNote.getChildBranches();
if (!childBranches) { if (!childBranches) {
messaging.logError(`No children for ${parentNote}. This shouldn't happen.`); messagingService.logError(`No children for ${parentNote}. This shouldn't happen.`);
return; return;
} }
@ -245,7 +243,7 @@ async function getRunPath(notePath) {
const parents = await child.getParentNotes(); const parents = await child.getParentNotes();
if (!parents) { if (!parents) {
messaging.logError("No parents found for " + childNoteId); messagingService.logError("No parents found for " + childNoteId);
return; return;
} }
@ -268,7 +266,7 @@ async function getRunPath(notePath) {
break; break;
} }
else { else {
messaging.logError("No parents, can't activate node."); messagingService.logError("No parents, can't activate node.");
return; return;
} }
} }
@ -315,7 +313,7 @@ async function showParentList(noteId, node) {
item = $("<span/>").attr("title", "Current note").append(title); item = $("<span/>").attr("title", "Current note").append(title);
} }
else { else {
item = link.createNoteLink(notePath, title); item = linkService.createNoteLink(notePath, title);
} }
$parentListList.append($("<li/>").append(item)); $parentListList.append($("<li/>").append(item));
@ -377,7 +375,7 @@ function setCurrentNotePathToHash(node) {
document.location.hash = currentNotePath; document.location.hash = currentNotePath;
recentNotes.addRecentNote(currentBranchId, currentNotePath); recentNotesDialog.addRecentNote(currentBranchId, currentNotePath);
} }
function getSelectedNodes(stopOnParents = false) { function getSelectedNodes(stopOnParents = false) {
@ -401,13 +399,13 @@ function initFancyTree(branch) {
const keybindings = { const keybindings = {
"del": node => { "del": node => {
treeChanges.deleteNodes(getSelectedNodes(true)); treeChangesService.deleteNodes(getSelectedNodes(true));
}, },
"ctrl+up": node => { "ctrl+up": node => {
const beforeNode = node.getPrevSibling(); const beforeNode = node.getPrevSibling();
if (beforeNode !== null) { if (beforeNode !== null) {
treeChanges.moveBeforeNode([node], beforeNode); treeChangesService.moveBeforeNode([node], beforeNode);
} }
return false; return false;
@ -415,13 +413,13 @@ function initFancyTree(branch) {
"ctrl+down": node => { "ctrl+down": node => {
let afterNode = node.getNextSibling(); let afterNode = node.getNextSibling();
if (afterNode !== null) { if (afterNode !== null) {
treeChanges.moveAfterNode([node], afterNode); treeChangesService.moveAfterNode([node], afterNode);
} }
return false; return false;
}, },
"ctrl+left": node => { "ctrl+left": node => {
treeChanges.moveNodeUpInHierarchy(node); treeChangesService.moveNodeUpInHierarchy(node);
return false; return false;
}, },
@ -429,7 +427,7 @@ function initFancyTree(branch) {
let toNode = node.getPrevSibling(); let toNode = node.getPrevSibling();
if (toNode !== null) { if (toNode !== null) {
treeChanges.moveToNode([node], toNode); treeChangesService.moveToNode([node], toNode);
} }
return false; return false;
@ -479,22 +477,22 @@ function initFancyTree(branch) {
return false; return false;
}, },
"ctrl+c": () => { "ctrl+c": () => {
contextMenu.copy(getSelectedNodes()); contextMenuService.copy(getSelectedNodes());
return false; return false;
}, },
"ctrl+x": () => { "ctrl+x": () => {
contextMenu.cut(getSelectedNodes()); contextMenuService.cut(getSelectedNodes());
return false; return false;
}, },
"ctrl+v": node => { "ctrl+v": node => {
contextMenu.pasteInto(node); contextMenuService.pasteInto(node);
return false; return false;
}, },
"return": node => { "return": node => {
noteDetail.focus(); noteDetailService.focus();
return false; return false;
}, },
@ -557,7 +555,7 @@ function initFancyTree(branch) {
setCurrentNotePathToHash(data.node); setCurrentNotePathToHash(data.node);
noteDetail.switchToNote(node.noteId); noteDetailService.switchToNote(node.noteId);
showParentList(node.noteId, data.node); showParentList(node.noteId, data.node);
}, },
@ -615,7 +613,7 @@ function initFancyTree(branch) {
} }
}); });
$tree.contextmenu(contextMenu.contextMenuSettings); $tree.contextmenu(contextMenuService.contextMenuSettings);
} }
async function loadSearchNote(searchNoteId) { async function loadSearchNote(searchNoteId) {
@ -768,7 +766,7 @@ async function createNote(node, parentNoteId, target, isProtected) {
// if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted
// but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often // but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often
if (!isProtected || !protected_session.isProtectedSessionAvailable()) { if (!isProtected || !protectedSessionService.isProtectedSessionAvailable()) {
isProtected = false; isProtected = false;
} }
@ -793,7 +791,7 @@ async function createNote(node, parentNoteId, target, isProtected) {
treeCache.add(note, branch); treeCache.add(note, branch);
noteDetail.newNoteCreated(); noteDetailService.newNoteCreated();
const newNode = { const newNode = {
title: newNoteName, title: newNoteName,
@ -869,7 +867,7 @@ $(document).bind('keydown', 'ctrl+p', e => {
$(document).bind('keydown', 'ctrl+del', e => { $(document).bind('keydown', 'ctrl+del', e => {
const node = getCurrentNode(); const node = getCurrentNode();
treeChanges.deleteNodes([node]); treeChangesService.deleteNodes([node]);
e.preventDefault(); e.preventDefault();
}); });

View file

@ -1,7 +1,6 @@
"use strict"; import treeService from './tree.js';
import treeService from './tree_service.js';
import utils from './utils.js'; import utils from './utils.js';
import server from './server.js';
async function moveBeforeNode(nodesToMove, beforeNode) { async function moveBeforeNode(nodesToMove, beforeNode) {
for (const nodeToMove of nodesToMove) { for (const nodeToMove of nodesToMove) {

View file

@ -1,5 +1,3 @@
"use strict";
import utils from './utils.js'; import utils from './utils.js';
const $tree = $("#tree"); const $tree = $("#tree");

View file

@ -1,7 +1,5 @@
"use strict"; import linkService from './link.js';
import messagingService from './messaging.js';
import link from './link.js';
import messaging from './messaging.js';
import ScriptContext from './script_context.js'; import ScriptContext from './script_context.js';
function reloadApp() { function reloadApp() {
@ -35,7 +33,7 @@ function showError(message, delay = 10000) {
} }
function throwError(message) { function throwError(message) {
messaging.logError(message); messagingService.logError(message);
throw new Error(message); throw new Error(message);
} }
@ -191,7 +189,7 @@ async function requireScript(url) {
async function requireCss(url) { async function requireCss(url) {
const css = Array const css = Array
.from(document.querySelectorAll('link')) .from(document.querySelectorAll('linkService'))
.map(scr => scr.href); .map(scr => scr.href);
if (!css.includes(url)) { if (!css.includes(url)) {