1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2026-01-22 10:54:46 +00:00

Compare commits

...

6 Commits

4 changed files with 59 additions and 1 deletions

View File

@@ -164,12 +164,59 @@ exports.enqueueTiddlerEvent = function(title,isDeleted) {
self.eventsTriggered = false;
if($tw.utils.count(changes) > 0) {
self.dispatchEvent("change",changes);
self.runFilteredActions();
}
});
this.eventsTriggered = true;
}
};
exports.runFilteredActions = function() {
if(!$tw.browser) {
return;
}
var self = this;
var now = (new Date()).getTime();
// Minimum interval between runs
this.intervalFilteredActions = this.intervalFilteredActions || 100;
// Time of the last run
this.timestampLastRunFilteredActions = this.timestampLastRunFilteredActions || now - this.intervalFilteredActions * 2;
// If we've run the filtered actions recently, queue another run
if((this.timestampLastRunFilteredActions + this.intervalFilteredActions) > now) {
if(!this.filterActionTimerId) {
this.filterActionTimerId = setTimeout(function() {
self.filterActionTimerId = null;
self.runFilteredActions();
},this.intervalFilteredActions);
}
return;
}
// Record the time of this run
this.timestampLastRunFilteredActions = now;
// Get the list of filtered action tiddlers and process each one
var filteredActions = $tw.wiki.getTiddlersWithTag("$:/tags/FilteredActions");
$tw.utils.each(filteredActions,function(filteredActionTitle) {
var tiddler = self.getTiddler(filteredActionTitle);
if(tiddler && tiddler.fields.filter) {
var results = self.filterTiddlers(tiddler.fields.filter);
if(results.length > 0) {
console.log("Executing actions",tiddler.fields.text,results)
self.invokeActionString(
tiddler.fields.text,
null,
{
filteredActionTitle: filteredActionTitle,
results: $tw.utils.stringifyList(results),
jsonResults: JSON.stringify(results)
},{
parentWidget: $tw.rootWidget
}
);
}
}
});
}
exports.getSizeOfTiddlerEventQueue = function() {
return $tw.utils.count(this.changedTiddlers);
};

View File

@@ -0,0 +1,5 @@
title: Sample Filtered Action
tags: $:/tags/FilteredActions
filter: [list[$:/StoryList]match[Sample Filtered Action]]
<$action-setfield $tiddler="$:/SiteTitle" text={{{ [{$:/SiteTitle}addsuffix[!]] }}}/>

View File

@@ -0,0 +1,7 @@
title: $:/plugins/tiddlywiki/tour/filtered-action
tags: $:/tags/FilteredActions
filter: [{$:/config/ShowTour}!is[blank]else[show]match[show]then[$:/state/tour/step]get[text]get[step-success-filter]] :map[subfilter<currentTiddler>] :filter[<currentTiddler>!match[]]
\import [[$:/plugins/tiddlywiki/tour/variables]]
<$action-sendmessage $message="tm-confetti-launch"/>
<<tour-next-step>>

View File

@@ -48,7 +48,6 @@ tags: $:/tags/PageTemplate
<$let tour-task="">
<$transclude tiddler=<<currentTourStep>> mode="block"/>
</$let>
<$confetti/>
<p>
Congratulations, you may proceed
</p>