mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
delete notes dialog WIP
This commit is contained in:
parent
76aa7d1451
commit
d62558d97a
@ -1,30 +1,31 @@
|
|||||||
import server from "../services/server.js";
|
import server from "../services/server.js";
|
||||||
import treeCache from "../services/tree_cache.js";
|
import treeCache from "../services/tree_cache.js";
|
||||||
import linkService from "../services/link.js";
|
import linkService from "../services/link.js";
|
||||||
|
import utils from "../services/utils.js";
|
||||||
|
|
||||||
const $dialog = $("#delete-notes-dialog");
|
const $dialog = $("#delete-notes-dialog");
|
||||||
const $confirmContent = $("#delete-notes-dialog-content");
|
|
||||||
const $okButton = $("#delete-notes-dialog-ok-button");
|
const $okButton = $("#delete-notes-dialog-ok-button");
|
||||||
const $cancelButton = $("#delete-notes-dialog-cancel-button");
|
const $cancelButton = $("#delete-notes-dialog-cancel-button");
|
||||||
const $custom = $("#delete-notes-dialog-custom");
|
|
||||||
const $deleteNotesList = $("#delete-notes-list");
|
const $deleteNotesList = $("#delete-notes-list");
|
||||||
const $brokenRelationsList = $("#broken-relations-list");
|
const $brokenRelationsList = $("#broken-relations-list");
|
||||||
const $deletedNotesCount = $("#deleted-notes-count");
|
const $deletedNotesCount = $("#deleted-notes-count");
|
||||||
const $noNoteToDeleteWrapper = $("#no-note-to-delete-wrapper");
|
const $noNoteToDeleteWrapper = $("#no-note-to-delete-wrapper");
|
||||||
const $deleteNotesListWrapper = $("#delete-notes-list-wrapper");
|
const $deleteNotesListWrapper = $("#delete-notes-list-wrapper");
|
||||||
const $brokenRelationsListWrapper = $("#broken-relations-wrapper");
|
const $brokenRelationsListWrapper = $("#broken-relations-wrapper");
|
||||||
|
const $brokenRelationsCount = $("#broke-relations-count");
|
||||||
|
|
||||||
const DELETE_NOTE_BUTTON_ID = "delete-notes-dialog-delete-note";
|
const DELETE_NOTE_BUTTON_ID = "delete-notes-dialog-delete-note";
|
||||||
|
|
||||||
let $originallyFocused; // element focused before the dialog was opened so we can return to it afterwards
|
let $originallyFocused; // element focused before the dialog was opened so we can return to it afterwards
|
||||||
|
|
||||||
|
let branchIds = null;
|
||||||
|
let resolve = null;
|
||||||
|
|
||||||
export async function showDialog(branchIdsToDelete) {
|
export async function showDialog(branchIdsToDelete) {
|
||||||
|
branchIds = branchIdsToDelete;
|
||||||
|
|
||||||
$originallyFocused = $(':focus');
|
$originallyFocused = $(':focus');
|
||||||
|
|
||||||
$custom.hide();
|
|
||||||
|
|
||||||
glob.activeDialog = $dialog;
|
|
||||||
|
|
||||||
const response = await server.post('delete-notes-preview', {branchIdsToDelete});
|
const response = await server.post('delete-notes-preview', {branchIdsToDelete});
|
||||||
|
|
||||||
$deleteNotesList.empty();
|
$deleteNotesList.empty();
|
||||||
@ -44,6 +45,7 @@ export async function showDialog(branchIdsToDelete) {
|
|||||||
$deletedNotesCount.text(response.noteIdsToBeDeleted.length);
|
$deletedNotesCount.text(response.noteIdsToBeDeleted.length);
|
||||||
|
|
||||||
$brokenRelationsListWrapper.toggle(response.brokenRelations.length > 0);
|
$brokenRelationsListWrapper.toggle(response.brokenRelations.length > 0);
|
||||||
|
$brokenRelationsCount.text(response.brokenRelations.length);
|
||||||
|
|
||||||
await treeCache.getNotes(response.brokenRelations.map(br => br.noteId));
|
await treeCache.getNotes(response.brokenRelations.map(br => br.noteId));
|
||||||
|
|
||||||
@ -57,9 +59,9 @@ export async function showDialog(branchIdsToDelete) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dialog.modal();
|
utils.openDialog($dialog);
|
||||||
|
|
||||||
return new Promise((res, rej) => { resolve = res; });
|
return new Promise((res, rej) => resolve = res);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDeleteNoteChecked() {
|
export function isDeleteNoteChecked() {
|
||||||
@ -68,23 +70,17 @@ export function isDeleteNoteChecked() {
|
|||||||
|
|
||||||
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
|
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
|
||||||
|
|
||||||
$dialog.on("hidden.bs.modal", () => {
|
$cancelButton.on('click', () => {
|
||||||
if (resolve) {
|
utils.closeActiveDialog();
|
||||||
resolve(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($originallyFocused) {
|
resolve({proceed: false});
|
||||||
$originallyFocused.trigger('focus');
|
|
||||||
$originallyFocused = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function doResolve(ret) {
|
$okButton.on('click', () => {
|
||||||
resolve(ret);
|
utils.closeActiveDialog();
|
||||||
resolve = null;
|
|
||||||
|
|
||||||
$dialog.modal("hide");
|
resolve({
|
||||||
}
|
proceed: true,
|
||||||
|
deleteClones: false
|
||||||
$cancelButton.on('click', () => doResolve(false));
|
});
|
||||||
$okButton.on('click', () => doResolve(true));
|
});
|
||||||
|
@ -75,31 +75,12 @@ async function deleteNotes(branchIdsToDelete) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deleteNotesDialog = await import("../dialogs/delete_notes.js");
|
const deleteNotesDialog = await import("../dialogs/delete_notes.js");
|
||||||
deleteNotesDialog.showDialog(branchIdsToDelete);
|
const {proceed, deleteClones} = await deleteNotesDialog.showDialog(branchIdsToDelete);
|
||||||
|
|
||||||
const $deleteClonesCheckbox = $('<div class="form-check">')
|
if (!proceed) {
|
||||||
.append($('<input type="checkbox" class="form-check-input" id="delete-clones-checkbox">'))
|
return false;
|
||||||
.append($('<label for="delete-clones-checkbox">')
|
|
||||||
.text("Also delete all note clones")
|
|
||||||
.attr("title", "all clones of selected notes will be deleted and as such the whole note will be deleted."));
|
|
||||||
|
|
||||||
const $nodeTitles = $("<ul>");
|
|
||||||
|
|
||||||
for (const branchId of branchIdsToDelete) {
|
|
||||||
const note = await treeCache.getBranch(branchId).getNote();
|
|
||||||
|
|
||||||
$nodeTitles.append($("<li>").text(note.title));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const $confirmText = $("<div>")
|
|
||||||
.append($("<p>").text('This will delete the following notes and their sub-notes: '))
|
|
||||||
.append($nodeTitles)
|
|
||||||
.append($deleteClonesCheckbox);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const deleteClones = $deleteClonesCheckbox.find("input").is(":checked");
|
|
||||||
|
|
||||||
const taskId = utils.randomString(10);
|
const taskId = utils.randomString(10);
|
||||||
|
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
|
@ -256,7 +256,7 @@ function getDeleteNotesPreview(req) {
|
|||||||
|
|
||||||
let brokenRelations = [];
|
let brokenRelations = [];
|
||||||
|
|
||||||
if (noteIdsToBeDeleted.length > 0) {
|
if (noteIdsToBeDeleted.size > 0) {
|
||||||
sql.fillParamList(noteIdsToBeDeleted);
|
sql.fillParamList(noteIdsToBeDeleted);
|
||||||
|
|
||||||
brokenRelations = sql.getRows(`
|
brokenRelations = sql.getRows(`
|
||||||
|
@ -12,19 +12,19 @@
|
|||||||
<div id="delete-notes-list-wrapper">
|
<div id="delete-notes-list-wrapper">
|
||||||
<h5>Following notes will be deleted (<span id="deleted-notes-count"></span>)</h5>
|
<h5>Following notes will be deleted (<span id="deleted-notes-count"></span>)</h5>
|
||||||
|
|
||||||
<ul id="delete-notes-list" style="max-height: 400px; overflow: auto;"></ul>
|
<ul id="delete-notes-list" style="max-height: 300px; overflow: auto;"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="no-note-to-delete-wrapper">
|
<div id="no-note-to-delete-wrapper" class="alert alert-info">
|
||||||
<strong>No note will be deleted (only clones).</strong>
|
No note will be deleted (only clones).
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="broken-relations-wrapper">
|
<div id="broken-relations-wrapper">
|
||||||
<h5>Broken relations</h5>
|
<div class="alert alert-danger">
|
||||||
|
<h5>Following relations will be broken and deleted (<span id="broke-relations-count"></span>)</h5>
|
||||||
|
|
||||||
Below can be seen relations which will be broken after notes mentioned above are deleted.
|
<ul id="broken-relations-list" style="max-height: 300px; overflow: auto;"></ul>
|
||||||
|
</div>
|
||||||
<ul id="broken-relations-list" style="max-height: 400px; overflow: auto;"></ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user