mirror of
https://github.com/zadam/trilium.git
synced 2025-11-07 13:56:11 +01:00
added progress also to export
This commit is contained in:
@@ -2,6 +2,8 @@ import treeService from '../services/tree.js';
|
||||
import treeUtils from "../services/tree_utils.js";
|
||||
import utils from "../services/utils.js";
|
||||
import protectedSessionHolder from "../services/protected_session_holder.js";
|
||||
import messagingService from "../services/messaging.js";
|
||||
import infoService from "../services/info.js";
|
||||
|
||||
const $dialog = $("#export-dialog");
|
||||
const $form = $("#export-form");
|
||||
@@ -10,8 +12,18 @@ 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 $exportButton = $("#export-button");
|
||||
|
||||
let exportId = '';
|
||||
|
||||
async function showDialog(defaultType) {
|
||||
// each opening of the dialog resets the exportId so we don't associate it with previous exports anymore
|
||||
exportId = '';
|
||||
$exportNoteCountWrapper.hide();
|
||||
$exportNoteCount.text('0');
|
||||
|
||||
if (defaultType === 'subtree') {
|
||||
$subtreeType.prop("checked", true).change();
|
||||
}
|
||||
@@ -33,6 +45,8 @@ async function showDialog(defaultType) {
|
||||
}
|
||||
|
||||
$form.submit(() => {
|
||||
$exportButton.attr("disabled", "disabled");
|
||||
|
||||
const exportType = $dialog.find("input[name='export-type']:checked").val();
|
||||
|
||||
if (!exportType) {
|
||||
@@ -49,13 +63,13 @@ $form.submit(() => {
|
||||
|
||||
exportBranch(currentNode.data.branchId, exportType, exportFormat);
|
||||
|
||||
$dialog.modal('hide');
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
function exportBranch(branchId, type, format) {
|
||||
const url = utils.getHost() + `/api/notes/${branchId}/export/${type}/${format}?protectedSessionId=` + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
|
||||
exportId = utils.randomString(10);
|
||||
|
||||
const url = utils.getHost() + `/api/notes/${branchId}/export/${type}/${format}/${exportId}?protectedSessionId=` + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
|
||||
|
||||
utils.download(url);
|
||||
}
|
||||
@@ -79,6 +93,30 @@ $('input[name=export-type]').change(function () {
|
||||
}
|
||||
});
|
||||
|
||||
messagingService.subscribeToMessages(async message => {
|
||||
if (message.type === 'export-error') {
|
||||
infoService.showError(message.message);
|
||||
$dialog.modal('hide');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!message.exportId || message.exportId !== exportId) {
|
||||
// incoming messages must correspond to this export instance
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === 'export-progress-count') {
|
||||
$exportNoteCountWrapper.show();
|
||||
|
||||
$exportNoteCount.text(message.progressCount);
|
||||
}
|
||||
else if (message.type === 'export-finished') {
|
||||
$dialog.modal('hide');
|
||||
|
||||
infoService.showMessage("Export finished successfully.");
|
||||
}
|
||||
});
|
||||
|
||||
export default {
|
||||
showDialog
|
||||
};
|
||||
@@ -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-note-count-wrapper");
|
||||
const $importNoteCount = $("#import-note-count");
|
||||
const $importNoteCountWrapper = $("#import-progress-count-wrapper");
|
||||
const $importNoteCount = $("#import-progress-count");
|
||||
const $importButton = $("#import-button");
|
||||
|
||||
let importId;
|
||||
@@ -74,10 +74,10 @@ messagingService.subscribeToMessages(async message => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === 'import-note-count') {
|
||||
if (message.type === 'import-progress-count') {
|
||||
$importNoteCountWrapper.show();
|
||||
|
||||
$importNoteCount.text(message.count);
|
||||
$importNoteCount.text(message.progressCount);
|
||||
}
|
||||
else if (message.type === 'import-finished') {
|
||||
$dialog.modal('hide');
|
||||
|
||||
Reference in New Issue
Block a user