Hi there.
I'm trying to make it easy to filter by labels. End goal: Have a menu with buttons that let me filter by labels, either showing only files that match, or files that don't.
I would like to have a way of just passing in the name of a label on my way to achieve this.
I thought it would be nice to get into evaluator functions for this.
Question 1: It looks like in the current stable version (13.10), there still is no "Evaluator Function" criteria type in the advanced filters dialog, only Evaluator Column
. Bespoke evaluator functions have to use the "edit as text" mode and be surrounded by "=()". Is that correct?
Aside: I spent way too long trying to get the Label
Matches
field to accept the variable filter_args
(also trying {$filter_args}
, $filter_args
, =(filter_args)
, =({$filter_args})
, =($filter_args)
, etc) in my filter called "ByLabel", combined with typing in the filter bar ?ByLabel:"Label Name"
, ?ByLabel:Label Name
, etc, because the docs didn't really make that clear enough for me
So, after some moments of desperation and bewilderment, I ended up writing a filter like this:
=(
// Output("Label of " + file_name + ": '" + label + "'");
toMatch = $label; // always empty string at the moment
// if(TypeOf(quick_filter) == "bool" && quick_filter == true) // Ugh, if this function was not called from the QuickFilter, quick_filter is not false but undefined. Without something like checking if it's of bool type first, a check for true will throw an exception
if(quick_filter)
toMatch = filter_args;
//Output("To match: " + toMatch);
if(! toMatch)
return true; // For my purposes, this is safer. I don't need to check if labels are blank.
rex = "(^|,) ?" + toMatch + "(,.+|$)";
//Output(file_name);
//Output(toMatch + " -> " + rex + ": " + Match(label, rex, "r"));
if(Match(label, rex, "r"))
return true;
return false;
)
, which I saved under the name "ByLabel".
This I can then use in a QuickFilter like ?ByLabel:Label Name
I was shocked to see that label
just returns a comma-separated string (TypeOf(label)
is indeed str
)
Question 2: Is there really no native way supported here to check if the file's labels contain one specific label?
This RegExp works well enough in most cases, but it seems bad to be unable to distinguish between a file having a label "foo" and a label "bar" from a file having a label called "foo, bar".
Question 3: In the docs, it says that the evaluator can access vars beginning with "$", as assigned by @set
. However, when I try to use a button like
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
<label>Label: Test</label>
<tip>Toggle label. Ctrl: Filter only, Shift: Filter out</tip>
<icon1>#read</icon1>
<function type="normal">
<instruction>@set label=Test</instruction>
<!--[...]-->
<instruction>@keydown:ctrl</instruction>
<instruction>Set QUICKFILTER="?ByLabel:{$label}"</instruction>SETLABELTOGGLE</instruction>
</function>
</button>
, the variable $label
stays empty inside the ByLabel
evaluator function.
Is there something I can do to make it available?
If not: I would hereby like to request that feature.
Question 4: Now that I have the above mostly working, I'm wondering: How do I invert (negate, not) the evaluation?
In the docs, it says to use a tilde (~
) as a "not" operator in DO's default pattern matching. I thought I should be able to start off the QuickFilter string with a "~" before entering into eval mode with "?", but that doesn't work.
Is there a way to negate an evaluator result in the Filter Bar (QuickFilter) in the general case? (i.e. without writing your own logic for that in the evaluator function)
Question 5: What would be a better way for me to provide a way to quickly/conveniently set up filters by label? What would y'all do if you knew you were going to be filtering by as yet unknown labels in the future and wanted to pave the way for convenience?
Question x: Along the way: Aaaargh! WTF? I just realized that my "ByLabel" evaluator gets run no matter what I type in the filter bar??? What is happening??
...And after refreshing the tab, it's just stuck trying to just eval everything. This has to be a bug
That was half a day of pulling my hair out and I'm angry frustrated drunk now
I hope the above makes sense and gets my questions across.
Thank you all who take their time to read and ponder this