diff --git a/src/public/javascripts/dialogs/add_link.js b/src/public/javascripts/dialogs/add_link.js index bf44a1ce4..fbf0ab92b 100644 --- a/src/public/javascripts/dialogs/add_link.js +++ b/src/public/javascripts/dialogs/add_link.js @@ -1,9 +1,7 @@ -"use strict"; - -import treeService from '../services/tree_service.js'; -import cloning from '../services/cloning.js'; -import link from '../services/link.js'; -import noteDetail from '../services/note_detail.js'; +import treeService from '../services/tree.js'; +import cloningService from '../services/cloning.js'; +import linkService from '../services/link.js'; +import noteDetailService from '../services/note_detail.js'; import treeUtils from '../services/tree_utils.js'; const $dialog = $("#add-link-dialog"); @@ -27,7 +25,7 @@ function setLinkType(linkType) { async function showDialog() { glob.activeDialog = $dialog; - if (noteDetail.getCurrentNoteType() === 'text') { + if (noteDetailService.getCurrentNoteType() === 'text') { $linkTypeHtml.prop('disabled', false); setLinkType('html'); @@ -58,7 +56,7 @@ async function showDialog() { minLength: 0, change: () => { const val = $autoComplete.val(); - const notePath = link.getNodePathFromLabel(val); + const notePath = linkService.getNodePathFromLabel(val); if (!notePath) { return; } @@ -72,7 +70,7 @@ async function showDialog() { // 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 focus: (event, ui) => { - const notePath = link.getNodePathFromLabel(ui.item.value); + const notePath = linkService.getNodePathFromLabel(ui.item.value); const noteId = treeUtils.getNoteIdFromNotePath(notePath); setDefaultLinkTitle(noteId); @@ -83,7 +81,7 @@ async function showDialog() { $form.submit(() => { const value = $autoComplete.val(); - const notePath = link.getNodePathFromLabel(value); + const notePath = linkService.getNodePathFromLabel(value); const noteId = treeUtils.getNoteIdFromNotePath(notePath); if (notePath) { @@ -94,19 +92,19 @@ $form.submit(() => { $dialog.dialog("close"); - link.addLinkToEditor(linkTitle, '#' + notePath); + linkService.addLinkToEditor(linkTitle, '#' + notePath); } else if (linkType === 'selected-to-current') { const prefix = $clonePrefix.val(); - cloning.cloneNoteTo(noteId, noteDetail.getCurrentNoteId(), prefix); + cloningService.cloneNoteTo(noteId, noteDetailService.getCurrentNoteId(), prefix); $dialog.dialog("close"); } else if (linkType === 'current-to-selected') { const prefix = $clonePrefix.val(); - cloning.cloneNoteTo(noteDetail.getCurrentNoteId(), noteId, prefix); + cloningService.cloneNoteTo(noteDetailService.getCurrentNoteId(), noteId, prefix); $dialog.dialog("close"); } diff --git a/src/public/javascripts/dialogs/edit_tree_prefix.js b/src/public/javascripts/dialogs/edit_tree_prefix.js index 30ddb6680..157261151 100644 --- a/src/public/javascripts/dialogs/edit_tree_prefix.js +++ b/src/public/javascripts/dialogs/edit_tree_prefix.js @@ -1,6 +1,4 @@ -"use strict"; - -import treeService from '../services/tree_service.js'; +import treeService from '../services/tree.js'; const $dialog = $("#edit-tree-prefix-dialog"); const $form = $("#edit-tree-prefix-form"); diff --git a/src/public/javascripts/dialogs/event_log.js b/src/public/javascripts/dialogs/event_log.js index 675cf80fe..4916a9dbf 100644 --- a/src/public/javascripts/dialogs/event_log.js +++ b/src/public/javascripts/dialogs/event_log.js @@ -1,6 +1,4 @@ -"use strict"; - -import link from '../services/link.js'; +import linkService from '../services/link.js'; import utils from '../services/utils.js'; const $dialog = $("#event-log-dialog"); @@ -23,7 +21,7 @@ async function showDialog() { const dateTime = utils.formatDateTime(utils.parseDate(event.dateAdded)); if (event.noteId) { - const noteLink = link.createNoteLink(event.noteId).prop('outerHTML'); + const noteLink = linkService.createNoteLink(event.noteId).prop('outerHTML'); event.comment = event.comment.replace('', noteLink); } diff --git a/src/public/javascripts/dialogs/jump_to_note.js b/src/public/javascripts/dialogs/jump_to_note.js index 6d7056dfb..52b0b228f 100644 --- a/src/public/javascripts/dialogs/jump_to_note.js +++ b/src/public/javascripts/dialogs/jump_to_note.js @@ -1,7 +1,5 @@ -"use strict"; - -import treeService from '../services/tree_service.js'; -import link from '../services/link.js'; +import treeService from '../services/tree.js'; +import linkService from '../services/link.js'; import utils from '../services/utils.js'; const $showDialogButton = $("#jump-to-note-button"); @@ -27,7 +25,7 @@ async function showDialog() { function getSelectedNotePath() { const val = $autoComplete.val(); - return link.getNodePathFromLabel(val); + return linkService.getNodePathFromLabel(val); } function goToNote() { diff --git a/src/public/javascripts/dialogs/labels.js b/src/public/javascripts/dialogs/labels.js index ca6ffd5f6..1e12a3743 100644 --- a/src/public/javascripts/dialogs/labels.js +++ b/src/public/javascripts/dialogs/labels.js @@ -1,6 +1,4 @@ -"use strict"; - -import noteDetail from '../services/note_detail.js'; +import noteDetailService from '../services/note_detail.js'; import utils from '../services/utils.js'; const $showDialogButton = $(".show-labels-button"); @@ -17,7 +15,7 @@ function LabelsModel() { this.labels = ko.observableArray(); this.loadLabels = async function() { - const noteId = noteDetail.getCurrentNoteId(); + const noteId = noteDetailService.getCurrentNoteId(); const labels = await server.get('notes/' + noteId + '/labels'); @@ -81,7 +79,7 @@ function LabelsModel() { return; } - const noteId = noteDetail.getCurrentNoteId(); + const noteId = noteDetailService.getCurrentNoteId(); const labelsToSave = self.labels() .map(attr => attr()) @@ -95,7 +93,7 @@ function LabelsModel() { utils.showMessage("Labels have been saved."); - noteDetail.loadLabelList(); + noteDetailService.loadLabelList(); }; function addLastEmptyRow() { diff --git a/src/public/javascripts/dialogs/note_history.js b/src/public/javascripts/dialogs/note_history.js index 9283fb4e4..54de9b4dc 100644 --- a/src/public/javascripts/dialogs/note_history.js +++ b/src/public/javascripts/dialogs/note_history.js @@ -1,6 +1,4 @@ -"use strict"; - -import noteDetail from '../services/note_detail.js'; +import noteDetailService from '../services/note_detail.js'; import utils from '../services/utils.js'; const $showDialogButton = $("#show-history-button"); @@ -12,7 +10,7 @@ const $title = $("#note-history-title"); let historyItems = []; async function showCurrentNoteHistory() { - await showNoteHistoryDialog(noteDetail.getCurrentNoteId()); + await showNoteHistoryDialog(noteDetailService.getCurrentNoteId()); } async function showNoteHistoryDialog(noteId, noteRevisionId) { diff --git a/src/public/javascripts/dialogs/note_source.js b/src/public/javascripts/dialogs/note_source.js index f34deb522..a755c530d 100644 --- a/src/public/javascripts/dialogs/note_source.js +++ b/src/public/javascripts/dialogs/note_source.js @@ -1,6 +1,4 @@ -"use strict"; - -import noteDetail from '../services/note_detail.js'; +import noteDetailService from '../services/note_detail.js'; const $showDialogButton = $("#show-source-button"); const $dialog = $("#note-source-dialog"); @@ -15,7 +13,7 @@ function showDialog() { height: 500 }); - const noteText = noteDetail.getCurrentNote().detail.content; + const noteText = noteDetailService.getCurrentNote().detail.content; $noteSource.text(formatHtml(noteText)); } diff --git a/src/public/javascripts/dialogs/recent_changes.js b/src/public/javascripts/dialogs/recent_changes.js index d832940dd..29ce6cffd 100644 --- a/src/public/javascripts/dialogs/recent_changes.js +++ b/src/public/javascripts/dialogs/recent_changes.js @@ -1,6 +1,4 @@ -"use strict"; - -import link from '../services/link.js'; +import linkService from '../services/link.js'; import utils from '../services/utils.js'; const $showDialogButton = $("#recent-changes-button"); @@ -42,7 +40,7 @@ async function showDialog() { noteLink = change.current_title; } else { - noteLink = link.createNoteLink(change.noteId, change.title); + noteLink = linkService.createNoteLink(change.noteId, change.title); } changesListEl.append($('
  • ') diff --git a/src/public/javascripts/dialogs/recent_notes.js b/src/public/javascripts/dialogs/recent_notes.js index 4b0d34c15..1b1a56256 100644 --- a/src/public/javascripts/dialogs/recent_notes.js +++ b/src/public/javascripts/dialogs/recent_notes.js @@ -1,8 +1,6 @@ -"use strict"; - -import treeService from '../services/tree_service.js'; +import treeService from '../services/tree.js'; +import messagingService from '../services/messaging.js'; import server from '../services/server.js'; -import messaging from '../services/messaging.js'; const $showDialogButton = $("#recent-notes-button"); const $dialog = $("#recent-notes-dialog"); @@ -53,7 +51,7 @@ function showDialog() { catch (e) { 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 { diff --git a/src/public/javascripts/dialogs/settings.js b/src/public/javascripts/dialogs/settings.js index bc26ad6c3..a9adabf31 100644 --- a/src/public/javascripts/dialogs/settings.js +++ b/src/public/javascripts/dialogs/settings.js @@ -1,6 +1,6 @@ "use strict"; -import protected_session from '../services/protected_session.js'; +import protectedSessionService from '../services/protected_session.js'; import utils from '../services/utils.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."); // password changed so current protected session is invalid and needs to be cleared - protected_session.resetProtectedSession(); + protectedSessionService.resetProtectedSession(); } else { utils.showError(result.message); @@ -109,7 +109,7 @@ addModule((function() { const protectedSessionTimeout = $protectedSessionTimeout.val(); settings.saveSettings(settingName, protectedSessionTimeout).then(() => { - protected_session.setProtectedSessionTimeout(protectedSessionTimeout); + protectedSessionService.setProtectedSessionTimeout(protectedSessionTimeout); }); return false; diff --git a/src/public/javascripts/dialogs/sql_console.js b/src/public/javascripts/dialogs/sql_console.js index 75bce6db7..38a5738c1 100644 --- a/src/public/javascripts/dialogs/sql_console.js +++ b/src/public/javascripts/dialogs/sql_console.js @@ -1,5 +1,3 @@ -"use strict"; - import utils from '../services/utils.js'; const $dialog = $("#sql-console-dialog"); diff --git a/src/public/javascripts/services/bootstrap.js b/src/public/javascripts/services/bootstrap.js index 658f7560e..862dbdcd2 100644 --- a/src/public/javascripts/services/bootstrap.js +++ b/src/public/javascripts/services/bootstrap.js @@ -28,7 +28,7 @@ import utils from './utils.js'; import searchTreeService from './search_tree.js'; import './init.js'; -import treeService from './tree_service.js'; +import treeService from './tree.js'; const $toggleSearchButton = $("#toggle-search-button"); $toggleSearchButton.click(searchTreeService.toggleSearch); diff --git a/src/public/javascripts/services/cloning.js b/src/public/javascripts/services/cloning.js index a335e8499..d7e1700b0 100644 --- a/src/public/javascripts/services/cloning.js +++ b/src/public/javascripts/services/cloning.js @@ -1,6 +1,4 @@ -"use strict"; - -import treeService from './tree_service.js'; +import treeService from './tree.js'; async function cloneNoteTo(childNoteId, parentNoteId, prefix) { const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, { diff --git a/src/public/javascripts/services/context_menu.js b/src/public/javascripts/services/context_menu.js index 9f627fae9..82ee7af06 100644 --- a/src/public/javascripts/services/context_menu.js +++ b/src/public/javascripts/services/context_menu.js @@ -1,11 +1,9 @@ -"use strict"; - -import treeService from './tree_service.js'; -import cloning from './cloning.js'; +import treeService from './tree.js'; +import cloningService from './cloning.js'; import exportService from './export.js'; -import messaging from './messaging.js'; -import protected_session from './protected_session.js'; -import treeChanges from './tree_changes.js'; +import messagingService from './messaging.js'; +import protectedSessionService from './protected_session.js'; +import treeChangesService from './tree_changes.js'; import treeUtils from './tree_utils.js'; import utils from './utils.js'; @@ -18,14 +16,14 @@ async function pasteAfter(node) { if (clipboardMode === 'cut') { const nodes = clipboardIds.map(nodeKey => treeUtils.getNodeByKey(nodeKey)); - await treeChanges.moveAfterNode(nodes, node); + await treeChangesService.moveAfterNode(nodes, node); clipboardIds = []; clipboardMode = null; } else if (clipboardMode === 'copy') { 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 @@ -42,14 +40,14 @@ async function pasteInto(node) { if (clipboardMode === 'cut') { const nodes = clipboardIds.map(nodeKey => treeUtils.getNodeByKey(nodeKey)); - await treeChanges.moveToNode(nodes, node); + await treeChangesService.moveToNode(nodes, node); clipboardIds = []; clipboardMode = null; } else if (clipboardMode === 'copy') { 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 } @@ -138,10 +136,10 @@ const contextMenuSettings = { editTreePrefix.showDialog(node); } else if (ui.cmd === "protectSubTree") { - protected_session.protectSubTree(node.data.noteId, true); + protectedSessionService.protectSubTree(node.data.noteId, true); } else if (ui.cmd === "unprotectSubTree") { - protected_session.protectSubTree(node.data.noteId, false); + protectedSessionService.protectSubTree(node.data.noteId, false); } else if (ui.cmd === "copy") { copy(treeService.getSelectedNodes()); @@ -156,7 +154,7 @@ const contextMenuSettings = { pasteInto(node); } else if (ui.cmd === "delete") { - treeChanges.deleteNodes(treeService.getSelectedNodes(true)); + treeChangesService.deleteNodes(treeService.getSelectedNodes(true)); } else if (ui.cmd === "exportSubTree") { exportService.exportSubTree(node.data.noteId); @@ -174,7 +172,7 @@ const contextMenuSettings = { treeService.sortAlphabetically(node.data.noteId); } else { - messaging.logError("Unknown command: " + ui.cmd); + messagingService.logError("Unknown command: " + ui.cmd); } } }; diff --git a/src/public/javascripts/services/drag_and_drop.js b/src/public/javascripts/services/drag_and_drop.js index e01b1e51c..70a7ca45f 100644 --- a/src/public/javascripts/services/drag_and_drop.js +++ b/src/public/javascripts/services/drag_and_drop.js @@ -1,7 +1,5 @@ -"use strict"; - -import treeService from './tree_service.js'; -import treeChanges from './tree_changes.js'; +import treeService from './tree.js'; +import treeChangesService from './tree_changes.js'; const dragAndDropSetup = { autoExpandMS: 600, @@ -55,13 +53,13 @@ const dragAndDropSetup = { const selectedNodes = treeService.getSelectedNodes(); if (data.hitMode === "before") { - treeChanges.moveBeforeNode(selectedNodes, node); + treeChangesService.moveBeforeNode(selectedNodes, node); } else if (data.hitMode === "after") { - treeChanges.moveAfterNode(selectedNodes, node); + treeChangesService.moveAfterNode(selectedNodes, node); } else if (data.hitMode === "over") { - treeChanges.moveToNode(selectedNodes, node); + treeChangesService.moveToNode(selectedNodes, node); } else { throw new Exception("Unknown hitMode=" + data.hitMode); diff --git a/src/public/javascripts/services/export.js b/src/public/javascripts/services/export.js index 601c70075..5018dc384 100644 --- a/src/public/javascripts/services/export.js +++ b/src/public/javascripts/services/export.js @@ -1,12 +1,10 @@ -"use strict"; - -import treeService from './tree_service.js'; -import protected_session from './protected_session.js'; +import treeService from './tree.js'; +import protectedSessionService from './protected_session.js'; import utils from './utils.js'; function exportSubTree(noteId) { const url = utils.getHost() + "/api/export/" + noteId + "?protectedSessionId=" - + encodeURIComponent(protected_session.getProtectedSessionId()); + + encodeURIComponent(protectedSessionService.getProtectedSessionId()); utils.download(url); } diff --git a/src/public/javascripts/services/init.js b/src/public/javascripts/services/init.js index 0ba895917..0a7bc0142 100644 --- a/src/public/javascripts/services/init.js +++ b/src/public/javascripts/services/init.js @@ -1,9 +1,7 @@ -"use strict"; - -import treeService from './tree_service.js'; -import link from './link.js'; -import messaging from './messaging.js'; -import noteDetail from './note_detail.js'; +import treeService from './tree.js'; +import linkService from './link.js'; +import messagingService from './messaging.js'; +import noteDetailService from './note_detail.js'; import treeUtils from './tree_utils.js'; import utils from './utils.js'; import server from './server.js'; @@ -24,7 +22,7 @@ $(document).bind('keydown', 'alt+t', e => { const date = new Date(); const dateString = utils.formatDateTime(date); - link.addTextToEditor(dateString); + linkService.addTextToEditor(dateString); e.preventDefault(); }); @@ -107,7 +105,7 @@ $("#note-title").bind('keydown', 'return', () => $("#note-detail").focus()); $(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 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 @@ -159,12 +157,12 @@ $.ui.autocomplete.filter = (array, terms) => { $(document).tooltip({ items: "#note-detail a", content: function(callback) { - const notePath = link.getNotePathFromLink($(this).attr("href")); + const notePath = linkService.getNotePathFromLink($(this).attr("href")); if (notePath !== null) { 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) @@ -201,7 +199,7 @@ window.onerror = function (msg, url, lineNo, columnNo, error) { ].join(' - '); } - messaging.logError(message); + messagingService.logError(message); return false; }; @@ -244,7 +242,7 @@ $("#attachment-upload").change(async function() { formData.append('upload', this.files[0]); const resp = await $.ajax({ - url: baseApiUrl + 'attachments/upload/' + noteDetail.getCurrentNoteId(), + url: baseApiUrl + 'attachments/upload/' + noteDetailService.getCurrentNoteId(), headers: server.getHeaders(), data: formData, type: 'POST', diff --git a/src/public/javascripts/services/link.js b/src/public/javascripts/services/link.js index 6b40becdb..5f2a84e8c 100644 --- a/src/public/javascripts/services/link.js +++ b/src/public/javascripts/services/link.js @@ -1,7 +1,5 @@ -"use strict"; - -import treeService from './tree_service.js'; -import noteDetail from './note_detail.js'; +import treeService from './tree.js'; +import noteDetailService from './note_detail.js'; import treeUtils from './tree_utils.js'; function getNotePathFromLink(url) { @@ -77,14 +75,14 @@ function goToLink(e) { } function addLinkToEditor(linkTitle, linkHref) { - const editor = noteDetail.getEditor(); + const editor = noteDetailService.getEditor(); const doc = editor.document; doc.enqueueChanges(() => editor.data.insertLink(linkTitle, linkHref), doc.selection); } function addTextToEditor(text) { - const editor = noteDetail.getEditor(); + const editor = noteDetailService.getEditor(); const doc = editor.document; doc.enqueueChanges(() => editor.data.insertText(text), doc.selection); diff --git a/src/public/javascripts/services/messaging.js b/src/public/javascripts/services/messaging.js index 8b3c7ba31..b5a930582 100644 --- a/src/public/javascripts/services/messaging.js +++ b/src/public/javascripts/services/messaging.js @@ -1,9 +1,7 @@ -"use strict"; - -import treeService from './tree_service.js'; +import treeService from './tree.js'; import noteDetailService from './note_detail.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"); @@ -54,7 +52,7 @@ function messageHandler(event) { if (syncData.some(sync => sync.entityName === 'recent_notes')) { 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 diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 48be3ed68..8c43cda0f 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -1,8 +1,6 @@ -"use strict"; - -import treeService from './tree_service.js'; -import noteType from './note_type.js'; -import protected_session from './protected_session.js'; +import treeService from './tree.js'; +import noteTypeService from './note_type.js'; +import protectedSessionService from './protected_session.js'; import utils from './utils.js'; import server from './server.js'; @@ -80,7 +78,7 @@ async function saveNoteIfChanged() { await saveNoteToServer(note); if (note.detail.isProtected) { - protected_session.touchProtectedSession(); + protectedSessionService.touchProtectedSession(); } } @@ -221,15 +219,15 @@ async function loadNoteToEditor(noteId) { $noteIdDisplay.html(noteId); - await protected_session.ensureProtectedSession(currentNote.detail.isProtected, false); + await protectedSessionService.ensureProtectedSession(currentNote.detail.isProtected, false); 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 // 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(); @@ -237,8 +235,8 @@ async function loadNoteToEditor(noteId) { $noteTitle.val(currentNote.detail.title); - noteType.setNoteType(currentNote.detail.type); - noteType.setNoteMime(currentNote.detail.mime); + noteTypeService.setNoteType(currentNote.detail.type); + noteTypeService.setNoteMime(currentNote.detail.mime); $noteDetail.hide(); $noteDetailSearch.hide(); @@ -362,7 +360,7 @@ $attachmentOpen.click(() => { function getAttachmentUrl() { // electron needs absolute URL so we extract current host, port, protocol return utils.getHost() + "/api/attachments/download/" + getCurrentNoteId() - + "?protectedSessionId=" + encodeURIComponent(protected_session.getProtectedSessionId()); + + "?protectedSessionId=" + encodeURIComponent(protectedSessionService.getProtectedSessionId()); } $(document).ready(() => { diff --git a/src/public/javascripts/services/note_type.js b/src/public/javascripts/services/note_type.js index 344887a2d..0c23ff364 100644 --- a/src/public/javascripts/services/note_type.js +++ b/src/public/javascripts/services/note_type.js @@ -1,6 +1,4 @@ -"use strict"; - -import treeService from './tree_service.js'; +import treeService from './tree.js'; import noteDetail from './note_detail.js'; import utils from './utils.js'; diff --git a/src/public/javascripts/services/protected_session.js b/src/public/javascripts/services/protected_session.js index 1eb041977..ae67a4508 100644 --- a/src/public/javascripts/services/protected_session.js +++ b/src/public/javascripts/services/protected_session.js @@ -1,6 +1,4 @@ -"use strict"; - -import treeService from './tree_service.js'; +import treeService from './tree.js'; import noteDetail from './note_detail.js'; import utils from './utils.js'; import server from './server.js'; diff --git a/src/public/javascripts/services/script_api.js b/src/public/javascripts/services/script_api.js index 0f4b10c4d..a4640988a 100644 --- a/src/public/javascripts/services/script_api.js +++ b/src/public/javascripts/services/script_api.js @@ -1,4 +1,4 @@ -import treeService from './tree_service.js'; +import treeService from './tree.js'; function ScriptApi(startNote, currentNote) { const $pluginButtons = $("#plugin-buttons"); diff --git a/src/public/javascripts/services/script_context.js b/src/public/javascripts/services/script_context.js index 0b77b037f..7b60e22df 100644 --- a/src/public/javascripts/services/script_context.js +++ b/src/public/javascripts/services/script_context.js @@ -1,5 +1,3 @@ -"use strict"; - import ScriptApi from './script_api.js'; import utils from './utils.js'; diff --git a/src/public/javascripts/services/search_tree.js b/src/public/javascripts/services/search_tree.js index bf9e759ff..a141cc96e 100644 --- a/src/public/javascripts/services/search_tree.js +++ b/src/public/javascripts/services/search_tree.js @@ -1,6 +1,4 @@ -"use strict"; - -import treeService from './tree_service.js'; +import treeService from './tree.js'; const $tree = $("#tree"); const $searchInput = $("input[name='search-text']"); diff --git a/src/public/javascripts/services/server.js b/src/public/javascripts/services/server.js index 9463edd7c..133737395 100644 --- a/src/public/javascripts/services/server.js +++ b/src/public/javascripts/services/server.js @@ -1,13 +1,11 @@ -"use strict"; - -import protected_session from './protected_session.js'; +import protectedSessionService from './protected_session.js'; import utils from './utils.js'; function getHeaders() { let protectedSessionId = null; 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) {} diff --git a/src/public/javascripts/services/sync.js b/src/public/javascripts/services/sync.js index faa431c74..7dd6cbde0 100644 --- a/src/public/javascripts/services/sync.js +++ b/src/public/javascripts/services/sync.js @@ -1,5 +1,3 @@ -"use strict"; - import utils from './utils.js'; async function syncNow() { diff --git a/src/public/javascripts/services/tree_service.js b/src/public/javascripts/services/tree.js similarity index 93% rename from src/public/javascripts/services/tree_service.js rename to src/public/javascripts/services/tree.js index c77cafb97..0a5b04d76 100644 --- a/src/public/javascripts/services/tree_service.js +++ b/src/public/javascripts/services/tree.js @@ -1,16 +1,14 @@ -"use strict"; - -import contextMenu from './context_menu.js'; +import contextMenuService from './context_menu.js'; import dragAndDropSetup from './drag_and_drop.js'; -import link from './link.js'; -import messaging from './messaging.js'; -import noteDetail from './note_detail.js'; -import protected_session from './protected_session.js'; -import treeChanges from './tree_changes.js'; +import linkService from './link.js'; +import messagingService from './messaging.js'; +import noteDetailService from './note_detail.js'; +import protectedSessionService from './protected_session.js'; +import treeChangesService from './tree_changes.js'; import treeUtils from './tree_utils.js'; import utils from './utils.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'; const $tree = $("#tree"); @@ -146,7 +144,7 @@ async function prepareBranchInner(parentNote) { const childBranches = await parentNote.getChildBranches(); if (!childBranches) { - messaging.logError(`No children for ${parentNote}. This shouldn't happen.`); + messagingService.logError(`No children for ${parentNote}. This shouldn't happen.`); return; } @@ -245,7 +243,7 @@ async function getRunPath(notePath) { const parents = await child.getParentNotes(); if (!parents) { - messaging.logError("No parents found for " + childNoteId); + messagingService.logError("No parents found for " + childNoteId); return; } @@ -268,7 +266,7 @@ async function getRunPath(notePath) { break; } else { - messaging.logError("No parents, can't activate node."); + messagingService.logError("No parents, can't activate node."); return; } } @@ -315,7 +313,7 @@ async function showParentList(noteId, node) { item = $("").attr("title", "Current note").append(title); } else { - item = link.createNoteLink(notePath, title); + item = linkService.createNoteLink(notePath, title); } $parentListList.append($("
  • ").append(item)); @@ -377,7 +375,7 @@ function setCurrentNotePathToHash(node) { document.location.hash = currentNotePath; - recentNotes.addRecentNote(currentBranchId, currentNotePath); + recentNotesDialog.addRecentNote(currentBranchId, currentNotePath); } function getSelectedNodes(stopOnParents = false) { @@ -401,13 +399,13 @@ function initFancyTree(branch) { const keybindings = { "del": node => { - treeChanges.deleteNodes(getSelectedNodes(true)); + treeChangesService.deleteNodes(getSelectedNodes(true)); }, "ctrl+up": node => { const beforeNode = node.getPrevSibling(); if (beforeNode !== null) { - treeChanges.moveBeforeNode([node], beforeNode); + treeChangesService.moveBeforeNode([node], beforeNode); } return false; @@ -415,13 +413,13 @@ function initFancyTree(branch) { "ctrl+down": node => { let afterNode = node.getNextSibling(); if (afterNode !== null) { - treeChanges.moveAfterNode([node], afterNode); + treeChangesService.moveAfterNode([node], afterNode); } return false; }, "ctrl+left": node => { - treeChanges.moveNodeUpInHierarchy(node); + treeChangesService.moveNodeUpInHierarchy(node); return false; }, @@ -429,7 +427,7 @@ function initFancyTree(branch) { let toNode = node.getPrevSibling(); if (toNode !== null) { - treeChanges.moveToNode([node], toNode); + treeChangesService.moveToNode([node], toNode); } return false; @@ -479,22 +477,22 @@ function initFancyTree(branch) { return false; }, "ctrl+c": () => { - contextMenu.copy(getSelectedNodes()); + contextMenuService.copy(getSelectedNodes()); return false; }, "ctrl+x": () => { - contextMenu.cut(getSelectedNodes()); + contextMenuService.cut(getSelectedNodes()); return false; }, "ctrl+v": node => { - contextMenu.pasteInto(node); + contextMenuService.pasteInto(node); return false; }, "return": node => { - noteDetail.focus(); + noteDetailService.focus(); return false; }, @@ -557,7 +555,7 @@ function initFancyTree(branch) { setCurrentNotePathToHash(data.node); - noteDetail.switchToNote(node.noteId); + noteDetailService.switchToNote(node.noteId); showParentList(node.noteId, data.node); }, @@ -615,7 +613,7 @@ function initFancyTree(branch) { } }); - $tree.contextmenu(contextMenu.contextMenuSettings); + $tree.contextmenu(contextMenuService.contextMenuSettings); } 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 // 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; } @@ -793,7 +791,7 @@ async function createNote(node, parentNoteId, target, isProtected) { treeCache.add(note, branch); - noteDetail.newNoteCreated(); + noteDetailService.newNoteCreated(); const newNode = { title: newNoteName, @@ -869,7 +867,7 @@ $(document).bind('keydown', 'ctrl+p', e => { $(document).bind('keydown', 'ctrl+del', e => { const node = getCurrentNode(); - treeChanges.deleteNodes([node]); + treeChangesService.deleteNodes([node]); e.preventDefault(); }); diff --git a/src/public/javascripts/services/tree_changes.js b/src/public/javascripts/services/tree_changes.js index 7aae9e70b..74183e585 100644 --- a/src/public/javascripts/services/tree_changes.js +++ b/src/public/javascripts/services/tree_changes.js @@ -1,7 +1,6 @@ -"use strict"; - -import treeService from './tree_service.js'; +import treeService from './tree.js'; import utils from './utils.js'; +import server from './server.js'; async function moveBeforeNode(nodesToMove, beforeNode) { for (const nodeToMove of nodesToMove) { diff --git a/src/public/javascripts/services/tree_utils.js b/src/public/javascripts/services/tree_utils.js index bd15439ed..4f189aa4d 100644 --- a/src/public/javascripts/services/tree_utils.js +++ b/src/public/javascripts/services/tree_utils.js @@ -1,5 +1,3 @@ -"use strict"; - import utils from './utils.js'; const $tree = $("#tree"); diff --git a/src/public/javascripts/services/utils.js b/src/public/javascripts/services/utils.js index 5ec6c7a76..80d2b7011 100644 --- a/src/public/javascripts/services/utils.js +++ b/src/public/javascripts/services/utils.js @@ -1,7 +1,5 @@ -"use strict"; - -import link from './link.js'; -import messaging from './messaging.js'; +import linkService from './link.js'; +import messagingService from './messaging.js'; import ScriptContext from './script_context.js'; function reloadApp() { @@ -35,7 +33,7 @@ function showError(message, delay = 10000) { } function throwError(message) { - messaging.logError(message); + messagingService.logError(message); throw new Error(message); } @@ -191,7 +189,7 @@ async function requireScript(url) { async function requireCss(url) { const css = Array - .from(document.querySelectorAll('link')) + .from(document.querySelectorAll('linkService')) .map(scr => scr.href); if (!css.includes(url)) {