Is it possible to query the nodejs server with a macro?

88 views
Skip to first unread message

Conner Phillips

unread,
May 29, 2017, 5:57:36 PM5/29/17
to tiddly...@googlegroups.com
What I would like to do:

Add a history tab to the ViewTemplate

This tab displays the results of a query to the server which runs and parses some git log commands.

It seems in the past this was strictly not possible, but now I'm not so sure.

Matthew Lauber

unread,
May 30, 2017, 10:28:17 PM5/30/17
to TiddlyWikiDev
Since you can write a javascript macro, it is _possible_ to use any of the functionality that the tiddlywiki itself provides. Therefore it is possible to run ajax requests to query the API.  That said, I'm going to bet it's not the easiest thing in the world.  This is probably a good place to start.  http://tiddlywiki.com/dev/index.html#JavaScript%20Macros  I'd also take a look at the files here for examples. https://github.com/Jermolene/TiddlyWiki5/tree/master/core/modules/macros

Conner Phillips

unread,
May 31, 2017, 8:30:14 AM5/31/17
to tiddly...@googlegroups.com
Okay, this says that "Note that JavaScript macros work on both the client and the server, and so do not have access to the browser DOM."

However, the issue true issue is that I am trying to load an npm module server side. The browser keeps complaining it isn't able to find it though.The specific module in question is simple-git

Looking around, would the most reasonable way to get this information from the server be an ajax.get, with separate code to handle it in the server side. The closest explanation I can find for such things is here: https://groups.google.com/forum/#!searchin/tiddlywikidev/ajax$20get|sort:relevance/tiddlywikidev/ICWbeY2CtwU/hdGqeol-t14J but I have a hard time following the conversation. Sorry I'm not so very clear about all this, I'm a physicist, no network developer!

Jeremy Ruston

unread,
Jun 3, 2017, 12:52:41 PM6/3/17
to TiddlyWikiDev
Hi Conner

Apologies for being late to respond. You're doing some interesting stuff.

The current approach for communicating between the browser and the server is to layer things on top of the existing tiddler synchronisation mechanism. This reflects a principle in TiddlyWiki's design: to strive for the minimum number of mechanisms, and to reuse them as much as possible.

In this case, you could use a single system tiddler to coordinate things. To trigger the command, the browser UI might set the text of the tiddler $:/commands/gitlog to the name of a tiddler that should contain the results of the gitlog command. The server has a wiki store change event handler that looks for modifications to that tiddler, and fires off the gitlog command when it sees the tiddler text changing. On completion, the server process would place the results of the command in the specified tiddler. The tiddler value would eventually propagate to the browser where a simple transclusion will cause it to be displayed where required.

There are some issues: currently there's a 60 second lag for changes to propagate from the server to the browser. That's partly because the polling mechanism is not very sophisticated. That all needs improving, but it's probably easier than introducing a wholly new transport system.

Best wishes

Jeremy





On Wed, May 31, 2017 at 1:30 PM, Conner Phillips <conner.r...@gmail.com> wrote:
Okay, this says that "Note that JavaScript macros work on both the client and the server, and so do not have access to the browser DOM."

However, the issue true issue is that I am trying to load an npm module server side. The browser keeps complaining it isn't able to find it though.The specific module in question is simple-git
On Wednesday, May 31, 2017 at 4:28:17 AM UTC+2, Matthew Lauber wrote:
Since you can write a javascript macro, it is _possible_ to use any of the functionality that the tiddlywiki itself provides. Therefore it is possible to run ajax requests to query the API.  That said, I'm going to bet it's not the easiest thing in the world.  This is probably a good place to start.  http://tiddlywiki.com/dev/index.html#JavaScript%20Macros  I'd also take a look at the files here for examples. https://github.com/Jermolene/TiddlyWiki5/tree/master/core/modules/macros

On Monday, May 29, 2017 at 5:57:36 PM UTC-4, Conner Phillips wrote:
What I would like to do:

Add a history tab to the ViewTemplate

This tab displays the results of a query to the server which runs and parses some git log commands.

It seems in the past this was strictly not possible, but now I'm not so sure.

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+unsubscribe@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/eaed9876-dbd0-4b78-85b9-445301d7b5f8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Conner Phillips

unread,
Jun 6, 2017, 7:04:50 AM6/6/17
to TiddlyWikiDev
I know this probably puts my modifications in the realm of a fork than a plugin, but I added a GET handler to the server. At the moment it is still very basic, but I use an http query to address mytwlocation/gitlog. The server handles requests to this url, gets the log, and returns the JSON string. Works fine with no delay. I will comment with some implementation details later.
Reply all
Reply to author
Forward
0 new messages