<$x-mangletags $list="mylist" $subfilter="newstring [[another new string]]"/><$x-mangletags $list="mylist" $subfilter="-oldstring -[[another old string]] +[sort[]]"/><$x-mangletags $list="mylist" $subfilter="+[addprefix[$]]"/><$x-mangletags $list="mylist" $filter="[tag[Widget]]" $subfilter="+[!sort[]]"/><$x-mangletags $list="tags" $subfilter="+[!prefix[$]]"/>On 14 Oct 2015, at 21:17, Jed Carty <inmy...@gmail.com> wrote:
The filters part isn't what I am objecting to. The only thing that imposes uniqueness in the list is the function $tw.utils.parseStringArray and that is an arbitrary limitation added to ensure uniqueness in the tags field. Since we want to use polymorphic fields that limitation should either be removed if possible or another function should be added that doesn't have that limit. This requires changes to exactly 2 lines of code in boot.js. I just added the a new function in my example because I wanted the demo to be independent of any changes to the core. Then when you want to use $tw.utils.parseStringArray and not impose uniqueness on the returned list you use $tw.utils.parseStringArray(list, true) instead of $tw.utils.parseStringArray(list)
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/135f1105-5eb0-44ad-9f59-dc61f4ee7909%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<$x-mangletags $subfilter="+[allafter[Wednesday]]"/><$x-mangletags $subfilter="[[---oOo---]] +[replace[Wednesday]]"/><$button>
<$action-setlist $tiddler="foo" $list="bar" $items="[list[foo!!bar]replace:Wedneday[---oOo---]]"/>
replace Wednesday with ---oOo--- </$button><$x-mangletags $list="mylist" $filter="[list[!!mylist]] [[---oOo---]] +[replace[Wednesday]]"/> <$x-mangletags $list="mylist" $subfilter="[[---oOo---]] +[replace[Wednesday]]"/><$x-mangletags $list="mylist" $subfilter="[[one]] [[two]] [[three]] +[replace:Wednesday[3]]"/>The way I have set up the widget -- you can use the full form of the filter using the $filter= attribute, like this:<$x-mangletags $list="mylist" $filter="[list[!!mylist]] [[---oOo---]] +[replace[Wednesday]]"/>
The code could be changed to insert more than one string, with syntax something like this (only at one position though):<$x-mangletags $list="mylist" $subfilter="[[one]] [[two]] [[three]] +[replace:Wednesday[3]]"/>-- but I'm not sure if this serves any use.
filter="[list[!!mylist]]put(one two [[and three]] before[this item])]"filter="[list[!!mylist]]replace([[mymarker]] with[this item])]"Hi Metabele,The way I have set up the widget -- you can use the full form of the filter using the $filter= attribute, like this:<$x-mangletags $list="mylist" $filter="[list[!!mylist]] [[---oOo---]] +[replace[Wednesday]]"/>Ah, of course (little facepalm), it always operates on the current tiddler's list by default.
That would be something this demo would benefit from mentioning. ;-)
<$action-listops $list="myfield" $subfilter="one two [[twenty one]] +[putbefore:2[Wednesday]putafter[Friday]]"/><$action-listops $list="myfield" $subfilter="one two [[twenty one]] +[putbefore:2[Wednesday]putafter[Friday]]"/>Witch is intended to:-- append three items to the list (one two [[twenty one]])-- move the last two appended items (two [[twenty one]]) before 'Wednesday'-- move the first appended item after 'Friday' (number of items to move defaults to 1)What do you think? and how do I get this to work?
<$action-listops $list="myfield" $subfilter="two [[twenty one]] +[putbefore:2[Wednesday]] one +[putafter[Friday]]"/>Still having problems getting this to work for more than 1 item. How does one use the '2' after the colon? Seems that 'source' refers to the input string, 'operator.operand' refers to the contents of the square brackets, but what is the variable name for the '2' after the colon?
<$action-listops $list="mylist" $subfilter="one two +[append{!!myfield}] +[putbefore:3[Wednesday]]"/>Appears that an append[] and a remove[] widget may be necessary where references to items are required?<$action-listops $list="mylist" $subfilter="one two +[append{!!myfield}] +[putbefore:3[Wednesday]]"/>
title: test
foo: bar
<$list filter="[{!!foo}]"/>
<$action-listops $list="mylist" $subfilter="[{!!selected-item}] +[putbefore{!!selected-weekday}}]"/>filter="[list[!!foo]] SomeItem +[back[10]]"{{{ [list[HelloThere]]}}}
{{{ [list[HelloThere]] Examples }}}
filter="[list[!!foo]] [back(what:SomeItem by:10)]"filter="[list[!!foo]] [back(what:SomeItem by:10 add:no)]"The filters themselves don't impose uniqueness -- items are, however, dominantly appended. If I wish to add an item, and an instance of that item already occurs in the list, then that instance will be removed the moment the second 'copy' gets added. Don't know if this is due only to the $tw.utils.stringifyList function. Anyway, this must be fixed elsewhere, and has nothing to do with my widget, or the filters themselves.
{{{ 1 2 3 2 1 2 3 2 1 }}}
One of those things the examples don't show,.. but thorough testng will.
For the time-being, therefore, if you wish to experiment (or use) such lists, keep them in an index of a data dictionary.
title: foo
foo: foo foo fooI have not managed to track down where in the core uniqueness gets imposed. As Jed points out, the StingifyList function is one place, but there appear to be others. An index in a data dictionary can be filled with multiple item values, however, when operations are carried out on that list, some operations impose uniqueness whilst others do not.
My widgets do not impose uniqueness, other than when core functions are implicitly or explicitly called which do so. However, I have made little effort to handle multiple instances of a value -- my filters will always use the first instance of an item as the marker.
Once the core has been modified to correctly handle multiple instances of the same item, filters can be modified or new filters written to handle the new usage cases.
{{{ foo foo foo }}}Currently, I believe that list management (even in its current form) should be brought into operation as soon as possible. This will enable most usage cases for user lists, and experience will be gained in the handling of lists before finalising their management.
I have written a couple of new filters to further extend what is possible with list management -- a couple more are necessary (especially a 'sortby[]' filter -- that is: sort a list of items in the order of another list.) I have also added an '$index=' attribute to the ActionListops widget to enable manipulation of data dictionary indexes (and modified a couple of my filters to work with them.)
<$action-listops ++1="new tag" ++2="another new tag" --1="tag to remove"/><$action-listops $tags="[[new tag]] [[another new tag]] -[[tag to remove]]"/><$action-listops $tags="-[prefix[$:/]]"/>Which do you prefer? Now that I have typed out both options, option 2 seems to be just as elegant, and is far more flexible:<$action-listops $tags="-[prefix[$:/]]"/>
Yes -- I prefer that option too -- I'll change the widget accordingly.Your proposal for the allbefore[] and allafter[] filters is a good one. They now respond to the presence of a suffix -- this will cause the marker to be included in the output list. In the docs, I shall specify that the suffix should be 'include', but anything will do.
HiI have been messing around with the use of filters to manage user lists (in any field):-- a demo of my current efforts may be found here-- I would appreciate some feedback as to whether this approach may be the way to goThere are also two new filters I wrote along the way, which may be of use:-- the 'allbefore[]' filter selects all strings from the current list before a specified marker string, and-- the 'allafter[]' filter selects all strings from the current list after a specified marker string(the demo on the wiki makes their usage clear.)regards
I have updated the append[] and prepend[] operators to understand a prefix and suffix. The prefix designates the number of items to take from the operator parameter (to append or prepend to the list) -- with no prefix, these are taken from the head and with a prefix from the tail.
filter="prepended appended"
filter = [list[Days of the Week]] Yesterday Today Tomorrow +[prepend:3[]]"Yesterday Today Tomorrow [[Party Friday]]Where items are being prepended, appended or removed from the list, there is no need for a marker, and the operand becomes available for specifying the items involved. One advantage is that items can be picked as a range from an array, which may be referenced rather than directly specified (as in, append the last three days-of-the-week to the list.)
filter="[list[some-list]prepend:5[some-tiddler!!some-list]]filter="[list[some-list]prepend:5{some-tiddler!!some-list}] if (append === "") {append = $tw.utils.parseStringArray(operator.operand);title: test
x: [[foo bar]] baz mumble frotz
y: [[aaaa bbbb]]] cccc mumble eeee
{{{ [list[!!x]append:3{!!y}] }}}{{{ [list[!!x]] [[aaaa bbbb]] cccc mumble }}}I see, so you are required to specify the operand using text-references or variables for multiple items.
Perhaps it is more consistent to use the same syntax of the list filter here, e.g:filter="[list[some-list]prepend:5[some-tiddler!!some-list]]instead of:filter="[list[some-list]prepend:5{some-tiddler!!some-list}]
filter="[list{mytext!!reference}prepend{....Also, reading the filter code, this should never do anything, it appears:if (append === "") {...as you have cast append into an array like so:append = $tw.utils.parseStringArray(operator.operand);
Here's a test that does not do as I expect:title: test
x: [[foo bar]] baz mumble frotz
y: [[aaaa bbbb]]] cccc mumble eeee
{{{ [list[!!x]append:3{!!y}] }}}which outputs this list:
- foo bar
- baz
- mumble
- frotz
- aaaa bbbb]
- cccc
- mumble
But should output a set as all other filters appear to do:
- foo bar
- baz
- frotz
- aaaa bbbb
- cccc
- mumble
In other words, it should work exactly the same as:{{{ [list[!!x]] [[aaaa bbbb]] cccc mumble }}}Should it not?Same for using a variable y instead of a field y.
Best wishes,— tb
I see, so you are required to specify the operand using text-references or variables for multiple items.
Not a requirement -- a simple list such as [one two [[and three]]] also works
{{{ [list[!!x]append:3[one two [[and three]] ]] }}}I didn't choose this convention -- this is standard syntax for references inside filter expressions -- if the list were referenced this should also be:filter="[list{mytext!!reference}prepend{...
Aha -- I haven't done any tests on these -- should this be append === [], in this case?
{{{ [list[!!x]append:3{!!y}] }}}
That's due to the triple ]]] after the bbbb -- the item gets read as aaaa bbbb]
I have not enforced single instances of items in any of the filter operators (although they were designed with single instances in mind.) Many operations currently enforce this, for example appending another run -- it's easy to do but I'm not sure if this is the best way to go. Rather, this default behaviour of lists may need modification, or at least this behaviour should be optional, as there is a need for repeat items in many types of list.
{{{ foo [list[!!bar]+] }}}One of my examples clearly displays this behaviour -- when first appended, multiple instances of an item are permitted, on the first update, the list becomes collapsed to single instances (due to the + before the next run.)
Not a requirement -- a simple list such as [one two [[and three]]] also worksI don't think so. This does not work, and I sure did not expect it to:{{{ [list[!!x]append:3[one two [[and three]] ]] }}}
append:3<myvariable>I have not enforced single instances of items in any of the filter operators (although they were designed with single instances in mind.) Many operations currently enforce this, for example appending another run -- it's easy to do but I'm not sure if this is the best way to go. Rather, this default behaviour of lists may need modification, or at least this behaviour should be optional, as there is a need for repeat items in many types of list.I agree that both have their uses, but — correct me if I'm wrong — so far, I have not encountered any filter operations that yield duplicates. So filters actually operate on or rather produce sets for the time being. In other words, I would not introduce true "lists" by virtue of a single new filter. If those were admissible by default, I think there should be core support for that no matter which filter is being interpreted, e.g.
{{{ foo [list[!!bar]+] }}}...and + indicating that duplicates are allowed in the operation that joins the two.One of my examples clearly displays this behaviour -- when first appended, multiple instances of an item are permitted, on the first update, the list becomes collapsed to single instances (due to the + before the next run.)Not sure which one you mean, but I think if only for testing purposes, you should...
- set up examples with duplicate entries
- define clearly what is expected to happen by default
- I think the default should be to not allow duplicates, as it is atm
I see, so you are required to specify the operand using text-references or variables for multiple items.Not a requirement -- a simple list such as [one two [[and three]]] also worksI don't think so. This does not work, and I sure did not expect it to:{{{ [list[!!x]append:3[one two [[and three]] ]] }}}
filter="[list[mylist]select:3{mytext!!reference}putfirst:3[]]"