mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 09:45:52 +01:00
becca conversion WIP
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
const utils = require('../../utils');
|
||||
|
||||
let becca = null;
|
||||
let repo = null;
|
||||
|
||||
class AbstractEntity {
|
||||
@@ -30,6 +31,15 @@ class AbstractEntity {
|
||||
return this.utcDateModified || this.utcDateCreated || "FAKE";
|
||||
}
|
||||
|
||||
get becca() {
|
||||
if (!becca) {
|
||||
becca = require('../becca');
|
||||
}
|
||||
|
||||
return becca;
|
||||
}
|
||||
|
||||
// temporarily needed for saving entities
|
||||
get repository() {
|
||||
if (!repo) {
|
||||
repo = require('../../repository');
|
||||
|
||||
@@ -11,11 +11,9 @@ class Attribute extends AbstractEntity {
|
||||
static get primaryKeyName() { return "attributeId"; }
|
||||
static get hashedProperties() { return ["attributeId", "noteId", "type", "name", "value", "isInheritable"]; }
|
||||
|
||||
constructor(becca, row) {
|
||||
constructor(row) {
|
||||
super();
|
||||
|
||||
/** @param {Becca} */
|
||||
this.becca = becca;
|
||||
/** @param {string} */
|
||||
this.attributeId = row.attributeId;
|
||||
/** @param {string} */
|
||||
@@ -74,7 +72,7 @@ class Attribute extends AbstractEntity {
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
getNote() {
|
||||
return this.repository.getNote(this.noteId);
|
||||
return this.becca.getNote(this.noteId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +87,7 @@ class Attribute extends AbstractEntity {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.repository.getNote(this.value);
|
||||
return this.becca.getNote(this.value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,11 +11,9 @@ class Branch extends AbstractEntity {
|
||||
// notePosition is not part of hash because it would produce a lot of updates in case of reordering
|
||||
static get hashedProperties() { return ["branchId", "noteId", "parentNoteId", "prefix"]; }
|
||||
|
||||
constructor(becca, row) {
|
||||
constructor(row) {
|
||||
super();
|
||||
|
||||
/** @param {Becca} */
|
||||
this.becca = becca;
|
||||
/** @param {string} */
|
||||
this.branchId = row.branchId;
|
||||
/** @param {string} */
|
||||
|
||||
@@ -17,12 +17,9 @@ class Note extends AbstractEntity {
|
||||
static get primaryKeyName() { return "noteId"; }
|
||||
static get hashedProperties() { return ["noteId", "title", "isProtected", "type", "mime"]; }
|
||||
|
||||
constructor(becca, row) {
|
||||
constructor(row) {
|
||||
super();
|
||||
|
||||
/** @param {Becca} */
|
||||
this.becca = becca;
|
||||
|
||||
this.update(row);
|
||||
|
||||
/** @param {Branch[]} */
|
||||
|
||||
@@ -2,7 +2,6 @@ const becca = require('./becca.js');
|
||||
const log = require('../log');
|
||||
const beccaService = require('./becca_service.js');
|
||||
const dateUtils = require('../date_utils');
|
||||
const repository = require('../repository');
|
||||
const { JSDOM } = require("jsdom");
|
||||
|
||||
const DEBUG = false;
|
||||
@@ -124,8 +123,7 @@ function buildRewardMap(note) {
|
||||
}
|
||||
|
||||
if (note.type === 'text' && note.isDecrypted) {
|
||||
const noteEntity = repository.getNote(note.noteId);
|
||||
const content = noteEntity.getContent();
|
||||
const content = note.getContent();
|
||||
const dom = new JSDOM(content);
|
||||
|
||||
function addHeadingsToRewardMap(elName, rewardFactor) {
|
||||
|
||||
@@ -111,7 +111,7 @@ function createNewNote(params) {
|
||||
}
|
||||
|
||||
return sql.transactional(() => {
|
||||
const note = new BeccaNote(becca,{
|
||||
const note = new BeccaNote({
|
||||
noteId: params.noteId, // optionally can force specific noteId
|
||||
title: params.title,
|
||||
isProtected: !!params.isProtected,
|
||||
@@ -121,7 +121,7 @@ function createNewNote(params) {
|
||||
|
||||
note.setContent(params.content);
|
||||
|
||||
const branch = new BeccaBranch(becca,{
|
||||
const branch = new BeccaBranch({
|
||||
noteId: note.noteId,
|
||||
parentNoteId: params.parentNoteId,
|
||||
notePosition: params.notePosition !== undefined ? params.notePosition : getNewNotePosition(params.parentNoteId),
|
||||
@@ -799,7 +799,7 @@ function duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapp
|
||||
|
||||
const newNoteId = noteIdMapping[origNote.noteId];
|
||||
|
||||
const newBranch = new BeccaBranch(becca,{
|
||||
const newBranch = new BeccaBranch({
|
||||
noteId: newNoteId,
|
||||
parentNoteId: newParentNoteId,
|
||||
// here increasing just by 1 to make sure it's directly after original
|
||||
@@ -817,7 +817,7 @@ function duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapp
|
||||
}
|
||||
}
|
||||
|
||||
const newNote = new BeccaNote(becca, origNote);
|
||||
const newNote = new BeccaNote(origNote);
|
||||
newNote.noteId = newNoteId;
|
||||
newNote.dateCreated = dateUtils.localNowDateTime();
|
||||
newNote.utcDateCreated = dateUtils.utcNowDateTime();
|
||||
@@ -833,7 +833,7 @@ function duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapp
|
||||
newNote.setContent(content);
|
||||
|
||||
for (const attribute of origNote.getOwnedAttributes()) {
|
||||
const attr = new BeccaAttribute(becca, attribute);
|
||||
const attr = new BeccaAttribute(attribute);
|
||||
attr.attributeId = undefined; // force creation of new attribute
|
||||
attr.noteId = newNote.noteId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user