auto numbering tiddlers

13 views
Skip to first unread message

okido

unread,
Sep 8, 2008, 12:18:07 PM9/8/08
to TiddlyWikiDev
I use the code below to create sequential numbered tiddlers, tiddler
tittle is 4 digits
The counter for the tiddler to be created tiddler is stored in a
tiddler using the datatiddler plugin.
This is all functional but I would rather use something like:

config.options.txtCounter = "56"; and increase this by 1 everytime,

I gave it a try but after reloading it always starts with in this case
56.
Any help is appreciated.

Second question is were can a find info on
the ......autoNumber.handler=function(...... more specific how does it
work?

***/
//{{{
config.macros.autoNumber={};
config.macros.autoNumber.handler=
function(place,macroName,params,wikifier,paramString,tiddler){
var label = params[0]||"New Record";
var tooltip = params[1]||"You are going to make a new record";
createTiddlyButton(place,label,tooltip,this.onclick);
}

config.macros.autoNumber.onclick= function()
{
var newTags = ' valid';
var newNumber = DataTiddler.getData("run_data","nmr");
var dt = new Date();
var newBody = '<<tiddler Tableview>>';
var newTitle='000'+newNumber;
newTitle=newTitle.substr(newTitle.length-4,4);
store.saveTiddler(
newTitle,
newTitle,
newBody,
config.options.txtUserName,
dt,
newTags);

displayMessage('New item created');

DataTiddler.setData("run_data","nmr",newNumber+1); // increase
number counter by 1

story.displayTiddler('top',newTitle); //open created tiddler
saveChanges(); // save all

}
//}}}

Have a nice day, okido

okido

unread,
Sep 8, 2008, 12:39:10 PM9/8/08
to TiddlyWikiDev
I use the code below to create tiddlers with a four digit number.
The next number to be used is stored in the tiddler run_data with the
Datatiddler plugin, this is functional.

But I would like to be less dependent of the Datatiddler plugin and
use something like:

config.options.tctCounter = "56"; but this I can not get to work,
after reloading the TW it starts at 56 again.
Any help appreciated.

The second question is about
the .....autoNumber.handler=function(...... what does it do and were
can I find info about it??

***/
//{{{
config.macros.autoNumber={};
config.macros.autoNumber.handler=
function(place,macroName,params,wikifier,paramString,tiddler){
var label = params[0]||"New Record";
var tooltip = params[1]||"You are going to make a new record";
createTiddlyButton(place,label,tooltip,this.onclick);
}

config.macros.autoNumber.onclick= function()
{
var newTags = ' valid';
var newNumber = DataTiddler.getData("run_data","nmr");
var dt = new Date();
var newBody = '<<tiddler Tableview>>';
var newTitle='000'+newNumber;
newTitle=newTitle.substr(newTitle.length-4,4); // thanks
to Eric
store.saveTiddler(
newTitle,
newTitle,
newBody,
config.options.txtUserName,
dt,
newTags);

displayMessage('New item created');

DataTiddler.setData("run_data","nmr",newNumber+1); // increase
number counter by 1

story.displayTiddler('top',newTitle); //open created tiddler
saveChanges(); // save all

}
//}}}

Have a nice day, Okido

FND

unread,
Sep 9, 2008, 6:35:17 AM9/9/08
to Tiddly...@googlegroups.com
> I use the code below to create sequential numbered tiddlers

I assume you are trying to create a unique identifier for each tiddler
that way?
Have you considered what happens when importing tiddlers into other
documents? You might wanna use GUIDs/UUIDs instead of sequential numbers.

> The counter for the tiddler to be created tiddler is stored in a

> tiddler using the datatiddler plugin. [...] I would rather use
> something like [...] config.options.txtCounter

Well, config.options are stored in cookies - so they depend on the
respective user's browser session, and thus seem unsuitable for this task.
So I'd say storing that data in a tiddler (slice) is the correct thing
to do.

> were can a find info on
> the ......autoNumber.handler=function(...... more specific how does it
> work?

Macro handlers (config.macros.*.handler) are invoked when the respective
macro is being rendered. All handlers are passed the following arguments:
* place: the respective macro call's containing DOM object
* macroName: the respective macro's name
* params: macro parameters as an array
* wikifier: the wikifier object being used
* paramString: macro parameters as a string
* tiddler: the respective macro call's containing tiddler

In contrast, the init function (config.macros.*.init) is executed on
startup and takes no arguments.

I've added this to the community wiki:
http://www.tiddlywiki.org/wiki/Dev:Macros#Macro_Execution
Feel free to improve/correct the information there.

HTH.


-- F.

okido

unread,
Sep 9, 2008, 12:10:06 PM9/9/08
to TiddlyWikiDev
Hi FND,

By numbering sequential it is easy to sort, and the numbers are
unique, like IDs that are used in databases.
I was also thinking about storing the counter var in the macro itself
and than after the creation of a tiddler rewrite the counter var with
a replace function.
Would be possible I think???

Thanks for the info, Okido

Anthony Muscio

unread,
Sep 9, 2008, 9:51:21 PM9/9/08
to Tiddly...@googlegroups.com
Okido,

I went down this path myself in the early days of my tiddlywiki experience. I realised I needed to make a paradigm shift.

Your say "By numbering sequential it is easy to sort, and the numbers are

unique, like IDs that are used in databases".

But you can only have the advantage of sorting in the order they were created and you can use the created and modified dates in ForEachTiddler and other sorts. If the title is a natural name then you have an additional sort field.

Tiddlers must be unique and this is enforced. You can also use the permalink command to get a full and unique reference to your tiddler which can also be valid across all possible tiddlywiki files and locations. eg file:///S:/Wiki/MasterDBV4.html#[[Fred]] and can provide a link to any other tiddler.

The New means new plugin could be used to number successive items of the same name. Automatically.

However if you want more database type of features investigate the DataTiddlerPlugin, slices, and tiddler fields.

Regards TonyM

On Wed, Sep 10, 2008 at 02:10, okidookido <bkn...@gmail.com> wrote:

Hi FND,

By numbering sequential it is easy to sort, and the numbers are
unique, like IDs that are used in databases.
I was also thinking about storing the counter var in the macro itself
and than after the creation of a tiddler rewrite the counter var with
a replace function.
Would be possible I think???

Thanks for the iOkidoOkido



On Sep 9, 12:35 pm, FND <F...@gmx.net> wrote:
> > I use the code below to create sequential numbered tiddlers
>
> I assume you are trying to create a unique identifier for each tiddler
> that way?
> Have you considered what happens when importing tiddlers into other
> documents? You might wannaGUIDsGUIDsUUIDsUUIDs instead of sequential numbers.

>
> > The counter for the tiddler to be created tiddler is stored in a
> > tiddler udatatiddlerdatatiddler plugin. [...] I would rather use
> > something like [...] config.options.txtCounter
config

ell, config.options are stored in cookies - so they depend on the
> respective user's browser session, and thus seem unsuitable for this task.
> So I'd say storing that data in a tiddler (slice) is the correct thing
> to do.
>
> > were can a find info on
> > the ......autoNumber.handler=function(...... more specific how does it
> > work?
>
> Macro handlers (config.macros.*.handler) are invoked when the respective
> macro is being rendered. All handlers are passed the following arguments:
> * place: the respecall'smacro call's containing DOM macroName
* macroName: the respective macroparamse
> * params: macro parameters as awikifier
> * wikifierwikifier: the wikifier oparamString used

> * paramString: macro parameters as a string
> * tiddler:call'sespective macro call's containing tiddler
init
In contrast, the init function (config.macros.*.istartup executed on

> startup and takes no arguments.
>
> I've added this to the community wiki:
>      http://www.tiddlywiki.org/wiki/Dev:Macros#Macro_Execution
> Feel free to improve/correct the information there.
>
> HTH.
>
> -- F.



--
Anthony Muscio

Anthony Muscio

unread,
Sep 9, 2008, 9:55:29 PM9/9/08
to Tiddly...@googlegroups.com
I should have proof read before posting sorry;

Delete;

But you can only have the advantage of sorting in the order they were created and you can use the created and modified dates in ForEachTiddler and other sorts. If the title is a natural name then you have an additional sort field.

Replace With.
But with numbers in the name you can only have the advantage of sorting in the order they were numbered/created
But
you can use the created and modified dates in ForEachTiddler and other sorts instead for the same result, so why use numbered records. If the title is a natural name then you have an additional sort field available.

Tony
--
Anthony Muscio

FND

unread,
Sep 10, 2008, 3:07:15 AM9/10/08
to Tiddly...@googlegroups.com
> By numbering sequential it is easy to sort, and the numbers are
> unique, like IDs that are used in databases.

The numbers are unique only as long as the tiddlers are not shared
between documents.
Tony's suggestion of using tiddler.created instead sounds reasonable.

> I was also thinking about storing the counter var in the macro itself
> and than after the creation of a tiddler rewrite the counter var with
> a replace function.

So you want to dynamically modify the respective plugin tiddler to
increment the initialization variable? I don't think that's such a good
idea...


-- F.

jean-cédric

unread,
Sep 10, 2008, 3:53:39 AM9/10/08
to TiddlyWikiDev
> Tony's suggestion of using tiddler.created instead sounds reasonable.

YYYY0MM0DD0hh0mm0ss+incremental number

like : 200809100952031

Fully sortable, understandable and still easy parsable

Ken Girard

unread,
Sep 10, 2008, 8:50:13 AM9/10/08
to TiddlyWikiDev
The AlternateBackupPlugin might give you some ideas.
(http://no-sin.com/wiki/WorkTracker.html#AlternateBackupPlugin)
It saves a rotating set of backups in the format of 'filename.1.html',
'filename.2.html', etc.
When it gets to 10 it starts over.
Only problem is I believe it stores the current number as a cookie, so
if you go to a different computer or clean out your cookies you are
back at number one.
There should be a way to get it to write the current number in when it
makes the copy, say in a custom field, but it is beyond me.

Ken Girard

okido

unread,
Sep 10, 2008, 2:18:07 PM9/10/08
to TiddlyWikiDev
The 4 digit number is used on a paper document and makes the paper
docs easy traceable.
Regarding sorting I agree that the creation date can be used.
I already use a custom field in a tiddler and retrieve the counter
number with the Datatiddler plugin.
I give it a go to dynamically modify the plugin tiddler to increment
the initialization variable, basically this is the same as using the
Datatiddler.

Have a nice day, Okido


Reply all
Reply to author
Forward
0 new messages