added list suffix for each filter

implements #1369

when the suffix is `list`, interprets the field as a list of individual
tiddler titles and returns all titles referenced in the list field of
the source list, existing or not
print-window-tiddler
Tobias Beer 2015-01-26 13:39:04 +01:00
rodzic 8a763e9d83
commit baca2703f1
1 zmienionych plików z 17 dodań i 12 usunięć

Wyświetl plik

@ -3,7 +3,8 @@ title: $:/core/modules/filters/each.js
type: application/javascript
module-type: filteroperator
Filter operator that selects one tiddler for each unique value of the specified field
Filter operator that selects one tiddler for each unique value of the specified field.
With suffix "list", selects all tiddlers that are values in a specified list field.
\*/
(function(){
@ -17,19 +18,23 @@ Export our filter function
*/
exports.each = function(source,operator,options) {
var results = [],
values = {};
values = {},
list = "list" === operator.suffix;
source(function(tiddler,title) {
if(tiddler) {
var value;
if((operator.operand === "") || (operator.operand === "title")) {
value = title;
} else {
value = tiddler.getFieldString(operator.operand);
}
if(!$tw.utils.hop(values,value)) {
values[value] = true;
results.push(title);
}
var value,
field = operator.operand || "title";
$tw.utils.each(
list ?
options.wiki.getTiddlerList(title,field) :
[ "title" === field ? title : tiddler.getFieldString(operator.operand)],
function(value){
if(!$tw.utils.hop(values,value)) {
values[value] = true;
results.push(list ? value : title);
}
}
)
}
});
return results;