TiddlyWiki tiddlers by field name, sorted by date?

May 24, 2011

Replace a Word based system with a more light weight web style? TiddlyWiki is a good approach to try first. However, unless you use TiddlyWiki a lot, it can take a while to grok.

This is posted, in case someone has need of example programming. Note I’m not a TiddlyWiki expert, so just use this as a start if it helps. Would have posted it to the TiddlyWiki forum but didn’t see how to post source code.

Requirements
I needed to search for Tiddlers by tag name, then open them in descending creation date.

Solution
Sounds simple and it is, but I had to access the TiddlyWiki source to see how to do it once I got a hint on the TiddlyWiki forum.

Put this source into a new Tiddler, for example, named openStatusTiddlers. Note the improved version in the comment by enrike on Dec 4.

// based on sample code by Eric Shulman
var fieldname='tags'; // put in what you want 
var fieldvalue='status'; // same thing 
var tidlist=[]; 

// iterate thru tiddlers and add matching to array.
store.forEachTiddler(function(title,tiddler){ 
   if (store.getValue(title,fieldname)==fieldvalue) {
      tidlist.pushUnique(title); 
   }
}); 

// comparison closure for array sort.
function sortCreation(tA,tB){
    return store.fetchTiddler(tB).created - store.fetchTiddler(tA).created
}

tidlist.sort(sortCreation);

// now show them in the 'story' object, which is the visible tiddlers.
story.displayTiddlers(null,tidlist); 

Button to show the content
Then I needed a ‘button’ to invoke that tiddler. I created some inline html in the MainMenu:

<html>
   <hide linebreaks> 
   <div>
      <<JsDoIt 'show status' 'execute javascript tiddler(s)' 'openStatusTiddlers'>>
   </div>
</html>

That uses the jsDoIt macro and HTMLFormattingPlugin.

Also in the MainMenu tiddler I’m considering putting in a list of the status tiddlers. One approach is using the forEachTiddlerMacro:

<<forEachTiddler
    where
        'tiddler.tags.contains("status")'
    write
        '"[[" + tiddler.title + "]]\n"'
        end 'count+" Tiddlers found\n"'
        none '"No Tiddlers found\n"'
>>

Show when page is loaded
Finally, I wanted these found tiddlers to open when the TiddlyWiki page first loads. For this I created another Tiddler that is put into the “DefaultTiddlers” Tiddler (which opens any included Tiddlers).
That Tiddler contains the same JavaScript as in listing one above.

Why a Single Page Wiki?
In Wikipedia there is an entry for a Single-Page Application (SPA). This is not exactly the same thing. In that entry the SPA as a functional organization is emphasized. In TiddlyWiki there is an additional physical structure, it is a single page or document.

Some SPAs may be executed from a local file using the file URI scheme. This gives users the ability to download the SPA from a server and run the file from a local storage device, without depending on server connectivity. If such a SPA wants to store and update data, it must be self-modifying. That is, the SPA must be capable of writing itself to disk, including a representation of the state that is to be persisted. Such applications benefit from advances available with HTML5, particularly Web Storage.

There are advantage to this single file approach. First is the small footprint, second is its mobility. Another important reason is usefulness over time. In a reporting or documentation that uses MS Word or any other proprietary (even PDF docs) application, there are no guarantees that a document will be readable by future applications. A TiddlyWiki, on the other hand includes it’s own software and unless there is a breaking change in JavaScript and the whole web stack, will be usable. (I hope!).

Summary
Gave some example JavaScript code to use in TiddlyWiki to use in a HTML replacement for status documents in MS Word. When the TiddlyWiki page is opened the list of status entries are shown in descending date order.

Probably not the best approach, but enough to see if it is viable.

Related
Single-Page Application
open multiple tiddlers macro forum thread.
jsDoIt macro
HTMLFormattingPlugin
My question posted on forum
ForEachTiddlerPlugin


Can’t save a new TiddlyWiki in IE

October 7, 2010

I wrote before about saving issues in Chrome Browser, I now have a similar problem. I downloaded a new TiddlyWiki version and when I try to save a change in it, I get problems in IE browser. I don’t have administrator access to this system, so maybe this is an issue?

Here is the fix which someone mentioned in the TiddlyWiki forum. Just copy the file and save to a new file name. This won’t work with just a file level copy. You have to copy the internals themselves: open the new file in a text editor, I used GVim, then copy the contents into a new editor file and save to a new file. When you open this new file you will get the usual first time IE security and activeX warnings. After that, the TiddlyWiki file is now a “normal” instance.

BTW, I recommend the SinglePageModePlugin. It allows the setting the way TiddlyWiki opens Tiddlers, less confusing, especially for casual TiddlyWiki use.

What the heck is TiddlyWiki? See “TiddlyWiki for the rest of us” for an end-user guide.


Follow

Get every new post delivered to your Inbox.