From baca2703f11021649c2487e8247d0191e9257ddf Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Mon, 26 Jan 2015 13:39:04 +0100 Subject: [PATCH] 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 --- core/modules/filters/each.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/core/modules/filters/each.js b/core/modules/filters/each.js index 591dfeae0..8126d5821 100644 --- a/core/modules/filters/each.js +++ b/core/modules/filters/each.js @@ -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;