Module:ProfessionList: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
Line 48: Line 48:
-- the queryString is just a selection of pages, from any combination of SMW properties and categories
-- the queryString is just a selection of pages, from any combination of SMW properties and categories
-- for pages with multiple recipes or activities, will make on entry into the results table for each
-- for pages with multiple recipes or activities, will make on entry into the results table for each
-- screenFunction takes a decoded recipe/activity JSON and returns true if it is to be kept
function p.generate_recipe_table(queryString)
function p.generate_recipe_table(queryString,screenFunction)
-- first formulate the query to get the list of pages
-- first formulate the query to get the list of pages
Line 66: Line 67:
end
end
-- output structure
-- collate structure
local output = {}
local recipes = {}
-- iterate through pages found
-- iterate through pages found
Line 79: Line 80:
for _, JSON in ipairs(page.activityJSON) do
for _, JSON in ipairs(page.activityJSON) do
local item = mw.text.jsonDecode(JSON)
local item = mw.text.jsonDecode(JSON)
item.page = page.pageName
item.pageName = page.pageName
item.pageImage = page.pageImage
item.pageImage = page.pageImage
item.type = 'activity'
item.type = 'activity'
table.insert(output,item)
table.insert(recipes,item)
end
end
end
end
Line 93: Line 94:
for _, JSON in ipairs(page.recipeJSON) do
for _, JSON in ipairs(page.recipeJSON) do
local item = mw.text.jsonDecode(JSON)
local item = mw.text.jsonDecode(JSON)
item.page = page.pageName
item.pageName = page.pageName
item.pageImage = page.pageImage
item.pageImage = page.pageImage
item.type = 'recipe'
item.type = 'recipe'
table.insert(output,item)
table.insert(recipes,item)
end
end
end
end
Line 102: Line 103:
end
end
-- output structure
local output = {}
-- screen using screenfunction
for _, item in ipairs(recipes) do
if screenfunction(item) then
table.insert(output,item)
end
end

-- sort the output by the .level parameter
-- sort the output by the .level parameter
table.sort(output, function(item1, item2)
table.sort(output, function(item1, item2)
Line 120: Line 131:
end
end



return p
return p