mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 10:55:55 +01:00
refactoring for testing parser
This commit is contained in:
34
src/services/search/expressions/attribute_exists.js
Normal file
34
src/services/search/expressions/attribute_exists.js
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
const NoteSet = require('../note_set');
|
||||
const noteCache = require('../../note_cache/note_cache');
|
||||
|
||||
class AttributeExistsExp {
|
||||
constructor(attributeType, attributeName) {
|
||||
this.attributeType = attributeType;
|
||||
this.attributeName = attributeName;
|
||||
}
|
||||
|
||||
execute(noteSet) {
|
||||
const attrs = noteCache.findAttributes(this.attributeType, this.attributeName);
|
||||
const resultNoteSet = new NoteSet();
|
||||
|
||||
for (const attr of attrs) {
|
||||
const note = attr.note;
|
||||
|
||||
if (noteSet.hasNoteId(note.noteId)) {
|
||||
if (attr.isInheritable) {
|
||||
resultNoteSet.addAll(note.subtreeNotesIncludingTemplated);
|
||||
}
|
||||
else if (note.isTemplate) {
|
||||
resultNoteSet.addAll(note.templatedNotes);
|
||||
}
|
||||
else {
|
||||
resultNoteSet.add(note);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AttributeExistsExp;
|
||||
Reference in New Issue
Block a user