From 4b0df1a7ae7f99f4c83eafc2feee16b80f3a4b2e Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 19 Jan 2024 11:03:58 +0000 Subject: [PATCH] Basic support for creating bags and recipes Cannot yet specify the bags for the new recipe --- .../MultiWikiServer Administration.tid | 52 +++++++++++++++++++ .../multiwikiserver/modules/route-put-bag.js | 36 +++++++++++++ .../modules/route-put-recipe.js | 36 +++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 plugins/tiddlywiki/multiwikiserver/modules/route-put-bag.js create mode 100644 plugins/tiddlywiki/multiwikiserver/modules/route-put-recipe.js diff --git a/plugins/tiddlywiki/multiwikiserver/admin-ui/MultiWikiServer Administration.tid b/plugins/tiddlywiki/multiwikiserver/admin-ui/MultiWikiServer Administration.tid index c36aa86b0..4521d1fc6 100644 --- a/plugins/tiddlywiki/multiwikiserver/admin-ui/MultiWikiServer Administration.tid +++ b/plugins/tiddlywiki/multiwikiserver/admin-ui/MultiWikiServer Administration.tid @@ -1,5 +1,51 @@ title: MultiWikiServer Administration +\procedure createBag(name) + +\procedure completion-createBag() +\import [subfilter{$:/core/config/GlobalImportFilter}] + <$action-log msg="In completion-createBag"/> + <$action-log/> +\end completion-createBag + +<$action-sendmessage + $message="tm-http-request" + url=`/wiki/$(name)$/bags/$(name)$` + method="PUT" + oncompletion=<> +/> +\end createBag + +\procedure createBagButton(name) +<$button class=""> +<$transclude $variable="createBag" name={{$:/state/NewBagName}}/> +{{$:/core/images/new-button}} +<$text text="Create a new bag:"/><$edit-text tiddler="$:/state/NewBagName" tag="input"/> +\end createBagButton + +\procedure createRecipe(name) + +\procedure completion-createRecipe() +\import [subfilter{$:/core/config/GlobalImportFilter}] + <$action-log msg="In completion-createRecipe"/> + <$action-log/> +\end completion-createRecipe + +<$action-sendmessage + $message="tm-http-request" + url=`/wiki/$(name)$/recipes/$(name)$` + method="PUT" + oncompletion=<> +/> +\end createRecipe + +\procedure createRecipeButton(name) +<$button class=""> +<$transclude $variable="createRecipe" name={{$:/state/NewRecipeName}}/> +{{$:/core/images/new-button}} +<$text text="Create a new recipe:"/><$edit-text tiddler="$:/state/NewRecipeName" tag="input"/> +\end createRecipeButton +

Recipes

    @@ -19,6 +65,9 @@ title: MultiWikiServer Administration
+<> +
+
Higher numbered bags take priority if a tiddler with the same title is in more than one bag

Bags

@@ -29,4 +78,7 @@ Higher numbered bags take priority if a tiddler with the same title is in more t +
+<> +
\ No newline at end of file diff --git a/plugins/tiddlywiki/multiwikiserver/modules/route-put-bag.js b/plugins/tiddlywiki/multiwikiserver/modules/route-put-bag.js new file mode 100644 index 000000000..7a4ad94c5 --- /dev/null +++ b/plugins/tiddlywiki/multiwikiserver/modules/route-put-bag.js @@ -0,0 +1,36 @@ +/*\ +title: $:/plugins/tiddlywiki/multiwikiserver/route-put-bag.js +type: application/javascript +module-type: route + +PUT /wikis/:bag_name/bags/:bag_name + +NOTE: Urls currently include the bag name twice. This is temporary to minimise the changes to the TiddlyWeb plugin + +\*/ +(function() { + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.method = "PUT"; + +exports.path = /^\/wiki\/([^\/]+)\/bags\/([^\/]+)$/; + +exports.handler = function(request,response,state) { + // Get the parameters + var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]), + bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]); + if(bag_name === bag_name_2) { + $tw.sqlTiddlerStore.createBag(bag_name); + state.sendResponse(204,{ + "Content-Type": "text/plain" + }); + } else { + response.writeHead(404); + response.end(); + } +}; + +}()); diff --git a/plugins/tiddlywiki/multiwikiserver/modules/route-put-recipe.js b/plugins/tiddlywiki/multiwikiserver/modules/route-put-recipe.js new file mode 100644 index 000000000..7793bcf5b --- /dev/null +++ b/plugins/tiddlywiki/multiwikiserver/modules/route-put-recipe.js @@ -0,0 +1,36 @@ +/*\ +title: $:/plugins/tiddlywiki/multiwikiserver/route-put-recipe.js +type: application/javascript +module-type: route + +PUT /wikis/:recipe_name/recipes/:recipe_name + +NOTE: Urls currently include the recipe name twice. This is temporary to minimise the changes to the TiddlyWeb plugin + +\*/ +(function() { + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.method = "PUT"; + +exports.path = /^\/wiki\/([^\/]+)\/recipes\/([^\/]+)$/; + +exports.handler = function(request,response,state) { + // Get the parameters + var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]), + recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]); + if(recipe_name === recipe_name_2) { + $tw.sqlTiddlerStore.createRecipe(recipe_name); + state.sendResponse(204,{ + "Content-Type": "text/plain" + }); + } else { + response.writeHead(404); + response.end(); + } +}; + +}());