Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
more changes to import reporting through WS
zadam5baa25194463
diff --git a/src/public/javascripts/dialogs/import.js b/src/public/javascripts/dialogs/import.jsindex 29e4cb3a9d..27b9629ae0 100644--- a/src/public/javascripts/dialogs/import.js+++ b/src/public/javascripts/dialogs/import.js@@ -10,11 +10,12 @@ const $noteTitle = $dialog.find(".note-title");const $fileUploadInput = $("#import-file-upload-input");const $importNoteCountWrapper = $("#import-note-count-wrapper");const $importNoteCount = $("#import-note-count");+const $importButton = $("#import-button");async function showDialog() {$importNoteCountWrapper.hide();$importNoteCount.text('0');- $fileUploadInput.val('');+ $fileUploadInput.val('').change(); // to trigger Import button disabling listener belowglob.activeDialog = $dialog;@@ -27,6 +28,9 @@ async function showDialog() {$form.submit(() => {const currentNode = treeService.getCurrentNode();+ // disabling so that import is not triggered again.+ $importButton.attr("disabled", "disabled");+importIntoNote(currentNode.data.noteId);return false;@@ -45,27 +49,37 @@ function importIntoNote(importNoteId) {contentType: false, // NEEDED, DON'T REMOVE THISprocessData: false, // NEEDED, DON'T REMOVE THIS})- .fail((xhr, status, error) => alert('Import error: ' + xhr.responseText))- .done(async note => {- $dialog.modal('hide');+ // we actually ignore the error since it can be caused by HTTP timeout and use WS messages instead.+ .fail((xhr, status, error) => {});+}- infoService.showMessage("Import finished successfully.");+messagingService.subscribeToMessages(async message => {+ if (message.type === 'import-note-count') {+ $importNoteCountWrapper.show();- await treeService.reload();+ $importNoteCount.text(message.count);+ }+ else if (message.type === 'import-finished') {+ $dialog.modal('hide');- if (note) {- const node = await treeService.activateNote(note.noteId);+ infoService.showMessage("Import finished successfully.");- node.setExpanded(true);- }- });-}+ await treeService.reload();-messagingService.subscribeToMessages(message => {- if (message.type === 'importNoteCount') {- $importNoteCountWrapper.show();+ if (message.noteId) {+ const node = await treeService.activateNote(message.noteId);- $importNoteCount.text(message.count);+ node.setExpanded(true);+ }+ }+});++$fileUploadInput.change(() => {+ if ($fileUploadInput.val()) {+ $importButton.removeAttr("disabled");+ }+ else {+ $importButton.attr("disabled", "disabled");}});diff --git a/src/services/import/tar.js b/src/services/import/tar.jsindex bc792ccab6..add0d6243d 100644--- a/src/services/import/tar.js+++ b/src/services/import/tar.js@@ -342,7 +342,7 @@ async function importTar(fileBuffer, importRootNote) {if (Date.now() - lastSentCountTs >= 1000) {lastSentCountTs = Date.now();- messagingService.sendMessageToAllClients({ type: 'importNoteCount', count: importNoteCount });+ messagingService.importNoteCount(importNoteCount);}next(); // ready for next entry@@ -379,6 +379,8 @@ async function importTar(fileBuffer, importRootNote) {}}+ messagingService.importFinished(firstNote);+resolve(firstNote);});diff --git a/src/services/messaging.js b/src/services/messaging.jsindex 6006e02b52..9c7f5c598d 100644--- a/src/services/messaging.js+++ b/src/services/messaging.js@@ -49,10 +49,6 @@ async function sendMessage(client, message) {}}-async function refreshTree() {- await sendMessageToAllClients({ type: 'refresh-tree' });-}-async function sendMessageToAllClients(message) {const jsonStr = JSON.stringify(message);@@ -78,8 +74,22 @@ async function sendPing(client, lastSentSyncId) {});}+async function refreshTree() {+ await sendMessageToAllClients({ type: 'refresh-tree' });+}++async function importNoteCount(count) {+ await sendMessageToAllClients({ type: 'import-note-count', count: count });+}++async function importFinished(firstNote) {+ await sendMessageToAllClients({ type: 'import-finished', noteId: firstNote.noteId });+}+module.exports = {init,+ sendMessageToAllClients,refreshTree,- sendMessageToAllClients+ importNoteCount,+ importFinished};\ No newline at end of filediff --git a/src/views/dialogs/import.ejs b/src/views/dialogs/import.ejsindex ed226724d5..02bdf4d0f6 100644--- a/src/views/dialogs/import.ejs+++ b/src/views/dialogs/import.ejs@@ -14,7 +14,7 @@<input type="file" id="import-file-upload-input" class="form-control-file" />- <p>File will be imported as child note(s) into <strong class="note-title"></strong>. Import file must be of supported type and have correct extension - one of <code>.html</code>, <code>.md</code>, <code>.tar</code>, <code>.enex</code>.</p>+ <p>Content of the file will be imported as child note(s) into <strong class="note-title"></strong>. Import file must be of supported type and have correct extension - one of <code>.html</code>, <code>.md</code>, <code>.tar</code>, <code>.enex</code>.</p></div><div class="form-group">@@ -33,7 +33,7 @@</div></div><div class="modal-footer">- <button class="btn btn-primary">Import</button>+ <button class="btn btn-primary" id="import-button">Import</button></div></form></div>