2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-02-18 00:50:14 +02:00
|
|
|
import Expression = require('./expression');
|
|
|
|
import NoteSet = require('../note_set');
|
|
|
|
import becca = require('../../../becca/becca');
|
|
|
|
import SearchContext = require('../search_context');
|
|
|
|
|
|
|
|
type Comparator = (value: string) => boolean;
|
2020-05-17 10:11:19 +02:00
|
|
|
|
2020-05-23 10:25:22 +02:00
|
|
|
class LabelComparisonExp extends Expression {
|
2024-02-18 00:50:14 +02:00
|
|
|
|
|
|
|
private attributeType: string;
|
|
|
|
private attributeName: string;
|
|
|
|
private comparator: Comparator;
|
|
|
|
|
|
|
|
constructor(attributeType: string, attributeName: string, comparator: Comparator) {
|
2020-05-22 09:38:30 +02:00
|
|
|
super();
|
|
|
|
|
2020-05-16 23:12:29 +02:00
|
|
|
this.attributeType = attributeType;
|
2020-12-14 23:59:05 +01:00
|
|
|
this.attributeName = attributeName.toLowerCase();
|
2020-05-20 23:20:39 +02:00
|
|
|
this.comparator = comparator;
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
2024-02-18 00:50:14 +02:00
|
|
|
execute(inputNoteSet: NoteSet, executionContext: {}, searchContext: SearchContext) {
|
2021-04-16 23:00:08 +02:00
|
|
|
const attrs = becca.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;
|
2021-10-08 22:13:39 +02:00
|
|
|
const value = attr.value?.toLowerCase();
|
2020-05-16 23:12:29 +02:00
|
|
|
|
2020-12-14 23:59:05 +01:00
|
|
|
if (inputNoteSet.hasNoteId(note.noteId) && this.comparator(value)) {
|
2020-05-16 23:12:29 +02:00
|
|
|
if (attr.isInheritable) {
|
2021-05-17 22:35:36 +02:00
|
|
|
resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated());
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
2023-01-06 20:31:55 +01:00
|
|
|
else if (note.isInherited()) {
|
|
|
|
resultNoteSet.addAll(note.getInheritingNotes());
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2024-02-18 00:50:14 +02:00
|
|
|
export = LabelComparisonExp;
|