mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
wip
This commit is contained in:
parent
dd62b306fd
commit
c778e87683
@ -56,6 +56,10 @@ class Attribute {
|
|||||||
* 3. attribute is owned by some note's ancestor and is inheritable
|
* 3. attribute is owned by some note's ancestor and is inheritable
|
||||||
*/
|
*/
|
||||||
isAffecting(affectedNote) {
|
isAffecting(affectedNote) {
|
||||||
|
if (!affectedNote) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const attrNote = this.getNote();
|
const attrNote = this.getNote();
|
||||||
const owningNotes = [affectedNote, ...affectedNote.getTemplateNotes()];
|
const owningNotes = [affectedNote, ...affectedNote.getTemplateNotes()];
|
||||||
|
|
||||||
|
@ -180,22 +180,9 @@ class NoteShort {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(this.noteId in noteAttributeCache)) {
|
if (!(this.noteId in noteAttributeCache.attributes)) {
|
||||||
const ownedAttributes = this.getOwnedAttributes();
|
|
||||||
|
|
||||||
const attrArrs = [
|
|
||||||
ownedAttributes
|
|
||||||
];
|
|
||||||
|
|
||||||
const newPath = [...path, this.noteId];
|
const newPath = [...path, this.noteId];
|
||||||
|
const attrArrs = [ this.getOwnedAttributes() ];
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.noteId !== 'root') {
|
if (this.noteId !== 'root') {
|
||||||
for (const parentNote of this.getParentNotes()) {
|
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();
|
noteAttributeCache.attributes[this.noteId] = attrArrs.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ const TPL = `
|
|||||||
<div class="attr-display">
|
<div class="attr-display">
|
||||||
<div class="note-attributes-editor" tabindex="200"></div>
|
<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">
|
<div class="attr-expander attr-inherited-expander">
|
||||||
<hr class="w-100">
|
<hr class="w-100">
|
||||||
@ -394,10 +394,9 @@ export default class NoteAttributesWidget extends TabAwareWidget {
|
|||||||
this.textEditor.setData($attributesContainer.html());
|
this.textEditor.setData($attributesContainer.html());
|
||||||
});
|
});
|
||||||
|
|
||||||
const inheritedAttributes = note.getAttributes().filter(attr => attr.isInheritable && attr.noteId !== this.noteId);
|
const inheritedAttributes = note.getAttributes().filter(attr => attr.noteId !== this.noteId);
|
||||||
const inheritedAttributeCount = inheritedAttributes.length;
|
console.log("inheritedAttributes", inheritedAttributes);
|
||||||
|
if (inheritedAttributes.length === 0) {
|
||||||
if (inheritedAttributeCount === 0) {
|
|
||||||
this.$inheritedExpander.hide();
|
this.$inheritedExpander.hide();
|
||||||
this.$inheritedEmptyExpander.show();
|
this.$inheritedEmptyExpander.show();
|
||||||
}
|
}
|
||||||
@ -406,7 +405,7 @@ export default class NoteAttributesWidget extends TabAwareWidget {
|
|||||||
this.$inheritedEmptyExpander.hide();
|
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);
|
await this.renderAttributes(inheritedAttributes, this.$inheritedAttributes);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ const noteCacheService = require('../../services/note_cache/note_cache.js');
|
|||||||
const log = require('../../services/log');
|
const log = require('../../services/log');
|
||||||
const TaskContext = require('../../services/task_context.js');
|
const TaskContext = require('../../services/task_context.js');
|
||||||
|
|
||||||
function importToBranch(req) {
|
async function importToBranch(req) {
|
||||||
const {parentNoteId} = req.params;
|
const {parentNoteId} = req.params;
|
||||||
const {taskId, last} = req.body;
|
const {taskId, last} = req.body;
|
||||||
|
|
||||||
@ -49,19 +49,15 @@ function importToBranch(req) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (extension === '.tar' && options.explodeArchives) {
|
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) {
|
} else if (extension === '.zip' && options.explodeArchives) {
|
||||||
const start = Date.now();
|
note = await zipImportService.importZip(taskContext, file.buffer, parentNote);
|
||||||
|
|
||||||
note = zipImportService.importZip(taskContext, file.buffer, parentNote);
|
|
||||||
|
|
||||||
console.log("Import took", Date.now() - start, "ms");
|
|
||||||
} else if (extension === '.opml' && options.explodeArchives) {
|
} 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) {
|
} else if (extension === '.enex' && options.explodeArchives) {
|
||||||
note = enexImportService.importEnex(taskContext, file, parentNote);
|
note = await enexImportService.importEnex(taskContext, file, parentNote);
|
||||||
} else {
|
} else {
|
||||||
note = singleImportService.importSingleFile(taskContext, file, parentNote);
|
note = await singleImportService.importSingleFile(taskContext, file, parentNote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
@ -83,8 +79,8 @@ function importToBranch(req) {
|
|||||||
|
|
||||||
// import has deactivated note events so note cache is not updated
|
// import has deactivated note events so note cache is not updated
|
||||||
// instead we force it to reload (can be async)
|
// instead we force it to reload (can be async)
|
||||||
// FIXME
|
|
||||||
//noteCacheService.load();
|
noteCacheService.load();
|
||||||
|
|
||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ const sql = require('./sql');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const Attribute = require('../entities/attribute');
|
const Attribute = require('../entities/attribute');
|
||||||
|
|
||||||
const ATTRIBUTE_TYPES = [ 'label', 'label-definition', 'relation', 'relation-definition' ];
|
const ATTRIBUTE_TYPES = [ 'label', 'relation' ];
|
||||||
|
|
||||||
const BUILTIN_ATTRIBUTES = [
|
const BUILTIN_ATTRIBUTES = [
|
||||||
// label names
|
// label names
|
||||||
|
@ -23,7 +23,7 @@ const treeService = require("../tree");
|
|||||||
* @param {Note} importRootNote
|
* @param {Note} importRootNote
|
||||||
* @return {Promise<*>}
|
* @return {Promise<*>}
|
||||||
*/
|
*/
|
||||||
function importTar(taskContext, fileBuffer, importRootNote) {
|
async function importTar(taskContext, fileBuffer, importRootNote) {
|
||||||
// maps from original noteId (in tar file) to newly generated noteId
|
// maps from original noteId (in tar file) to newly generated noteId
|
||||||
const noteIdMap = {};
|
const noteIdMap = {};
|
||||||
const attributes = [];
|
const attributes = [];
|
||||||
|
@ -21,7 +21,7 @@ const yauzl = require("yauzl");
|
|||||||
* @param {Note} importRootNote
|
* @param {Note} importRootNote
|
||||||
* @return {Promise<*>}
|
* @return {Promise<*>}
|
||||||
*/
|
*/
|
||||||
function importZip(taskContext, fileBuffer, importRootNote) {
|
async function importZip(taskContext, fileBuffer, importRootNote) {
|
||||||
// maps from original noteId (in tar file) to newly generated noteId
|
// maps from original noteId (in tar file) to newly generated noteId
|
||||||
const noteIdMap = {};
|
const noteIdMap = {};
|
||||||
const attributes = [];
|
const attributes = [];
|
||||||
@ -133,6 +133,15 @@ function importZip(taskContext, fileBuffer, importRootNote) {
|
|||||||
for (const attr of noteMeta.attributes) {
|
for (const attr of noteMeta.attributes) {
|
||||||
attr.noteId = note.noteId;
|
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)) {
|
if (!attributeService.isAttributeType(attr.type)) {
|
||||||
log.error("Unrecognized attribute type " + attr.type);
|
log.error("Unrecognized attribute type " + attr.type);
|
||||||
continue;
|
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.
|
// 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);
|
const filePath = normalizeFilePath(entry.fileName);
|
||||||
|
|
||||||
if (filePath === '!!!meta.json') {
|
if (filePath === '!!!meta.json') {
|
||||||
const content = readContent(zipfile, entry);
|
const content = await readContent(zipfile, entry);
|
||||||
|
|
||||||
metaFile = JSON.parse(content.toString("UTF-8"));
|
metaFile = JSON.parse(content.toString("UTF-8"));
|
||||||
}
|
}
|
||||||
@ -417,14 +426,14 @@ function importZip(taskContext, fileBuffer, importRootNote) {
|
|||||||
zipfile.readEntry();
|
zipfile.readEntry();
|
||||||
});
|
});
|
||||||
|
|
||||||
readZipFile(fileBuffer, (zipfile, entry) => {
|
await readZipFile(fileBuffer, async (zipfile, entry) => {
|
||||||
const filePath = normalizeFilePath(entry.fileName);
|
const filePath = normalizeFilePath(entry.fileName);
|
||||||
|
|
||||||
if (/\/$/.test(entry.fileName)) {
|
if (/\/$/.test(entry.fileName)) {
|
||||||
saveDirectory(filePath);
|
saveDirectory(filePath);
|
||||||
}
|
}
|
||||||
else if (filePath !== '!!!meta.json') {
|
else if (filePath !== '!!!meta.json') {
|
||||||
const content = readContent(zipfile, entry);
|
const content = await readContent(zipfile, entry);
|
||||||
|
|
||||||
saveNote(filePath, content);
|
saveNote(filePath, content);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class Attribute {
|
|||||||
/** @param {string} */
|
/** @param {string} */
|
||||||
this.name = row.name.toLowerCase();
|
this.name = row.name.toLowerCase();
|
||||||
/** @param {string} */
|
/** @param {string} */
|
||||||
this.value = row.type === 'label'? row.value.toLowerCase() : row.value;
|
this.value = row.type === 'label' ? row.value.toLowerCase() : row.value;
|
||||||
/** @param {boolean} */
|
/** @param {boolean} */
|
||||||
this.isInheritable = !!row.isInheritable;
|
this.isInheritable = !!row.isInheritable;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user