2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-05-17 10:11:19 +02:00
|
|
|
const NoteSet = require('../note_set');
|
|
|
|
const noteCache = require('../../note_cache/note_cache');
|
|
|
|
|
2020-05-20 00:03:33 +02:00
|
|
|
class AttributeExistsExp {
|
2020-05-21 12:05:12 +02:00
|
|
|
constructor(attributeType, attributeName, prefixMatch) {
|
2020-05-16 23:12:29 +02:00
|
|
|
this.attributeType = attributeType;
|
|
|
|
this.attributeName = attributeName;
|
2020-05-21 12:05:12 +02:00
|
|
|
this.prefixMatch = prefixMatch;
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
execute(noteSet) {
|
2020-05-21 12:05:12 +02:00
|
|
|
const attrs = this.prefixMatch
|
|
|
|
? noteCache.findAttributesWithPrefix(this.attributeType, this.attributeName)
|
|
|
|
: noteCache.findAttributes(this.attributeType, this.attributeName);
|
|
|
|
|
2020-05-16 23:12:29 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-21 00:39:17 +02:00
|
|
|
|
|
|
|
return resultNoteSet;
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-17 09:48:24 +02:00
|
|
|
|
2020-05-20 00:03:33 +02:00
|
|
|
module.exports = AttributeExistsExp;
|