From caa7dd9619dc025809434f7cb1603596c861ba07 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 10 Feb 2019 22:56:14 +0100 Subject: [PATCH] prettier progress count --- src/public/javascripts/dialogs/export.js | 12 ++++++------ src/public/javascripts/dialogs/import.js | 12 ++++++------ src/routes/api/export.js | 2 +- src/routes/api/import.js | 8 ++++---- src/services/import/tar.js | 1 - src/views/dialogs/export.ejs | 8 ++++---- src/views/dialogs/import.ejs | 8 ++++---- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/public/javascripts/dialogs/export.js b/src/public/javascripts/dialogs/export.js index 332a362f6..abb408009 100644 --- a/src/public/javascripts/dialogs/export.js +++ b/src/public/javascripts/dialogs/export.js @@ -12,8 +12,8 @@ const $subtreeFormats = $("#export-subtree-formats"); const $singleFormats = $("#export-single-formats"); const $subtreeType = $("#export-type-subtree"); const $singleType = $("#export-type-single"); -const $exportNoteCountWrapper = $("#export-progress-count-wrapper"); -const $exportNoteCount = $("#export-progress-count"); +const $exportProgressWrapper = $("#export-progress-count-wrapper"); +const $exportProgressCount = $("#export-progress-count"); const $exportButton = $("#export-button"); let exportId = ''; @@ -22,8 +22,8 @@ async function showDialog(defaultType) { // each opening of the dialog resets the exportId so we don't associate it with previous exports anymore exportId = ''; $exportButton.removeAttr("disabled"); - $exportNoteCountWrapper.hide(); - $exportNoteCount.text('0'); + $exportProgressWrapper.hide(); + $exportProgressCount.text('0'); if (defaultType === 'subtree') { $subtreeType.prop("checked", true).change(); @@ -108,9 +108,9 @@ messagingService.subscribeToMessages(async message => { } if (message.type === 'export-progress-count') { - $exportNoteCountWrapper.show(); + $exportProgressWrapper.slideDown(); - $exportNoteCount.text(message.progressCount); + $exportProgressCount.text(message.progressCount); } else if (message.type === 'export-finished') { $dialog.modal('hide'); diff --git a/src/public/javascripts/dialogs/import.js b/src/public/javascripts/dialogs/import.js index 905d178e3..d94a1fc0b 100644 --- a/src/public/javascripts/dialogs/import.js +++ b/src/public/javascripts/dialogs/import.js @@ -9,8 +9,8 @@ const $dialog = $("#import-dialog"); const $form = $("#import-form"); const $noteTitle = $dialog.find(".note-title"); const $fileUploadInput = $("#import-file-upload-input"); -const $importNoteCountWrapper = $("#import-progress-count-wrapper"); -const $importNoteCount = $("#import-progress-count"); +const $importProgressCountWrapper = $("#import-progress-count-wrapper"); +const $importProgressCount = $("#import-progress-count"); const $importButton = $("#import-button"); let importId; @@ -18,8 +18,8 @@ let importId; async function showDialog() { // each opening of the dialog resets the importId so we don't associate it with previous imports anymore importId = ''; - $importNoteCountWrapper.hide(); - $importNoteCount.text('0'); + $importProgressCountWrapper.hide(); + $importProgressCount.text('0'); $fileUploadInput.val('').change(); // to trigger Import button disabling listener below glob.activeDialog = $dialog; @@ -75,9 +75,9 @@ messagingService.subscribeToMessages(async message => { } if (message.type === 'import-progress-count') { - $importNoteCountWrapper.show(); + $importProgressCountWrapper.slideDown(); - $importNoteCount.text(message.progressCount); + $importProgressCount.text(message.progressCount); } else if (message.type === 'import-finished') { $dialog.modal('hide'); diff --git a/src/routes/api/export.js b/src/routes/api/export.js index 304c5b920..521587267 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -20,7 +20,7 @@ class ExportContext { async increaseProgressCount() { this.progressCount++; - if (Date.now() - this.lastSentCountTs >= 200) { + if (Date.now() - this.lastSentCountTs >= 500) { this.lastSentCountTs = Date.now(); await messagingService.sendMessageToAllClients({ diff --git a/src/routes/api/import.js b/src/routes/api/import.js index ec63abd8f..23c7eaa14 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -17,20 +17,20 @@ class ImportContext { // to have multiple imports going at the same time this.importId = importId; // // count is mean to represent count of exported notes where practical, otherwise it's just some measure of progress - this.count = 0; + this.progressCount = 0; this.lastSentCountTs = Date.now(); } async increaseProgressCount() { - this.count++; + this.progressCount++; - if (Date.now() - this.lastSentCountTs >= 200) { + if (Date.now() - this.lastSentCountTs >= 500) { this.lastSentCountTs = Date.now(); await messagingService.sendMessageToAllClients({ importId: this.importId, type: 'import-progress-count', - count: this.count + progressCount: this.progressCount }); } } diff --git a/src/services/import/tar.js b/src/services/import/tar.js index 98483e322..cca223e2d 100644 --- a/src/services/import/tar.js +++ b/src/services/import/tar.js @@ -24,7 +24,6 @@ let lastSentCountTs = Date.now(); */ async function importTar(importContext, fileBuffer, importRootNote) { importNoteCount = 0; - throw new Error("Hello"); // maps from original noteId (in tar file) to newly generated noteId const noteIdMap = {}; const attributes = []; diff --git a/src/views/dialogs/export.ejs b/src/views/dialogs/export.ejs index 9f31007a6..30c933756 100644 --- a/src/views/dialogs/export.ejs +++ b/src/views/dialogs/export.ejs @@ -9,6 +9,10 @@
- -
- Note export progress count: -
- -
- Note import progress count: -