Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
wip
zadamc778e8768373
diff --git a/src/public/app/entities/attribute.js b/src/public/app/entities/attribute.jsindex d7a42b4ecf..61254592ba 100644--- a/src/public/app/entities/attribute.js+++ b/src/public/app/entities/attribute.js@@ -56,6 +56,10 @@ class Attribute {* 3. attribute is owned by some note's ancestor and is inheritable*/isAffecting(affectedNote) {+ if (!affectedNote) {+ return false;+ }+const attrNote = this.getNote();const owningNotes = [affectedNote, ...affectedNote.getTemplateNotes()];diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.jsindex 6bbb54bc30..8687142806 100644--- a/src/public/app/entities/note_short.js+++ b/src/public/app/entities/note_short.js@@ -180,22 +180,9 @@ class NoteShort {return [];}- if (!(this.noteId in noteAttributeCache)) {- const ownedAttributes = this.getOwnedAttributes();-- const attrArrs = [- ownedAttributes- ];-+ if (!(this.noteId in noteAttributeCache.attributes)) {const newPath = [...path, this.noteId];-- for (const templateAttr of ownedAttributes.filter(oa => oa.type === 'relation' && oa.name === 'template')) {- const templateNote = this.treeCache.notes[templateAttr.value];-- if (templateNote && templateNote.noteId !== this.noteId) {- attrArrs.push(templateNote.__getCachedAttributes(newPath));- }- }+ const attrArrs = [ this.getOwnedAttributes() ];if (this.noteId !== 'root') {for (const parentNote of this.getParentNotes()) {@@ -206,6 +193,14 @@ class NoteShort {}}+ for (const templateAttr of attrArrs.flat().filter(attr => attr.type === 'relation' && attr.name === 'template')) {+ const templateNote = this.treeCache.notes[templateAttr.value];++ if (templateNote && templateNote.noteId !== this.noteId) {+ attrArrs.push(templateNote.__getCachedAttributes(newPath));+ }+ }+noteAttributeCache.attributes[this.noteId] = attrArrs.flat();}diff --git a/src/public/app/widgets/note_attributes.js b/src/public/app/widgets/note_attributes.jsindex af7beda7e6..34cc83b929 100644--- a/src/public/app/widgets/note_attributes.js+++ b/src/public/app/widgets/note_attributes.js@@ -157,7 +157,7 @@ const TPL = `<div class="attr-display"><div class="note-attributes-editor" tabindex="200"></div>- <hr class="w-100 attr-inherited-empty-expander">+ <hr class="w-100 attr-inherited-empty-expander" style="margin-bottom: 10px;"><div class="attr-expander attr-inherited-expander"><hr class="w-100">@@ -394,10 +394,9 @@ export default class NoteAttributesWidget extends TabAwareWidget {this.textEditor.setData($attributesContainer.html());});- const inheritedAttributes = note.getAttributes().filter(attr => attr.isInheritable && attr.noteId !== this.noteId);- const inheritedAttributeCount = inheritedAttributes.length;-- if (inheritedAttributeCount === 0) {+ const inheritedAttributes = note.getAttributes().filter(attr => attr.noteId !== this.noteId);+console.log("inheritedAttributes", inheritedAttributes);+ if (inheritedAttributes.length === 0) {this.$inheritedExpander.hide();this.$inheritedEmptyExpander.show();}@@ -406,7 +405,7 @@ export default class NoteAttributesWidget extends TabAwareWidget {this.$inheritedEmptyExpander.hide();}- this.$inheritedExpanderText.text(inheritedAttributeCount + ' inherited ' + this.attrPlural(inheritedAttributeCount));+ this.$inheritedExpanderText.text(inheritedAttributes.length + ' inherited ' + this.attrPlural(inheritedAttributes.length));await this.renderAttributes(inheritedAttributes, this.$inheritedAttributes);}diff --git a/src/routes/api/import.js b/src/routes/api/import.jsindex 80c76b8a43..6687255155 100644--- a/src/routes/api/import.js+++ b/src/routes/api/import.js@@ -12,7 +12,7 @@ const noteCacheService = require('../../services/note_cache/note_cache.js');const log = require('../../services/log');const TaskContext = require('../../services/task_context.js');-function importToBranch(req) {+async function importToBranch(req) {const {parentNoteId} = req.params;const {taskId, last} = req.body;@@ -49,19 +49,15 @@ function importToBranch(req) {try {if (extension === '.tar' && options.explodeArchives) {- note = tarImportService.importTar(taskContext, file.buffer, parentNote);+ note = await tarImportService.importTar(taskContext, file.buffer, parentNote);} else if (extension === '.zip' && options.explodeArchives) {- const start = Date.now();-- note = zipImportService.importZip(taskContext, file.buffer, parentNote);-- console.log("Import took", Date.now() - start, "ms");+ note = await zipImportService.importZip(taskContext, file.buffer, parentNote);} else if (extension === '.opml' && options.explodeArchives) {- note = opmlImportService.importOpml(taskContext, file.buffer, parentNote);+ note = await opmlImportService.importOpml(taskContext, file.buffer, parentNote);} else if (extension === '.enex' && options.explodeArchives) {- note = enexImportService.importEnex(taskContext, file, parentNote);+ note = await enexImportService.importEnex(taskContext, file, parentNote);} else {- note = singleImportService.importSingleFile(taskContext, file, parentNote);+ note = await singleImportService.importSingleFile(taskContext, file, parentNote);}}catch (e) {@@ -83,8 +79,8 @@ function importToBranch(req) {// import has deactivated note events so note cache is not updated// instead we force it to reload (can be async)- // FIXME- //noteCacheService.load();++ noteCacheService.load();return note;}diff --git a/src/services/attributes.js b/src/services/attributes.jsindex bb227314c9..9f10b79634 100644--- a/src/services/attributes.js+++ b/src/services/attributes.js@@ -5,7 +5,7 @@ const sql = require('./sql');const utils = require('./utils');const Attribute = require('../entities/attribute');-const ATTRIBUTE_TYPES = [ 'label', 'label-definition', 'relation', 'relation-definition' ];+const ATTRIBUTE_TYPES = [ 'label', 'relation' ];const BUILTIN_ATTRIBUTES = [// label namesdiff --git a/src/services/import/tar.js b/src/services/import/tar.jsindex c668bcd7d1..b375918092 100644--- a/src/services/import/tar.js+++ b/src/services/import/tar.js@@ -23,7 +23,7 @@ const treeService = require("../tree");* @param {Note} importRootNote* @return {Promise<*>}*/-function importTar(taskContext, fileBuffer, importRootNote) {+async function importTar(taskContext, fileBuffer, importRootNote) {// maps from original noteId (in tar file) to newly generated noteIdconst noteIdMap = {};const attributes = [];diff --git a/src/services/import/zip.js b/src/services/import/zip.jsindex 18a0b77ca9..fcd3541dec 100644--- a/src/services/import/zip.js+++ b/src/services/import/zip.js@@ -21,7 +21,7 @@ const yauzl = require("yauzl");* @param {Note} importRootNote* @return {Promise<*>}*/-function importZip(taskContext, fileBuffer, importRootNote) {+async function importZip(taskContext, fileBuffer, importRootNote) {// maps from original noteId (in tar file) to newly generated noteIdconst noteIdMap = {};const attributes = [];@@ -133,6 +133,15 @@ function importZip(taskContext, fileBuffer, importRootNote) {for (const attr of noteMeta.attributes) {attr.noteId = note.noteId;+ if (attr.type === 'label-definition') {+ attr.type = 'label';+ attr.name = 'label:' + attr.name;+ }+ else if (attr.type === 'relation-definition') {+ attr.type = 'label';+ attr.name = 'relation:' + attr.name;+ }+if (!attributeService.isAttributeType(attr.type)) {log.error("Unrecognized attribute type " + attr.type);continue;@@ -405,11 +414,11 @@ function importZip(taskContext, fileBuffer, importRootNote) {// we're running two passes to make sure that the meta file is loaded before the rest of the files is processed.- readZipFile(fileBuffer, (zipfile, entry) => {+ await readZipFile(fileBuffer, async (zipfile, entry) => {const filePath = normalizeFilePath(entry.fileName);if (filePath === '!!!meta.json') {- const content = readContent(zipfile, entry);+ const content = await readContent(zipfile, entry);metaFile = JSON.parse(content.toString("UTF-8"));}@@ -417,14 +426,14 @@ function importZip(taskContext, fileBuffer, importRootNote) {zipfile.readEntry();});- readZipFile(fileBuffer, (zipfile, entry) => {+ await readZipFile(fileBuffer, async (zipfile, entry) => {const filePath = normalizeFilePath(entry.fileName);if (/\/$/.test(entry.fileName)) {saveDirectory(filePath);}else if (filePath !== '!!!meta.json') {- const content = readContent(zipfile, entry);+ const content = await readContent(zipfile, entry);saveNote(filePath, content);}diff --git a/src/services/note_cache/entities/attribute.js b/src/services/note_cache/entities/attribute.jsindex 73ae80e860..b9103df4c8 100644--- a/src/services/note_cache/entities/attribute.js+++ b/src/services/note_cache/entities/attribute.js@@ -13,7 +13,7 @@ class Attribute {/** @param {string} */this.name = row.name.toLowerCase();/** @param {string} */- this.value = row.type === 'label'? row.value.toLowerCase() : row.value;+ this.value = row.type === 'label' ? row.value.toLowerCase() : row.value;/** @param {boolean} */this.isInheritable = !!row.isInheritable;