Module:CRTModel: Difference between revisions
Add Accessories section, smart remote display (strips redundant brand prefix) (via update-page on MediaWiki MCP Server) |
Restyle accessories section: group by type using addRow (label/value grid) instead of bullet list, matching Archival Links style (via update-page on MediaWiki MCP Server) |
||
| Line 651: | Line 651: | ||
addSectionRow(container, 'Accessories') | addSectionRow(container, 'Accessories') | ||
-- Query accessories and display grouped by type | |||
-- Query accessories and display | |||
local accessoriesQueryWikitext = | local accessoriesQueryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
| Line 669: | Line 666: | ||
local accessoriesResult = frame:preprocess(accessoriesQueryWikitext) | local accessoriesResult = frame:preprocess(accessoriesQueryWikitext) | ||
-- Parse accessories from broadtable result | -- Parse accessories from broadtable result and group by type | ||
local | local accessoriesByType = {} | ||
local typeOrder = {} | |||
if accessoriesResult then | if accessoriesResult then | ||
for rowContent in accessoriesResult:gmatch('<tr[^>]*>(.-)</tr>') do | for rowContent in accessoriesResult:gmatch('<tr[^>]*>(.-)</tr>') do | ||
| Line 682: | Line 681: | ||
if #cells >= 2 then | if #cells >= 2 then | ||
local accPageName = cells[1] | local accPageName = cells[1] | ||
local accType = cells[2] | local accType = cells[2] or 'Accessory' | ||
local accDesc = cells[4] | local accDesc = cells[4] | ||
if accPageName then | if accPageName then | ||
table.insert( | -- Track type order for consistent display | ||
if not accessoriesByType[accType] then | |||
accessoriesByType[accType] = {} | |||
table.insert(typeOrder, accType) | |||
end | |||
table.insert(accessoriesByType[accType], { | |||
page = accPageName, | page = accPageName, | ||
desc = accDesc | desc = accDesc | ||
}) | }) | ||
| Line 698: | Line 700: | ||
end | end | ||
-- Display as label/value rows grouped by type (like Archival Links) | |||
for _, accType in ipairs(typeOrder) do | |||
local accs = accessoriesByType[accType] | |||
if accs and #accs > 0 then | |||
for _, acc in ipairs( | local accLinks = {} | ||
for _, acc in ipairs(accs) do | |||
local displayText = getAccessoryDisplayText(acc.page, brand) | |||
local linkText = displayText | |||
if acc.desc and acc.desc ~= '' then | |||
linkText = displayText .. ' – ' .. acc.desc | |||
end | |||
table.insert(accLinks, '[[' .. acc.page .. '|' .. linkText .. ']]') | |||
end | end | ||
addRow(container, accType, table.concat(accLinks, '<br>'), true) | |||
end | end | ||
end | end | ||