FET Question about available date attributes

44 views
Skip to first unread message

TK

unread,
Jan 25, 2011, 8:34:22 PM1/25/11
to TiddlyWiki

G'day

I want to create a list of tiddlers ordered by the date the tiddler
was last opened.

It will be like a breadcrumb trail (though I want to use it as a tool
for maintaining/culling old tiddlers that I rarely visit).

I can use the For Each Tiddler functionality to create the list
ordered by date 'created' or 'modified' e.g.

<<forEachTiddler
where
'tiddler.created'
sortBy 'tiddler.created'
descending
>>

I have examined all the examples on the FET site without finding one
that satisfies my particular need.

So my question: What can i substitute for 'tiddler.created' in the
above piece of code to give me the tiddlers ordered by when they were
last opened?

And a supplamentary question, how could I have discovered this answer
for myself?

Tony

Måns

unread,
Jan 25, 2011, 10:02:26 PM1/25/11
to tiddl...@googlegroups.com
Hi Tony


I want to create a list of tiddlers ordered by the date the tiddler
was last opened.

I don't think a tiddlywiki has any way to know when you have visited/shown a tiddler...
However if you install StorySaverPlugin you can save a "story" of currently open tiddlers or/and automatically save the
current story view in a cookie (txtSavedStory) as a space-separated list of tiddler titles in the order they are displayed.  
Then, when you reload the document, the plugin automatically restores the previous view from the saved cookie value, so that you can just resume
working from where you left off.... Read more about Eric's StorySaverPlugin here.

Cheers Måns Mårtensson

passingby

unread,
Jan 25, 2011, 10:20:26 PM1/25/11
to TiddlyWiki
I am just thinking out loud over here. Maybe you could put something
in the view template which triggers a javascript code which records
the time a tiddler was opened in a separate tiddler. Then another
script should read that tiddler to produce that information in a
formatted form you desire. It would be like putting this into
ViewTemplate:
<span macro="tiddler RecordWhenOpened"></span>
And in the [[RecordWhenOpened]] tiddler would be an inline javascript
which can get access the name of the tiddler into which that script
has been transcluded and then write it down in a separate [[LogBook]]
tiddler along with the current time.
You then would need another script in another tiddler which can read
[[LogBook]] and generate a report in tabular form.
I am off to a weeklong trip to my village(would not have access to a
laptop or internet) so cannot try this myself but I think this is do-
able.

On Jan 26, 8:02 am, Måns <humam...@gmail.com> wrote:
> Hi Tony
>
> I want to create a list of tiddlers ordered by the date the tiddler
>
> > was last opened.
>
> I don't think a tiddlywiki has any way to know when you have visited/shown a
> tiddler...
> However if you install StorySaverPlugin<http://www.tiddlytools.com/#StorySaverPlugin> you
> can save a "story" of currently open tiddlers or/and automatically save the
> current story view in a cookie (txtSavedStory) as a space-separated list of
> tiddler titles in the order they are displayed.  
> Then, when you reload the document, the plugin automatically restores
> the previous view from the saved cookie value, so that you can just resume
> working from where you left off.... Read more about Eric's StorySaverPlugin<http://www.tiddlytools.com/#StorySaverPlugin>
>  here <http://www.tiddlytools.com/#StorySaverPluginInfo>.
>
> Cheers Måns Mårtensson
> <http://www.tiddlytools.com/#StorySaverPlugin>

passingby

unread,
Jan 25, 2011, 10:25:09 PM1/25/11
to TiddlyWiki
Another suggestion. Instead of recording the time of viewing of
tiddler the [[LogBook]] I think it would be better to save the time in
a custom field in the tiddler itself. In this way the info is always
available within the tiddler itself. Any script can then scan the
tiddler for this information.

Eric Shulman

unread,
Jan 25, 2011, 11:35:46 PM1/25/11
to TiddlyWiki, elsd...@gmail.com
> I want to create a list of tiddlers ordered by the date the tiddler
> was last opened.
> I can use the For Each Tiddler functionality to create the list
> ordered by date 'created' or 'modified' e.g.
> So my question:  What can i substitute for 'tiddler.created' in the
> above piece of code to give me the tiddlers ordered by when they were
> last opened?

First, you need to actual keep track of when each tiddler is opened.
To do this, you can *hijack* the TW core's displayTiddler() function,
like this:

//{{{
Story.prototype.save_displayTiddler=Story.prototype.displayTiddler;
Story.prototype.displayTiddler=function(srcElem,tiddler) {
this.save_displayTiddler.apply(this,arguments);
var title=(tiddler instanceof Tiddler)?tiddler.title:tiddler;
if (config.options.chkTrackViews && store.tiddlerExists(title))
store.setValue(title,'viewed',new Date());
}
//}}}

Put the above code into a tiddler tagged with systemConfig (i.e., make
it a plugin). This code first invokes the default core processing (to
display the tiddler), and then, if the tiddler actually exists, and
the 'chkTrackViews' option is enabled, it writes a *custom field*
named 'viewed', containing the current date/time, to the tiddler.

Note: writing the custom field to the tiddler means that every time
you visit a tiddler, the document will become 'dirty' (in need of
saving). The chkTrackViews option allows you to enable/disable
updates to the 'viewed' field, so that you can avoid making document
changes when you don't want them.

To set/clear the chkTrackViews option, you will need to add a checkbox
somewhere in your document (e.g., OptionsPanel), like this:
<<option chkTrackViews>> track tiddler views
Then, after you save-and-reload and enable the checkbox, every time a
tiddler is opened, the 'viewed' field for that tiddler will be
updated. If you clear the checkbox, the most recent 'viewed' values
will be retained, but not updated.

Finally, to create date-ordered <<forEachTiddler>> 'reports' based on
the 'last viewed' field values, you can refer to:
tiddler.fields.viewed

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

Kriss

unread,
Jan 26, 2011, 8:39:48 AM1/26/11
to TiddlyWiki
Nice! :-D

How would I have to chance the *hijack* if I wanted to add a
'viewcount' field as well ? (a counter increasing every time the
tiddler is displayed)

I tried to add just another store.setValue()-line but apparently it is
not just that simple :-$

Kriss

unread,
Jan 26, 2011, 9:34:44 AM1/26/11
to TiddlyWiki
formatString() does not work on this field??

tiddler.created.formatString("YYYY, MMM 0DD")

works fine, but

tiddler.fields.viewed.formatString("YYYY, MMM 0DD")

returns TypeError: tiddler.fields.viewed.formatString is not a function

axelm

unread,
Oct 17, 2011, 6:22:53 PM10/17/11
to tiddl...@googlegroups.com
Has anybody found an answer to Kriss's question?
I get the same error.

axelm


Reply all
Reply to author
Forward
0 new messages