allow also deleting note when removing note from note relation

This commit is contained in:
azivner 2018-11-14 23:30:28 +01:00
parent fa264d1cbe
commit 8ee8639faa
6 changed files with 67 additions and 7 deletions

View file

@ -2,10 +2,15 @@ const $dialog = $("#confirm-dialog");
const $confirmContent = $("#confirm-dialog-content"); const $confirmContent = $("#confirm-dialog-content");
const $okButton = $("#confirm-dialog-ok-button"); const $okButton = $("#confirm-dialog-ok-button");
const $cancelButton = $("#confirm-dialog-cancel-button"); const $cancelButton = $("#confirm-dialog-cancel-button");
const $custom = $("#confirm-dialog-custom");
const DELETE_NOTE_BUTTON_ID = "confirm-dialog-delete-note";
let resolve; let resolve;
function confirm(message) { function confirm(message) {
$custom.hide();
glob.activeDialog = $dialog; glob.activeDialog = $dialog;
$confirmContent.text(message); $confirmContent.text(message);
@ -15,6 +20,35 @@ function confirm(message) {
return new Promise((res, rej) => { resolve = res; }); return new Promise((res, rej) => { resolve = res; });
} }
function confirmDeleteNoteBoxWithNote(title) {
glob.activeDialog = $dialog;
$confirmContent.text(`Are you sure you want to remove the note "${title}" from relation map?`);
$custom.empty()
.append("<br/>")
.append($("<div>").addClass("form-check")
.append($("<input>")
.attr("id", DELETE_NOTE_BUTTON_ID)
.attr("type", "checkbox")
.addClass("form-check-input"))
.append($("<label>")
.attr("for", DELETE_NOTE_BUTTON_ID)
.addClass("form-check-label")
.attr("style", "text-decoration: underline dotted black")
.attr("title", "If you don't check this, note will be only removed from relation map, but will stay as a note.")
.html("Also delete note")));
$custom.show();
$dialog.modal();
return new Promise((res, rej) => { resolve = res; });
}
function isDeleteNoteChecked() {
return $("#" + DELETE_NOTE_BUTTON_ID + ":checked").length > 0;
}
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus")); $dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
$dialog.on("hidden.bs.modal", () => { $dialog.on("hidden.bs.modal", () => {
@ -34,5 +68,7 @@ $cancelButton.click(() => doResolve(false));
$okButton.click(() => doResolve(true)); $okButton.click(() => doResolve(true));
export default { export default {
confirm confirm,
confirmDeleteNoteBoxWithNote,
isDeleteNoteChecked
} }

View file

@ -13,7 +13,7 @@ const dragAndDropSetup = {
const selectedNodes = treeService.getSelectedNodes().map(node => { const selectedNodes = treeService.getSelectedNodes().map(node => {
return { return {
noteId: node.data.noteId, noteId: node.data.noteId,
title: node.data.title title: node.title
} }
}); });

View file

@ -382,15 +382,23 @@ $relationMapContainer.on("contextmenu", ".note-box", e => {
async function noteContextMenuHandler(event, cmd) { async function noteContextMenuHandler(event, cmd) {
const $noteBox = $(event.originalTarget).closest(".note-box"); const $noteBox = $(event.originalTarget).closest(".note-box");
const $title = $noteBox.find(".title a");
const noteId = idToNoteId($noteBox.prop("id")); const noteId = idToNoteId($noteBox.prop("id"));
if (cmd === "remove") { if (cmd === "remove") {
if (!await confirmDialog.confirm("Are you sure you want to remove the note from this diagram?")) { if (!await confirmDialog.confirmDeleteNoteBoxWithNote($title.text())) {
return; return;
} }
jsPlumbInstance.remove(noteIdToId(noteId)); jsPlumbInstance.remove(noteIdToId(noteId));
if (confirmDialog.isDeleteNoteChecked()) {
await server.remove("notes/" + noteId);
// to force it to disappear from the tree
treeService.reload();
}
mapData.notes = mapData.notes.filter(note => note.noteId !== noteId); mapData.notes = mapData.notes.filter(note => note.noteId !== noteId);
relations = relations.filter(relation => relation.sourceNoteId !== noteId && relation.targetNoteId !== noteId); relations = relations.filter(relation => relation.sourceNoteId !== noteId && relation.targetNoteId !== noteId);
@ -398,8 +406,10 @@ async function noteContextMenuHandler(event, cmd) {
saveData(); saveData();
} }
else if (cmd === "edit-title") { else if (cmd === "edit-title") {
const $title = $noteBox.find(".title a"); const title = await promptDialog.ask({
const title = await promptDialog.ask({ message: "Enter new note title:", defaultValue: $title.text() }); message: "Enter new note title:",
defaultValue: $title.text()
});
if (!title) { if (!title) {
return; return;
@ -471,7 +481,7 @@ async function refresh() {
let clipboard = null; let clipboard = null;
$createChildNote.click(async () => { $createChildNote.click(async () => {
const title = await promptDialog.ask("Enter title of new note", "new note"); const title = await promptDialog.ask({ message: "Enter title of new note", defaultValue: "new note" });
if (!title.trim()) { if (!title.trim()) {
return; return;
@ -528,7 +538,7 @@ async function dropNoteOntoRelationMapHandler(ev) {
continue; continue;
} }
mapData.notes.push({id: note.noteId, x, y}); mapData.notes.push({noteId: note.noteId, x, y});
if (x - startX > 1000) { if (x - startX > 1000) {
x = startX; x = startX;

View file

@ -66,6 +66,16 @@ async function updateNote(req) {
await noteService.updateNote(noteId, note); await noteService.updateNote(noteId, note);
} }
async function deleteNote(req) {
const noteId = req.params.noteId;
const note = await repository.getNote(noteId);
for (const branch of await note.getBranches()) {
await noteService.deleteNote(branch);
}
}
async function sortNotes(req) { async function sortNotes(req) {
const noteId = req.params.noteId; const noteId = req.params.noteId;
@ -165,6 +175,7 @@ async function changeTitle(req) {
module.exports = { module.exports = {
getNote, getNote,
updateNote, updateNote,
deleteNote,
createNote, createNote,
sortNotes, sortNotes,
protectSubtree, protectSubtree,

View file

@ -115,6 +115,7 @@ function register(app) {
apiRoute(GET, '/api/notes/:noteId', notesApiRoute.getNote); apiRoute(GET, '/api/notes/:noteId', notesApiRoute.getNote);
apiRoute(PUT, '/api/notes/:noteId', notesApiRoute.updateNote); apiRoute(PUT, '/api/notes/:noteId', notesApiRoute.updateNote);
apiRoute(DELETE, '/api/notes/:noteId', notesApiRoute.deleteNote);
apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote); apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote);
apiRoute(GET, '/api/notes/:parentNoteId/children', notesApiRoute.getChildren); apiRoute(GET, '/api/notes/:parentNoteId/children', notesApiRoute.getChildren);
apiRoute(PUT, '/api/notes/:noteId/sort', notesApiRoute.sortNotes); apiRoute(PUT, '/api/notes/:noteId/sort', notesApiRoute.sortNotes);

View file

@ -10,6 +10,8 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div id="confirm-dialog-content"></div> <div id="confirm-dialog-content"></div>
<div id="confirm-dialog-custom"></div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-default btn-sm" id="confirm-dialog-cancel-button">Cancel</button> <button class="btn btn-default btn-sm" id="confirm-dialog-cancel-button">Cancel</button>