This commit is contained in:
zadam 2020-06-27 00:40:35 +02:00
parent dd62b306fd
commit c778e87683
8 changed files with 44 additions and 41 deletions

View File

@ -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()];

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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 names

View File

@ -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 noteId
const noteIdMap = {};
const attributes = [];

View File

@ -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 noteId
const 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);
}

View File

@ -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;