Update entity state tiddlers on startup to read bag and recipe info

This commit is contained in:
Jeremy Ruston 2024-01-19 11:03:27 +00:00
parent 4133e7d6d6
commit 9767e7d3b7
2 changed files with 21 additions and 0 deletions

View File

@ -42,6 +42,7 @@ exports.startup = function() {
databasePath: databasePath
});
$tw.sqlTiddlerStore.createTables();
$tw.sqlTiddlerStore.updateAdminWiki();
// Create bags and recipes
$tw.sqlTiddlerStore.createBag("bag-alpha");
$tw.sqlTiddlerStore.createBag("bag-beta");

View File

@ -57,6 +57,26 @@ SqlTiddlerStore.prototype.saveEntityStateTiddler = function(tiddler) {
this.adminWiki.addTiddler(new $tw.Tiddler(tiddler,{title: this.entityStateTiddlerPrefix + tiddler.title}));
};
SqlTiddlerStore.prototype.updateAdminWiki = function() {
// Update bags
for(const bagInfo of this.listBags()) {
this.saveEntityStateTiddler({
title: "bags/" + bagInfo.bag_name,
"bag-name": bagInfo.bag_name,
text: ""
});
}
// Update recipes
for(const recipeInfo of this.listRecipes()) {
this.saveEntityStateTiddler({
title: "recipes/" + recipeInfo.recipe_name,
"recipe-name": recipeInfo.recipe_name,
text: "",
list: $tw.utils.stringifyList(this.getRecipeBags(recipeInfo.recipe_name))
});
}
};
SqlTiddlerStore.prototype.createTables = function() {
this.runStatements([`
-- Bags have names and access control settings