mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Add an untagged filter operator and sidebar tab
This commit is contained in:
parent
99fd7a6849
commit
4fb6836481
44
core/modules/filters/untagged.js
Normal file
44
core/modules/filters/untagged.js
Normal 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -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="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="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>
|
<$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>
|
<$transclude title="$:/core/ui/TagTemplate"/> <small class="tw-menu-list-count"><$count filter="[is[current]tagging[]]"/></small>
|
||||||
</$list>
|
</$list>
|
||||||
</$reveal>
|
</$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">
|
<$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"/>
|
<$list filter="[is[missing]sort[title]]" itemClass="tw-menu-list-item" template="$:/core/ui/MissingTemplate"/>
|
||||||
</$reveal>
|
</$reveal>
|
||||||
|
@ -50,7 +50,6 @@ describe("Filter tests", function() {
|
|||||||
wiki.addTiddler({
|
wiki.addTiddler({
|
||||||
title: "one",
|
title: "one",
|
||||||
text: "This is the text of tiddler [[one]]",
|
text: "This is the text of tiddler [[one]]",
|
||||||
tags: [],
|
|
||||||
list: "[[Tiddler Three]] [[TiddlerOne]]",
|
list: "[[Tiddler Three]] [[TiddlerOne]]",
|
||||||
modifier: "JohnDoe"});
|
modifier: "JohnDoe"});
|
||||||
// And some shadows
|
// 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");
|
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() {
|
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("a fourth tiddler,one,Tiddler Three,TiddlerSix,TiddlerTwo,TiddlerZero");
|
||||||
expect(wiki.filterTiddlers("[is[shadow]links[]sort[title]]").join(",")).toBe("TiddlerOne");
|
expect(wiki.filterTiddlers("[is[shadow]links[]sort[title]]").join(",")).toBe("TiddlerOne");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
created: 201308270800
|
created: 201308270800
|
||||||
creator: JeremyRuston
|
creator: JeremyRuston
|
||||||
modified: 201308300906
|
modified: 201309141606
|
||||||
modifier: JeremyRuston
|
modifier: JeremyRuston
|
||||||
tags: concepts
|
tags: concepts
|
||||||
title: TiddlerFilters
|
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]]`)
|
* ''{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
|
* ''tags'': selects the tags on the currently selected tiddlers
|
||||||
* ''tagging'': selects the tiddlers tagged with 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
|
* ''links'': selects the outgoing links on the currently selected tiddlers
|
||||||
* ''backlinks'': selects the tiddlers that link to 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]]
|
* ''list'': selects the tiddlers listed in a specified [[TiddlerList|TiddlerLists]]
|
||||||
|
Loading…
Reference in New Issue
Block a user