mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	converted NoteRevision entity to the becca
This commit is contained in:
		| @@ -7,6 +7,7 @@ const noteRevisionService = require('../../services/note_revisions'); | ||||
| const utils = require('../../services/utils'); | ||||
| const sql = require('../../services/sql'); | ||||
| const path = require('path'); | ||||
| const becca = require("../../services/becca/becca.js"); | ||||
|  | ||||
| function getNoteRevisions(req) { | ||||
|     return repository.getEntities(` | ||||
| @@ -19,11 +20,11 @@ function getNoteRevisions(req) { | ||||
| } | ||||
|  | ||||
| function getNoteRevision(req) { | ||||
|     const noteRevision = repository.getNoteRevision(req.params.noteRevisionId); | ||||
|     const noteRevision = becca.getNoteRevision(req.params.noteRevisionId); | ||||
|  | ||||
|     if (noteRevision.type === 'file') { | ||||
|         if (noteRevision.isStringNote()) { | ||||
|             noteRevision.content = (noteRevision.getContent()).substr(0, 10000); | ||||
|             noteRevision.content = noteRevision.getContent().substr(0, 10000); | ||||
|         } | ||||
|     } | ||||
|     else { | ||||
| @@ -62,7 +63,7 @@ function getRevisionFilename(noteRevision) { | ||||
| } | ||||
|  | ||||
| function downloadNoteRevision(req, res) { | ||||
|     const noteRevision = repository.getNoteRevision(req.params.noteRevisionId); | ||||
|     const noteRevision = becca.getNoteRevision(req.params.noteRevisionId); | ||||
|  | ||||
|     if (noteRevision.noteId !== req.params.noteId) { | ||||
|         return res.status(400).send(`Note revision ${req.params.noteRevisionId} does not belong to note ${req.params.noteId}`); | ||||
| @@ -92,7 +93,7 @@ function eraseNoteRevision(req) { | ||||
| } | ||||
|  | ||||
| function restoreNoteRevision(req) { | ||||
|     const noteRevision = repository.getNoteRevision(req.params.noteRevisionId); | ||||
|     const noteRevision = becca.getNoteRevision(req.params.noteRevisionId); | ||||
|  | ||||
|     if (noteRevision) { | ||||
|         const note = noteRevision.getNote(); | ||||
|   | ||||
| @@ -23,7 +23,7 @@ function getNotesAndBranchesAndAttributes(noteIds) { | ||||
|         } | ||||
|  | ||||
|         for (const childNote of note.children) { | ||||
|             const childBranch = becca.getBranch(childNote.noteId, note.noteId); | ||||
|             const childBranch = becca.getBranchFromChildAndParent(childNote.noteId, note.noteId); | ||||
|  | ||||
|             collectedBranchIds.add(childBranch.branchId); | ||||
|         } | ||||
| @@ -127,7 +127,7 @@ function getTree(req) { | ||||
|         for (const childNote of parentNote.children) { | ||||
|             collectedNoteIds.add(childNote.noteId); | ||||
|  | ||||
|             const childBranch = becca.getBranch(childNote.noteId, parentNote.noteId); | ||||
|             const childBranch = becca.getBranchFromChildAndParent(childNote.noteId, parentNote.noteId); | ||||
|  | ||||
|             if (childBranch.isExpanded) { | ||||
|                 collect(childBranch.childNote); | ||||
|   | ||||
| @@ -1,5 +1,8 @@ | ||||
| "use strict"; | ||||
|  | ||||
| const sql = require("../sql.js"); | ||||
| const NoteRevision = require("./entities/note_revision.js"); | ||||
|  | ||||
| class Becca { | ||||
|     constructor() { | ||||
|         this.reset(); | ||||
| @@ -45,9 +48,27 @@ class Becca { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     getBranch(childNoteId, parentNoteId) { | ||||
|     getNote(noteId) { | ||||
|         return this.notes[noteId]; | ||||
|     } | ||||
|  | ||||
|     getBranch(branchId) { | ||||
|         return this.branches[branchId]; | ||||
|     } | ||||
|  | ||||
|     getAttribute(attributeId) { | ||||
|         return this.attributes[attributeId]; | ||||
|     } | ||||
|  | ||||
|     getBranchFromChildAndParent(childNoteId, parentNoteId) { | ||||
|         return this.childParentToBranch[`${childNoteId}-${parentNoteId}`]; | ||||
|     } | ||||
|  | ||||
|     getNoteRevision(noteRevisionId) { | ||||
|         const row = sql.getRow("SELECT * FROM note_revisions WHERE noteRevisionId = ?", [noteRevisionId]); | ||||
|  | ||||
|         return row ? new NoteRevision(row) : null; | ||||
|     } | ||||
| } | ||||
|  | ||||
| const becca = new Becca(); | ||||
|   | ||||
| @@ -80,7 +80,7 @@ function getNoteTitle(childNoteId, parentNoteId) { | ||||
|         title = childNote.title; | ||||
|     } | ||||
|  | ||||
|     const branch = parentNote ? becca.getBranch(childNote.noteId, parentNote.noteId) : null; | ||||
|     const branch = parentNote ? becca.getBranchFromChildAndParent(childNote.noteId, parentNote.noteId) : null; | ||||
|  | ||||
|     return ((branch && branch.prefix) ? `${branch.prefix} - ` : '') + title; | ||||
| } | ||||
| @@ -175,7 +175,7 @@ function getNotePath(noteId) { | ||||
|  | ||||
|         return { | ||||
|             noteId: noteId, | ||||
|             branchId: becca.getBranch(noteId, parentNote.noteId).branchId, | ||||
|             branchId: becca.getBranchFromChildAndParent(noteId, parentNote.noteId).branchId, | ||||
|             title: noteTitle, | ||||
|             notePath: retPath, | ||||
|             path: retPath.join('/') | ||||
|   | ||||
| @@ -107,7 +107,7 @@ class Note extends AbstractEntity { | ||||
|     } | ||||
|  | ||||
|     getChildBranches() { | ||||
|         return this.children.map(childNote => this.becca.getBranch(childNote.noteId, this.noteId)); | ||||
|         return this.children.map(childNote => this.becca.getBranchFromChildAndParent(childNote.noteId, this.noteId)); | ||||
|     } | ||||
|  | ||||
|     /* | ||||
|   | ||||
		Reference in New Issue
	
	Block a user