1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Add an untagged filter operator and sidebar tab

This commit is contained in:
Jeremy Ruston 2013-09-14 16:28:46 +01:00
parent 99fd7a6849
commit 4fb6836481
4 changed files with 56 additions and 2 deletions

View File

@ -0,0 +1,44 @@
/*\
title: $:/core/modules/filters/untagged.js
type: application/javascript
module-type: filteroperator
Filter operator returning all the selected tiddlers that are untagged
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.untagged = function(source,operator,options) {
var results = [];
// Function to check an individual title
function checkTiddler(title) {
var tiddler = options.wiki.getTiddler(title),
match = tiddler && $tw.utils.isArray(tiddler.fields.tags) && tiddler.fields.tags.length > 0;
if(operator.prefix !== "!") {
match = !match;
}
if(match) {
$tw.utils.pushTop(results,title);
}
}
// Iterate through the source tiddlers
if($tw.utils.isArray(source)) {
$tw.utils.each(source,function(title) {
checkTiddler(title);
});
} else {
$tw.utils.each(source,function(element,title) {
checkTiddler(title);
});
}
return results;
};
})();

View File

@ -8,6 +8,8 @@ title: $:/core/ui/MoreSideBar
<$button type="set" set="$:/state/moreSideBarTabSet" setTo="tagsTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Tags</$button>
<$button type="set" set="$:/state/moreSideBarTabSet" setTo="untaggedTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Untagged</$button>
<$button type="set" set="$:/state/moreSideBarTabSet" setTo="missingTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Missing</$button>
<$button type="set" set="$:/state/moreSideBarTabSet" setTo="draftsTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Drafts</$button>
@ -32,6 +34,9 @@ title: $:/core/ui/MoreSideBar
<$transclude title="$:/core/ui/TagTemplate"/> <small class="tw-menu-list-count"><$count filter="[is[current]tagging[]]"/></small>
</$list>
</$reveal>
<$reveal type="match" state="$:/state/moreSideBarTabSet" text="untaggedTab" qualifyTiddlerTitles="yes">
<$list filter="[untagged[]!is[system]sort[title]]" itemClass="tw-menu-list-item"/>
</$reveal>
<$reveal type="match" state="$:/state/moreSideBarTabSet" text="missingTab" qualifyTiddlerTitles="yes">
<$list filter="[is[missing]sort[title]]" itemClass="tw-menu-list-item" template="$:/core/ui/MissingTemplate"/>
</$reveal>

View File

@ -50,7 +50,6 @@ describe("Filter tests", function() {
wiki.addTiddler({
title: "one",
text: "This is the text of tiddler [[one]]",
tags: [],
list: "[[Tiddler Three]] [[TiddlerOne]]",
modifier: "JohnDoe"});
// And some shadows
@ -119,6 +118,11 @@ describe("Filter tests", function() {
expect(wiki.filterTiddlers("[is[current]tagging[]sort[title]]","one").join(",")).toBe("Tiddler Three,TiddlerOne");
});
it("should handle the untagged operator", function() {
expect(wiki.filterTiddlers("[untagged[]sort[title]]").join(",")).toBe("a fourth tiddler,one");
expect(wiki.filterTiddlers("[!untagged[]sort[title]]").join(",")).toBe("$:/TiddlerTwo,Tiddler Three,TiddlerOne");
});
it("should handle the links operator", function() {
expect(wiki.filterTiddlers("[!is[shadow]links[]sort[title]]").join(",")).toBe("a fourth tiddler,one,Tiddler Three,TiddlerSix,TiddlerTwo,TiddlerZero");
expect(wiki.filterTiddlers("[is[shadow]links[]sort[title]]").join(",")).toBe("TiddlerOne");

View File

@ -1,6 +1,6 @@
created: 201308270800
creator: JeremyRuston
modified: 201308300906
modified: 201309141606
modifier: JeremyRuston
tags: concepts
title: TiddlerFilters
@ -44,6 +44,7 @@ A filter string consists of one or more runs of filter operators that each look
* ''{field}'': tests whether a tiddler field has a specified value (`[modifier[Jeremy]]`) or not (`[!modifier[Jeremy]]`)
* ''tags'': selects the tags on the currently selected tiddlers
* ''tagging'': selects the tiddlers tagged with the currently selected tiddlers
* ''untagged'': selects the any of the selected tiddlers that do not have at least one tag
* ''links'': selects the outgoing links on the currently selected tiddlers
* ''backlinks'': selects the tiddlers that link to the currently selected tiddlers
* ''list'': selects the tiddlers listed in a specified [[TiddlerList|TiddlerLists]]