1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Make getRecipeTiddlers return the bagname as well

This commit is contained in:
Jeremy Ruston 2024-01-20 20:22:46 +00:00
parent e9f83ca735
commit 59aed49e98
4 changed files with 37 additions and 27 deletions

View File

@ -24,12 +24,12 @@ exports.handler = function(request,response,state) {
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]);
if(recipe_name === recipe_name_2) {
// Get the tiddlers in the recipe
var titles = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name);
var recipeTiddlers = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name);
// Get a skinny version of each tiddler
var tiddlers = [];
$tw.utils.each(titles,function(title) {
var tiddlerInfo = $tw.sqlTiddlerStore.getRecipeTiddler(title,recipe_name);
tiddlers.push(Object.assign({},tiddlerInfo.tiddler,{text: undefined, revision: "0", bag: "bag-gamma"}));
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
var tiddlerInfo = $tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
tiddlers.push(Object.assign({},tiddlerInfo.tiddler,{text: undefined, revision: "0", bag: recipeTiddlerInfo.bag_name}));
});
var text = JSON.stringify(tiddlers);
state.sendResponse(200,{"Content-Type": "application/json"},text,"utf8");

View File

@ -26,7 +26,7 @@ exports.handler = function(request,response,state) {
"Content-Type": "text/html"
});
// Get the tiddlers in the recipe
var titles = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name);
var recipeTiddlers = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name);
// Render the template
var template = $tw.sqlTiddlerStore.adminWiki.renderTiddler("text/plain","$:/core/templates/tiddlywiki5.html",{
variables: {
@ -49,19 +49,19 @@ exports.handler = function(request,response,state) {
throw new Error("Cannot find tiddler store in template");
}
response.write(template.substring(0,markerPos + marker.length));
$tw.utils.each(titles,function(title) {
var tiddlerInfo = $tw.sqlTiddlerStore.getRecipeTiddler(title,recipe_name);
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
var tiddlerInfo = $tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
if((tiddlerInfo.tiddler.text || "").length > 10 * 1024 * 1024) {
response.write(JSON.stringify(Object.assign({},tiddlerInfo.tiddler,{
revision: "0",
bag: "bag-gamma",
bag: recipeTiddlerInfo.bag_name,
text: undefined,
_canonical_uri: `/wiki/${recipe_name}/recipes/${recipe_name}/tiddlers/${title}`
})));
} else {
response.write(JSON.stringify(Object.assign({},tiddlerInfo.tiddler,{
revision: "0",
bag: "bag-gamma"
bag: recipeTiddlerInfo.bag_name
})));
}
response.write(",")

View File

@ -387,22 +387,20 @@ Get the titles of the tiddlers in a recipe. Returns an empty array for recipes t
*/
SqlTiddlerStore.prototype.getRecipeTiddlers = function(recipename) {
const rows = this.runStatementGetAll(`
SELECT DISTINCT title
FROM tiddlers
WHERE bag_id IN (
SELECT bag_id
FROM recipe_bags
WHERE recipe_id = (
SELECT recipe_id
FROM recipes
WHERE recipe_name = $recipe_name
)
SELECT title, bag_name
FROM (
SELECT t.title, b.bag_name, MAX(rb.position) AS position
FROM bags AS b
INNER JOIN recipe_bags AS rb ON b.bag_id = rb.bag_id
INNER JOIN recipes AS r ON rb.recipe_id = r.recipe_id
INNER JOIN tiddlers AS t ON b.bag_id = t.bag_id
WHERE r.recipe_name = $recipe_name
GROUP BY title
)
ORDER BY title ASC
`,{
recipe_name: recipename
});
return rows.map(value => value.title);
return rows;
};
/*

View File

@ -42,8 +42,14 @@ describe("SQL tiddler store", function() {
sqlTiddlerStore.saveBagTiddler({title: "Hello There",text: "I'm in beta",tags: "four five six"},"bag-beta");
sqlTiddlerStore.saveBagTiddler({title: "Hello There",text: "I'm in gamma",tags: "seven eight nine"},"bag-gamma");
// Verify what we've got
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-rho")).toEqual([ "Another Tiddler", "Hello There"]);
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-sigma")).toEqual([ "Another Tiddler", "Hello There"]);
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-rho")).toEqual([
{ title: 'Another Tiddler', bag_name: 'bag-alpha' },
{ title: 'Hello There', bag_name: 'bag-beta' }
]);
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-sigma")).toEqual([
{ title: 'Another Tiddler', bag_name: 'bag-alpha' },
{ title: 'Hello There', bag_name: 'bag-gamma' }
]);
expect(sqlTiddlerStore.getRecipeTiddler("Hello There","recipe-rho").tiddler).toEqual({ title: "Hello There", text: "I'm in beta", tags: "four five six" });
expect(sqlTiddlerStore.getRecipeTiddler("Missing Tiddler","recipe-rho")).toEqual(null);
expect(sqlTiddlerStore.getRecipeTiddler("Another Tiddler","recipe-rho").tiddler).toEqual({ title: "Another Tiddler", text: "I'm in alpha", tags: "one two three" });
@ -52,12 +58,18 @@ describe("SQL tiddler store", function() {
expect(sqlTiddlerStore.getRecipeTiddler("Hello There","recipe-upsilon").tiddler).toEqual({title: "Hello There",text: "I'm in beta",tags: "four five six"});
// Delete a tiddlers to ensure the underlying tiddler in the recipe shows through
sqlTiddlerStore.deleteTiddler("Hello There","bag-beta");
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-rho")).toEqual([ "Another Tiddler", "Hello There"]);
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-sigma")).toEqual([ "Another Tiddler", "Hello There"]);
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-rho")).toEqual([
{ title: 'Another Tiddler', bag_name: 'bag-alpha' },
{ title: 'Hello There', bag_name: 'bag-alpha' }
]);
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-sigma")).toEqual([
{ title: 'Another Tiddler', bag_name: 'bag-alpha' },
{ title: 'Hello There', bag_name: 'bag-gamma' }
]);
expect(sqlTiddlerStore.getRecipeTiddler("Hello There","recipe-beta")).toEqual(null);
sqlTiddlerStore.deleteTiddler("Another Tiddler","bag-alpha");
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-rho")).toEqual([ "Hello There"]);
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-sigma")).toEqual([ "Hello There"]);
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-rho")).toEqual([ { title: 'Hello There', bag_name: 'bag-alpha' } ]);
expect(sqlTiddlerStore.getRecipeTiddlers("recipe-sigma")).toEqual([ { title: 'Hello There', bag_name: 'bag-gamma' } ]);
// Save a recipe tiddler
sqlTiddlerStore.saveRecipeTiddler({title: "More", text: "None"},"recipe-rho");
expect(sqlTiddlerStore.getRecipeTiddler("More","recipe-rho").tiddler).toEqual({title: "More", text: "None"});