changing title directly from relation map

This commit is contained in:
azivner 2018-10-30 22:18:20 +01:00
parent f33f99134b
commit 639284fd85
6 changed files with 38 additions and 6 deletions

View File

@ -36,9 +36,14 @@ class Note extends Entity {
super(row);
this.isProtected = !!this.isProtected;
/* true if content (meaning any kind of potentially encrypted content) is either not encrypted
* or encrypted, but with available protected session (so effectively decrypted) */
this.isContentAvailable = true;
// check if there's noteId, otherwise this is a new entity which wasn't encrypted yet
if (this.isProtected && this.noteId) {
this.isContentAvailable = protectedSessionService.isProtectedSessionAvailable();
protectedSessionService.decryptNote(this);
}

View File

@ -2,6 +2,7 @@ import server from "./server.js";
import noteDetailService from "./note_detail.js";
import linkService from "./link.js";
import libraryLoader from "./library_loader.js";
import treeService from "./tree.js";
const $noteDetailRelationMap = $("#note-detail-relation-map");
const $relationMapCanvas = $("#relation-map-canvas");
@ -267,18 +268,18 @@ async function noteContextMenuHandler(event, ui) {
saveData();
}
else if (ui.cmd === "edit-title") {
const title = prompt("Enter new note title:");
const $title = $noteBox.find(".title a");
const title = prompt("Enter new note title:", $title.text());
if (!title) {
return;
}
const note = mapData.notes.find(note => note.id === noteId);
note.title = title;
await server.put(`notes/${noteId}/change-title`, { title });
$noteBox.find(".title").text(note.title);
treeService.setNoteTitle(noteId, title);
saveData();
$title.text(title);
}
}

View File

@ -122,6 +122,25 @@ async function getRelationMap(req) {
return resp;
}
async function changeTitle(req) {
const noteId = req.params.noteId;
const title = req.body.title;
const note = await repository.getNote(noteId);
if (!note) {
return [404, `Note ${noteId} has not been found`];
}
if (!note.isContentAvailable) {
return [400, `Note ${noteId} is not available for change`];
}
note.title = title;
await note.save();
}
module.exports = {
getNote,
updateNote,
@ -130,5 +149,6 @@ module.exports = {
protectSubtree,
setNoteTypeMime,
getChildren,
getRelationMap
getRelationMap,
changeTitle
};

View File

@ -122,6 +122,7 @@ function register(app) {
apiRoute(PUT, /\/api\/notes\/(.*)\/type\/(.*)\/mime\/(.*)/, notesApiRoute.setNoteTypeMime);
apiRoute(GET, '/api/notes/:noteId/revisions', noteRevisionsApiRoute.getNoteRevisions);
apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap);
apiRoute(PUT, '/api/notes/:noteId/change-title', notesApiRoute.changeTitle);
apiRoute(PUT, '/api/notes/:noteId/clone-to/:parentNoteId', cloningApiRoute.cloneNoteToParent);
apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter);

View File

@ -222,6 +222,10 @@ async function saveNoteRevision(note) {
async function updateNote(noteId, noteUpdates) {
const note = await repository.getNote(noteId);
if (!note.isContentAvailable) {
throw new Error(`Note ${noteId} is not available for change!`);
}
if (note.type === 'file') {
// for update file, newNote doesn't contain file payloads
noteUpdates.content = note.content;

View File

@ -78,6 +78,7 @@ async function updateEntity(entity) {
delete clone.isOwned;
delete clone.isChanged;
delete clone.origParentNoteId;
delete clone.isContentAvailable;
delete clone.__attributeCache;
for (const key in clone) {