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:
parent
ca51634041
commit
cf75b209ba
42
core/modules/filters/eachday.js
Normal file
42
core/modules/filters/eachday.js
Normal 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;
|
||||
};
|
||||
|
||||
})();
|
46
core/modules/filters/sameday.js
Normal file
46
core/modules/filters/sameday.js
Normal 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;
|
||||
};
|
||||
|
||||
})();
|
Loading…
Reference in New Issue
Block a user