Updating a tiddler from a text-file on the server before performing an action ...and uploading an updated version

Hi Tiddlywikians,
I volunteered for a job in my food-coop which I thought would be easy to solve in TW.
I promised to create a sort of doodle where people can choose the time they do some necessary tasks which is the stored in a dictionary tiddler.

It turns out that I somehow miscalulated the task, because in TW if two people save in the same time, or download the wiki and save the result much later one result is lost ( I am on php single file setup).

My approach now is to update a single Tiddler by

  • retrievieng it from a txt-file on the server with http-request, :white_check_mark: :question:
  • perform the action to create a new dictionary-tiddler and
  • post an updated version of the dictionary-tiddler 1sec later with .js :question:
  • to save it on the server with the help of a php-file. :white_check_mark:

I can build a http request that you find down below.

But I do not know how to perform the upload which in this case cannot be done with a simple form like demonstrated here, but has to be triggered with .js to be performed after the other actions.

Who can teach me how to upload a tiddlers text to a php

/*\
title: $:/plugins/JJ/InterAction/macros/dataurl.js
type: application/javascript
module-type: macro
Macro to fetch an integrate a textfile from the server.
\*/

(function(){
   /*jslint node: true, browser: true */
   /*global $tw: false */
   "use strict";

/*
Information about this macro
*/
   exports.name = "getdata";

/*
Run the macro
*/
   exports.run = function() {
      var dataurl = "data.txt";
      var client = new XMLHttpRequest();client.open('GET', dataurl , false);
      client.setRequestHeader('Content-type', 'Content-Type: text/html; charset=ISO-8859-1');
      client.onreadystatechange = function() {
    if (client.readyState == 4 && client.status == 200)
    {
      var data = client.responseText;
      var fields = {title: '$:/temp/data', text:  data}
       $tw.wiki.addTiddler(new $tw.Tiddler(fields))
    }
  } 
   client.send();

})();
1 Like

I thougth this to work when triggered from a button

<$button class="tc-btn-invisible">
<$macrocall $name="getdata"/>Test
</$button>

and if data.text is present on the server next to theindex.html…

Well … should work, but it does not work yet. So debugging is appreciated here also…

I would recommend not reinventing the wheel and checking out TW5-Bob. The caveat is that it uses a node version. The description reads:

A plugin that makes tiddlywiki a multi-user wiki on node

I have used it in the past with great success. It has a ton of very useful features.

I am no expert but typically such macros are created as the particular type of “action macros”. Have a look inside some existing action macro .js files may give you some clues.

I think you may need developer help for this one.