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')
local accessoriesDiv = container:tag('div')
-- Query accessories and display grouped by type
css(accessoriesDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em;')
-- Query accessories and display as a list
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 accessories = {}
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 accModel = cells[3]
local accDesc = cells[4]
local accDesc = cells[4]
if accPageName then
if accPageName then
table.insert(accessories, {
-- 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,
type = accType,
model = accModel,
desc = accDesc
desc = accDesc
})
})
Line 698: Line 700:
end
end
if #accessories > 0 then
-- Display as label/value rows grouped by type (like Archival Links)
local ul = accessoriesDiv:tag('ul')
for _, accType in ipairs(typeOrder) do
ul:css('margin', '0'):css('padding-left', '1.5em')
local accs = accessoriesByType[accType]
if accs and #accs > 0 then
for _, acc in ipairs(accessories) do
local accLinks = {}
local li = ul:tag('li')
for _, acc in ipairs(accs) do
local displayText = getAccessoryDisplayText(acc.page, brand)
-- Get display text: strip brand prefix if it matches CRT brand
local linkText = displayText
local displayText = getAccessoryDisplayText(acc.page, brand)
if acc.desc and acc.desc ~= '' then
linkText = displayText .. ' – ' .. acc.desc
-- Build the display: model code (optionally with description)
end
local linkText = displayText
table.insert(accLinks, '[[' .. acc.page .. '|' .. linkText .. ']]')
if acc.desc and acc.desc ~= '' then
linkText = displayText .. ' – ' .. acc.desc
end
-- Add type prefix in small text
if acc.type then
li:wikitext('<small>' .. acc.type .. ':</small> [[' .. acc.page .. '|' .. linkText .. ']]')
else
li:wikitext('[[' .. acc.page .. '|' .. linkText .. ']]')
end
end
addRow(container, accType, table.concat(accLinks, '<br>'), true)
end
end
end
end
MediaWiki Appliance - Powered by TurnKey Linux