[Solved] Struggling with dynamic filter string

I used a similar “composite filter” technique when I wrote TiddlyTools/Panels/Images. However, since it was before the new \function syntax was available, I used the older subfilter<...> syntax to produce equivalent results. While I could now switch over to using \function syntax, I decided to leave the older syntax in place so that my code is backward compatible and can still be used with versions of the TWCore before v5.3.0.

Here’s the definitions I used in TiddlyTools/Panels/Images:

\define isimage()		[is[image]] [tag[$:/tags/Image]] [type[video/webm]] [type[audio/mpeg]] [has[error]] -[type[application/pdf]] -[has[draft.of]]
...
\define prefixfilter()	[enlist{$(config)$##prefix}] :map:flat[all<include>prefix<currentTiddler>]
\define suffixfilter()	[enlist{$(config)$##suffix}] :map:flat[all<include>suffix<currentTiddler>]
\define tagsfilter()	[enlist{$(config)$##tags}]   :map:flat[all<include>tag<currentTiddler>]
\define extrafilter()	[subfilter{$(config)$##filter}] ~[!match[]]
\define imagefilter()	[subfilter<prefixfilter>] [subfilter<suffixfilter>] [subfilter<tagsfilter>] ~[all<include>] +[subfilter<extrafilter>] -[subfilter{$(config)$##exclude}] +[subfilter<isimage>] $(sortFilter)$

which is then used in the rest of the TiddlyTools/Panels/Images code with:

<$list filter="[subfilter<imagefilter>]" ...>
   ...
</$list>

Note how each filter uses [enlist{$(config)$##something}] so that they can be easily reconfigured for different user-entered prefix, suffix, and tag values, and the :map:flat[...] syntax uses all<include>, where <include> can be set to “tiddlers”, “shadows”, or “tiddlers+shadows” to further control which tiddlers the combined imagefilter will include in the final results.

-e

1 Like

Indeed. I’m a fan of “passing” context from outside, something I find TW encourages since, in essence, the whole page (the entire philosophy) lends itself to it.

Yes, Having spent a vast majority of a career in IT with different support obligations, any apparently difficult problem usually has a root cause which is not disclosed. By determining the root cause we can find more abstract answers which solve multiple problems at a time and more elegantly.

What this thread @CodaCoder has raised in my mind is;

what methods can we use to merge lists or sets whilst retaining the raw order?

The simplest, and general answer may be to use the “Order Operators” (so tagged on tiddlywiki.com) such as append and prepend inside a single filter run.

  • Then be aware of those operators that can act on a list without altering the order eg unique.

I am curiouse since you @CodaCoder are the master of your domain, can you not have, a naming standard such that you can retrieve prefix[CH]

@etardiff Unfortunately, your prefixed.with isn’t working correctly:

In AdvancedSearch : works fine

In a Bundle listing : works fine

As exported JSON: FAIL.

None of the prefix bits are included in the export, but they’re definitely there in the list produced by AdvancedSearch.

Baffling.

That is odd, and I’m not entirely sure where to start looking. :confused: My first guess would be that the export mechanism doesn’t have access to the $:/tags/Global tag… I don’t suppose replacing it with $:/tags/Macro changes anything?

All right, from my own testing, $:/tags/Macro vs. $:/tags/Global does not seem to make a difference. Technically good… though I would have liked an easy answer!

I did try modifying the exportButton macro in $:/core/macros/export as follows, to define the payload before it gets passed to $:/core/templates/exporters/JsonFile, and that seemed to solve the issue—at least in my quick testing on TW-com.

\define exportButtonFilename(baseFilename) $baseFilename$$(extension)$

\define exportButton(exportFilter:"[!is[system]sort[title]]",lingoBase,baseFilename:"tiddlers")
\whitespace trim
<$vars hint={{{ [<__lingoBase__>addsuffix[Hint]get[text]] }}} caption={{{  [<__lingoBase__>addsuffix[Caption]get[text]] }}}>
<span class="tc-popup-keep"><$button popup=<<qualify "$:/state/popup/export">> tooltip=<<hint>> aria-label=<<caption>> class=<<tv-config-toolbar-class>> selectedClass="tc-selected">
<$list filter="[<tv-config-toolbar-icons>match[yes]]">
{{$:/core/images/export-button}}
</$list>
<$list filter="[<tv-config-toolbar-text>match[yes]]">
<span class="tc-btn-text"><$text text=<<caption>>/></span>
</$list>
</$button></span></$vars>
<$reveal state=<<qualify "$:/state/popup/export">> type="popup" position="below" animate="yes">
<div class="tc-drop-down">
<$set name="payload" filter="[subfilter<__exportFilter__>]"> <!-- THE LINE I ADDED -->
<$set name="count" value={{{ [enlist<payload>count[]] }}}>
<$list filter="[all[shadows+tiddlers]tag[$:/tags/Exporter]]">
<$list filter="[<currentTiddler>has[condition]subfilter{!!condition}limit[1]] ~[<currentTiddler>!has[condition]then[true]]" variable="ignore">
<$button class="tc-btn-invisible">
<$action-sendmessage $message="tm-download-file" $param=<<currentTiddler>> exportFilter=<<payload>> filename={{{ [<__baseFilename__>addsuffix{!!extension}] }}}/> <!-- ALSO MODIFIED -->
<$action-deletetiddler $tiddler=<<qualify "$:/state/popup/export">>/>
<$transclude field="description"/>
</$button>
</$list>
</$list>
</$set>
</$set>
</div>
</$reveal>
\end

Can you confirm that this fix works for you as well? If so, I’d suspect that the issue lies with either the tiddlers tagged with $:/tags/Exporter or the widget message tm-download-file, which handles them, and one or both of these do not have access to the global function… for some reason.

2 Likes

:trophy:

I most certainly can. Superb turnaround, Emily. Grassy ass.

Shame we didn’t catch this before the recent release. :frowning:

(@jeremyruston )