mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-28 18:42:28 +08:00
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
"use strict";
|
|
|
|
const NoteSet = require('../note_set');
|
|
const becca = require('../../../becca/becca');
|
|
const Expression = require('./expression');
|
|
|
|
class AttributeExistsExp extends Expression {
|
|
constructor(attributeType, attributeName, prefixMatch) {
|
|
super();
|
|
|
|
this.attributeType = attributeType;
|
|
this.attributeName = attributeName;
|
|
this.prefixMatch = prefixMatch;
|
|
}
|
|
|
|
execute(inputNoteSet) {
|
|
const attrs = this.prefixMatch
|
|
? becca.findAttributesWithPrefix(this.attributeType, this.attributeName)
|
|
: becca.findAttributes(this.attributeType, this.attributeName);
|
|
|
|
const resultNoteSet = new NoteSet();
|
|
|
|
for (const attr of attrs) {
|
|
const note = attr.note;
|
|
|
|
if (inputNoteSet.hasNoteId(note.noteId)) {
|
|
if (attr.isInheritable) {
|
|
resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated());
|
|
}
|
|
else if (note.isTemplate()) {
|
|
resultNoteSet.addAll(note.getTemplatedNotes());
|
|
}
|
|
else {
|
|
resultNoteSet.add(note);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultNoteSet;
|
|
}
|
|
}
|
|
|
|
module.exports = AttributeExistsExp;
|