mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
converted NoteRevision entity to the becca
This commit is contained in:
parent
d8f1c39282
commit
e466c393eb
@ -7,6 +7,7 @@ const noteRevisionService = require('../../services/note_revisions');
|
|||||||
const utils = require('../../services/utils');
|
const utils = require('../../services/utils');
|
||||||
const sql = require('../../services/sql');
|
const sql = require('../../services/sql');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const becca = require("../../services/becca/becca.js");
|
||||||
|
|
||||||
function getNoteRevisions(req) {
|
function getNoteRevisions(req) {
|
||||||
return repository.getEntities(`
|
return repository.getEntities(`
|
||||||
@ -19,11 +20,11 @@ function getNoteRevisions(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getNoteRevision(req) {
|
function getNoteRevision(req) {
|
||||||
const noteRevision = repository.getNoteRevision(req.params.noteRevisionId);
|
const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);
|
||||||
|
|
||||||
if (noteRevision.type === 'file') {
|
if (noteRevision.type === 'file') {
|
||||||
if (noteRevision.isStringNote()) {
|
if (noteRevision.isStringNote()) {
|
||||||
noteRevision.content = (noteRevision.getContent()).substr(0, 10000);
|
noteRevision.content = noteRevision.getContent().substr(0, 10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -62,7 +63,7 @@ function getRevisionFilename(noteRevision) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function downloadNoteRevision(req, res) {
|
function downloadNoteRevision(req, res) {
|
||||||
const noteRevision = repository.getNoteRevision(req.params.noteRevisionId);
|
const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);
|
||||||
|
|
||||||
if (noteRevision.noteId !== req.params.noteId) {
|
if (noteRevision.noteId !== req.params.noteId) {
|
||||||
return res.status(400).send(`Note revision ${req.params.noteRevisionId} does not belong to note ${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) {
|
function restoreNoteRevision(req) {
|
||||||
const noteRevision = repository.getNoteRevision(req.params.noteRevisionId);
|
const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);
|
||||||
|
|
||||||
if (noteRevision) {
|
if (noteRevision) {
|
||||||
const note = noteRevision.getNote();
|
const note = noteRevision.getNote();
|
||||||
|
@ -23,7 +23,7 @@ function getNotesAndBranchesAndAttributes(noteIds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const childNote of note.children) {
|
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);
|
collectedBranchIds.add(childBranch.branchId);
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ function getTree(req) {
|
|||||||
for (const childNote of parentNote.children) {
|
for (const childNote of parentNote.children) {
|
||||||
collectedNoteIds.add(childNote.noteId);
|
collectedNoteIds.add(childNote.noteId);
|
||||||
|
|
||||||
const childBranch = becca.getBranch(childNote.noteId, parentNote.noteId);
|
const childBranch = becca.getBranchFromChildAndParent(childNote.noteId, parentNote.noteId);
|
||||||
|
|
||||||
if (childBranch.isExpanded) {
|
if (childBranch.isExpanded) {
|
||||||
collect(childBranch.childNote);
|
collect(childBranch.childNote);
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const sql = require("../sql.js");
|
||||||
|
const NoteRevision = require("./entities/note_revision.js");
|
||||||
|
|
||||||
class Becca {
|
class Becca {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.reset();
|
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}`];
|
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();
|
const becca = new Becca();
|
||||||
|
@ -80,7 +80,7 @@ function getNoteTitle(childNoteId, parentNoteId) {
|
|||||||
title = childNote.title;
|
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;
|
return ((branch && branch.prefix) ? `${branch.prefix} - ` : '') + title;
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ function getNotePath(noteId) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
noteId: noteId,
|
noteId: noteId,
|
||||||
branchId: becca.getBranch(noteId, parentNote.noteId).branchId,
|
branchId: becca.getBranchFromChildAndParent(noteId, parentNote.noteId).branchId,
|
||||||
title: noteTitle,
|
title: noteTitle,
|
||||||
notePath: retPath,
|
notePath: retPath,
|
||||||
path: retPath.join('/')
|
path: retPath.join('/')
|
||||||
|
@ -107,7 +107,7 @@ class Note extends AbstractEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getChildBranches() {
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user