Question on tags and FET plugin

55 views
Skip to first unread message

googlepilot

unread,
Dec 8, 2011, 9:37:35 AM12/8/11
to tiddl...@googlegroups.com
Hi there,

I have a question related to the forEachTiddler (FET) plugin and tags. I am trying to set-up TW as an easy to use relational database.

In the db I have tiddlers as list items, which I group into different lists using the FET plugin. Items can appear on different lists in different positions. Since items can appear only once on each list, the information of list and position are linked.

So far, I have found no way to code the position of an item at the tag level. One of my ideas was to bring both informations into one tag, something like [list-x/position-y]. But then I do not know how to put my lists together with FET, since the plugin seems to work only with the full tags, and not with something like "put together a list that contains all tiddlers that have a tag containing 'list-x'".

Any ideas?

Måns

unread,
Dec 8, 2011, 10:01:06 AM12/8/11
to TiddlyWiki
Hi googlepilot

> So far, I have found no way to code the position of an item at the tag level. One of my ideas was to bring both informations into one tag, something like [list-x/position-y]. But then I do not know how to put my lists together with FET, since the plugin seems to work only with the full tags, and not with something like "put together a list that contains all tiddlers that have a tag containing 'list-x'".

This seems to work:
<<forEachTiddler where
'tiddler.tags.join("]]").contains("list-x")'>>

+ sortBy title to uppercase

<<forEachTiddler where
'tiddler.tags.join("]]").contains("list-x")'sortBy
'tiddler.title.toUpperCase()'>>

I don't know how to connect it with groupings based on tags - If you
find out, please tell...

Cheers Måns Mårtensson

Måns

unread,
Dec 8, 2011, 10:08:00 AM12/8/11
to TiddlyWiki
Hi again

> I don't know how to connect it with groupings based on tags - If you find out, please tell...

Here's a go at it:

<<forEachTiddler
where
'tiddler.tags.join("]]").contains("list-x")&& tiddler.tags.length'
sortBy
'getSortedTagsText(tiddler)+"###"+tiddler.title'
script
'function getSortedTagsText(tiddler) {var tags = tiddler.tags; if (!
tags) return ""; tags.sort(); var result = ""; for (var i = 0; i <
tags.length;i++) {result += tags[i]+ " ";} return result;} function
getGroupTitle(tiddler, context) {if (!context.lastGroup ||
context.lastGroup != getSortedTagsText(tiddler)) { context.lastGroup =
getSortedTagsText(tiddler); return "* {{{"+(context.lastGroup?
context.lastGroup:"no tags")+"}}}\n";} else return "";} '
write
'getGroupTitle(tiddler, context)+"** [[" + tiddler.title+"]]\n"'
>>


Cheers Måns Mårtensson

googlepilot

unread,
Dec 9, 2011, 10:31:03 AM12/9/11
to tiddl...@googlegroups.com
Dear Mans,

Thanks so much for your help!

Indeed, the tiddler.tags.join("]]").contains("X") in the where condition does already half of the trick: tiddlers tagged with X-Y show up now in the list created by FET.

Then you point to a problem that I haven't' even thought of: how to sort the resulting list correctly, based on the tags. Unfortunately, my knowledge of JavaScript is only basic at best, and I do not fully understand your script. I set up a test case though, and implemented your FET script. As you can see from the screenshot (http://i39.tinypic.com/2dllo29.jpg), there are two list Items A and B, which should appear in Lists 01 and 02 in different order, and are tagged accordingly. However, they appear in the same order in both lists.

Or did I just miss out what to do with the "###" in the sortBy statement?

I would suggest a different solution, but again I lack the JavaScript skills to implement it: Since I create tables for my lists anyway, using FET, I could add a column that contains only the tag in question: I would tell FET: 'Create a table from all tiddlers that have a tag that contains "X". One column of the table should contain the full tag that contains the "X"-part.' I could then either sort the table directly based on this column using the sortBy statement of FET, or I could use the SortableTable plugin.

Would that be a way? And how is it done in FET?

Måns

unread,
Dec 9, 2011, 11:34:58 AM12/9/11
to TiddlyWiki
Hi googlepilot

We could try to construct it in javascript (Then we might get some
help from someone who knows the language ;-)):

Install Eric's InlineJavaScriptPlugin: http://www.tiddlytools.com/#InlineJavascriptPlugin

Write sth like this (seems to work some of the way):

<script>
var prefix ="list-x" ;
var out = "" ;
var tags= store.getTags() ;
//wikify(tags,place) ;
for(var i=0;i<tags.length;i++) {
str = new String(tags[i]) ;
if(! str.startsWith(prefix)) continue ;
out+="* <<tag [["+tags[i][0]+"]]>> ("+tags[i][1]+")"+"\n";
}

return out ;
</script>

If we want to create tables - sth like this should be possible (there
are some errors in this attempt and we need HELP*!!):

<script>
var prefix ="list-x" ;
var out = "" ;
var hdr="|sortable|k\n| !Tiddler&Tagged | !Number of tagged |h"
out.push(hdr);
var tags= store.getTags() ;
//wikify(tags,place) ;
for(var i=0;i<tags.length;i++) {
str = new String(tags[i]) ;
if(! str.startsWith(prefix)) continue ;
out.push('|<<tag [["+tags[i][0]+"]]>>| ("+tags[i][1]+")"+" |"+'');
}
return out.join('\n');
</script>

*Please correct my mistakes - @eric, @mike, @mark, @cmari ....??

Cheers Måns Mårtensson

Måns

unread,
Dec 9, 2011, 11:51:05 AM12/9/11
to TiddlyWiki
Quick tables for groups of tags stating with list-x:

<<forEachTiddler where 'tiddler.tags.join("]]").contains("list-x")&&
tiddler.tags.length'
sortBy
'getSortedTagsText(tiddler)+"###"+tiddler.title'
script
'function getSortedTagsText(tiddler) {var tags = tiddler.tags; if (!
tags) return ""; tags.sort(); var result = ""; for (var i = 0; i <
tags.length;i++) {result += tags[i]+ " ";} return result;} function
getGroupTitle(tiddler, context) {if (!context.lastGroup ||
context.lastGroup != getSortedTagsText(tiddler)) { context.lastGroup =

getSortedTagsText(tiddler); return "|{{{"+(context.lastGroup?
context.lastGroup:"no tags")+"}}}|h\n";} else return "";} '
write
'getGroupTitle(tiddler, context)+"|[[" + tiddler.title+"]]|\n"'
>>

Cheers Måns Mårtensson

Måns

unread,
Dec 9, 2011, 2:55:27 PM12/9/11
to TiddlyWiki

okido

unread,
Dec 9, 2011, 5:04:10 PM12/9/11
to TiddlyWiki
Following script should do the trick, if I understood the problem
well:

Install Eric's InlineJavaScriptPlugin: http://www.tiddlytools.com/#InlineJavascriptPlugin
to use it.
Watch out for the linebreaks !!!!

<script>
var prefix ="list" ; // Use only the tags that start with list
format is list-listnumber-listposition
var out = [] ; var list = {} ; var list_tags = [] ;
var position = [] ;
var tags= store.getTags() ;
// first let get all tags that match the prefix and store them in
list_tags


for (var i = 0 ; i < tags.length; i++) {

var str = new String(tags[i][0]) ;
if(str.startsWith(prefix)) { list_tags.push(str) }
}
// now process the array with list tags, first find all
listnumber
for (var i = 0 ; i < list_tags.length; i++) {
var position = list_tags[i].split('-') ;
if ( !list[position[1]]) { list[position[1]] = [] ; }
list[position[1]].push(list_tags[i]) ;
}
for ( var f in list) {
out.push("*List " + f);
for ( var t = 0 ; t < list[f].length ; t++ ) {
second_list = list[f][t] ;
out.push('**' + second_list ) ;
}}

return out.join('\n');

</script>

Have fun, Okido

Reply all
Reply to author
Forward
0 new messages