added getAllNotePaths, fixes #708

This commit is contained in:
zadam
2019-11-16 19:07:32 +01:00
parent 95d0ad1cad
commit 1838f097e5
20 changed files with 662 additions and 290 deletions

View File

@@ -49,6 +49,7 @@ const RELATION_DEFINITION = 'relation-definition';
* @property {string} type - one of "text", "code", "file" or "render"
* @property {string} mime - MIME type, e.g. "text/html"
* @property {string} title - note title
* @property {int} contentLength - length of content
* @property {boolean} isProtected - true if note is protected
* @property {boolean} isDeleted - true if note is deleted
* @property {boolean} isErased - true if note's content is erased after it has been deleted
@@ -143,6 +144,7 @@ class Note extends Entity {
async setContent(content) {
// force updating note itself so that dateModified is represented correctly even for the content
this.forcedChange = true;
this.contentLength = content.length;
await this.save();
this.content = content;
@@ -754,6 +756,26 @@ class Note extends Entity {
AND parent_notes.isDeleted = 0`, [this.noteId]);
}
/**
* @return {Promise<string[][]>} - array of notePaths (each represented by array of noteIds constituting the particular note path)
*/
async getAllNotePaths() {
if (this.noteId === 'root') {
return [['root']];
}
const notePaths = [];
for (const parentNote of await this.getParentNotes()) {
for (const parentPath of await parentNote.getAllNotePaths()) {
parentPath.push(this.noteId);
notePaths.push(parentPath);
}
}
return notePaths;
}
beforeSaving() {
if (!this.isDeleted) {
this.isDeleted = false;
@@ -767,6 +789,10 @@ class Note extends Entity {
this.utcDateCreated = dateUtils.utcNowDateTime();
}
if (this.contentLength === undefined) {
this.contentLength = -1;
}
super.beforeSaving();
if (this.isChanged) {