2013-05-25 16:26:22 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/filters/field.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: filteroperator
|
|
|
|
|
|
|
|
Filter operator for comparing fields for equality
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
Export our filter function
|
|
|
|
*/
|
|
|
|
exports.field = function(source,operator,options) {
|
2019-05-24 20:07:37 +00:00
|
|
|
var results = [],indexedResults,
|
2021-07-14 08:15:30 +00:00
|
|
|
fieldname = operator.suffix || operator.operator || "title";
|
2014-04-03 19:49:16 +00:00
|
|
|
if(operator.prefix === "!") {
|
|
|
|
if(operator.regexp) {
|
|
|
|
source(function(tiddler,title) {
|
|
|
|
if(tiddler) {
|
|
|
|
var text = tiddler.getFieldString(fieldname);
|
|
|
|
if(text !== null && !operator.regexp.exec(text)) {
|
|
|
|
results.push(title);
|
|
|
|
}
|
2014-12-11 17:49:17 +00:00
|
|
|
} else {
|
|
|
|
results.push(title);
|
2014-04-03 19:49:16 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
source(function(tiddler,title) {
|
|
|
|
if(tiddler) {
|
|
|
|
var text = tiddler.getFieldString(fieldname);
|
|
|
|
if(text !== null && text !== operator.operand) {
|
|
|
|
results.push(title);
|
|
|
|
}
|
2014-12-11 17:49:17 +00:00
|
|
|
} else {
|
|
|
|
results.push(title);
|
2014-04-03 19:49:16 +00:00
|
|
|
}
|
|
|
|
});
|
2013-05-25 16:26:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-04-03 19:49:16 +00:00
|
|
|
if(operator.regexp) {
|
|
|
|
source(function(tiddler,title) {
|
|
|
|
if(tiddler) {
|
|
|
|
var text = tiddler.getFieldString(fieldname);
|
|
|
|
if(text !== null && !!operator.regexp.exec(text)) {
|
|
|
|
results.push(title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2019-09-09 13:47:27 +00:00
|
|
|
if(source.byField && operator.operand) {
|
2019-05-24 20:07:37 +00:00
|
|
|
indexedResults = source.byField(fieldname,operator.operand);
|
|
|
|
if(indexedResults) {
|
|
|
|
return indexedResults
|
|
|
|
}
|
|
|
|
}
|
2014-04-03 19:49:16 +00:00
|
|
|
source(function(tiddler,title) {
|
|
|
|
if(tiddler) {
|
|
|
|
var text = tiddler.getFieldString(fieldname);
|
|
|
|
if(text !== null && text === operator.operand) {
|
|
|
|
results.push(title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-05-25 16:26:22 +00:00
|
|
|
}
|
|
|
|
return results;
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|