This commit is contained in:
Jeremy Ruston 2024-05-02 16:49:01 +02:00 committed by GitHub
commit 1a0a4009f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 1 deletions

View File

@ -164,12 +164,53 @@ 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();
this.timestampLastRunFilteredActions = this.timestampLastRunFilteredActions || now;
this.intervalFilteredActions = this.intervalFilteredActions || 500;
if((this.timestampLastRunFilteredActions + this.intervalFilteredActions) > now) {
if(!this.filterActionTimerId) {
this.filterActionTimerId = setTimeout(function() {
self.filterActionTimerId = null;
self.runFilteredActions();
},this.intervalFilteredActions);
}
return;
}
this.timestampLastRunFilteredActions = now;
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,
{
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

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