1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Add eachday and sameday filter operators

These operators will enable us to group the recent changes list by day
This commit is contained in:
Jeremy Ruston 2013-05-27 17:59:33 +01:00
parent ca51634041
commit cf75b209ba
2 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,42 @@
/*\
title: $:/core/modules/filters/eachday.js
type: application/javascript
module-type: filteroperator
Filter operator that selects one tiddler for each unique day covered by the specified date field
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.eachday = function(source,operator,options) {
// Convert the source to an array if necessary
if(!$tw.utils.isArray(source)) {
var copy = [];
$tw.utils.each(source,function(element,title) {
copy.push(title);
});
source = copy;
}
// Collect up the first tiddler with each unique day value of the specified field
var results = [],values = {};
$tw.utils.each(source,function(title) {
var tiddler = options.wiki.getTiddler(title);
if(tiddler) {
var value = tiddler.getFieldString(operator.operand).substr(0,8);
if(!$tw.utils.hop(values,value)) {
values[value] = true;
results.push(title);
}
}
});
return results;
};
})();

View File

@ -0,0 +1,46 @@
/*\
title: $:/core/modules/filters/sameday.js
type: application/javascript
module-type: filteroperator
Filter operator that selects tiddlers with a modified date field on the same day as the provided value.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.sameday = function(source,operator,options) {
var results = [];
// Function to check an individual title
function checkTiddler(title) {
var tiddler = options.wiki.getTiddler(title);
if(tiddler) {
var match = tiddler.getFieldString("modified").substr(0,8) === operator.operand.substr(0,8);
if(operator.prefix === "!") {
match = !match;
}
if(match) {
results.push(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;
};
})();