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?
> 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
> 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
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
<<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
<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