As a learning exercise, I’m working on a javascript macro to select and pick filenames from a webDAV server. I may have bitten off more than I can chew Functionally, the macro seems to work, but for each attempt read of a webDAV directory, the js macro is invoked three times, apparently as part of the “TW refresh processing”. I found a reference in TW documentation:
“Macros are just used to return a chunk of wikitext for further processing. They should not make modifications to tiddlers in the wiki store. The reason is that you cannot control when the macro is called; it may be called repeatedly as part of refresh processing. So it is important that macros do not have any other side effects beyond generating their text.”
I tried to pass a flag (below) to the js macro so it can return immediately if it’s not being deliberately invoked, to no avail. Those extra calls were made while the proper macro call is being made (from within a conditional statement) and while the flag was set. OTOH, this is already an improvement over an earlier iteration where the JS macro is spontaneously invoked for every file in the directory within a $LIST loop!
The nature of this ‘refreshing’ is mystifying to me.
<$action-deletefield $tiddler="@Art_datadict" ButtonActive/> <!--- @Art_readDir will run only if ButtonActive FIELD don't exist and flag != 'No' ; testing --->
<$set name="var_ButtonActive" filter="[[@Art_datadict]field:ButtonActive[]]" value='1' emptyValue="No" >
<$set name="var_readDir" filter="[[@Art_datadict]field:ButtonActive[]]" emptyValue="{}" value='<$macrocall $name="@Art_readDir" webdavurl={{@Art_datadict!!webdavurl}} webdavdir={{@Art_datadict!!webdavdir}} flag=<<var_ButtonActive>> />' >
<$wikify name=wiki_Dir text=<<var_readDir>> >
<$action-setfield $tiddler="@Art_datadict" text=<<wiki_Dir>> />
<$action-setfield $tiddler="@Art_datadict" ButtonActive="SET"/>
On Android (using RCX) and Windows (using Hacdias webdav server), the response time from webdav server is still ok, but on a Chromebook (using Hacdias webdav server) the response time is slow enough to trigger a not responding message from Tiddywiki.
My question is is there anything that can be done at the Wikitext level so the js macro is called only once, or minimally ?
Also, is a javascript macro the wrong approach for this purpose of selecting files from a webdav server ?
Oh, I know Saqimtiaz has a better webDAV solution if i really need to use webDAV So this is really just a learning experience for me. I do seem to be tantalizingly close to getting it done (js macro in json attached), so would like to see if I can get pass this hurdle.
JArt_webdav_filepicker_trial.json (17.0 KB)
JacN