Extend listed filter operator to use any field

This commit is contained in:
Jermolene 2014-06-13 10:58:19 +01:00
parent f54f0d1c3e
commit 4238af2a40
4 changed files with 12 additions and 9 deletions

View File

@ -16,9 +16,10 @@ Filter operator returning all tiddlers that have the selected tiddlers in a list
Export our filter function
*/
exports.listed = function(source,operator,options) {
var results = [];
var field = operator.operand || "list",
results = [];
source(function(tiddler,title) {
$tw.utils.pushTop(results,options.wiki.findListingsOfTiddler(title));
$tw.utils.pushTop(results,options.wiki.findListingsOfTiddler(title,field));
});
return results;
};

View File

@ -480,13 +480,14 @@ exports.getTagMap = function() {
};
/*
Lookup a given tiddler and return a list of all the tiddlers that include it in their list
Lookup a given tiddler and return a list of all the tiddlers that include it in the specified list field
*/
exports.findListingsOfTiddler = function(targetTitle) {
// Get the list associated with the tag
exports.findListingsOfTiddler = function(targetTitle,fieldName) {
fieldName = fieldName || "list";
var titles = [];
this.each(function(tiddler,title) {
if($tw.utils.isArray(tiddler.fields.list) && tiddler.fields.list.indexOf(targetTitle) !== -1) {
var list = $tw.utils.parseStringArray(tiddler.fields[fieldName]);
if(list && list.indexOf(targetTitle) !== -1) {
titles.push(title);
}
});

View File

@ -33,6 +33,7 @@ See [[Notes for upgrading to 5.0.13-beta]] for more details of these changes:
* [[Added|https://github.com/Jermolene/TiddlyWiki5/commit/d2796d0c9c7ed7a971ae6b0752d7418384072bb5]] new SetFieldCommand
* [[Added|https://github.com/Jermolene/TiddlyWiki5/commit/305617b632fd6ecf25cd4be85f4dfb5a5a65dfef]] new SaveTiddlersCommand
* [[Added|https://github.com/Jermolene/TiddlyWiki5/commit/f14ecf4eb8965f2e407ccac51d4277330221efe3]] support for system tag [[$:/tags/RawMarkup]]
* Extended [[FilterOperator: listed]] to work with any list field
!! Bug Fixes

View File

@ -1,13 +1,13 @@
created: 20140410103123179
modified: 20140410103123179
modified: 20140613103123179
tags: filters
title: FilterOperator: listed
type: text/vnd.tiddlywiki
The ''listed'' filter operator returns the titles of the tiddlers that have `list` fields that contain any members of the current list.
The ''listed'' filter operator returns the titles of the tiddlers that have `list` fields that contain any members of the current list. The optional operand can be used to specify a different field.
For example:
|!Filter String |!Description |
|`[[HelloThere]listed[]]` |Returns the titles of any tiddlers containing `HelloThere` in their `list` fields |
|`[all[current]listed[]]]` |Returns the titles of any tiddlers containing the current tiddler in their `list` fields |
|`[all[current]listed[my-special-list]]]` |Returns the titles of any tiddlers containing the current tiddler in their `my-special-list` fields |