|
|
| Line 172: |
Line 172: |
| end | | end |
|
| |
|
| -- Inputs section: preprocess #ask so it renders, but only show section if there are results | | -- Inputs section: use count query to check if there are any inputs |
| local askWikitext = | | local inputsCountWikitext = |
| '{{#ask:\n' .. | | '{{#ask:\n' .. |
| ' [[Has CRT model::' .. fullPageName .. ']]\n' .. | | ' [[Has CRT model::' .. fullPageName .. ']]\n' .. |
| ' |?Has video signal format=signal\n' .. | | ' [[Has video signal format::+]]\n' .. |
| ' |?Has connector type=connector\n' .. | | ' |format=count\n' .. |
| ' |?Has input count=count\n' ..
| |
| ' |?Has input location=location\n' ..
| |
| ' |format=ul\n' ..
| |
| ' |template=CRT input inline\n' ..
| |
| ' |named args=yes\n' ..
| |
| ' |searchlabel=\n' ..
| |
| '}}' | | '}}' |
| local askHtml = frame:preprocess(askWikitext) | | local inputCount = frame:preprocess(inputsCountWikitext) |
| -- Only display Inputs section if the query returned content (not just whitespace) | | local hasInputs = inputCount and tonumber(trim(inputCount)) and tonumber(trim(inputCount)) > 0 |
| if askHtml and trim(askHtml) then | | |
| | if hasInputs then |
| | local askWikitext = |
| | '{{#ask:\n' .. |
| | ' [[Has CRT model::' .. fullPageName .. ']]\n' .. |
| | ' |?Has video signal format=signal\n' .. |
| | ' |?Has connector type=connector\n' .. |
| | ' |?Has input count=count\n' .. |
| | ' |?Has input location=location\n' .. |
| | ' |format=ul\n' .. |
| | ' |template=CRT input inline\n' .. |
| | ' |named args=yes\n' .. |
| | ' |searchlabel=\n' .. |
| | '}}' |
| | local askHtml = frame:preprocess(askWikitext) |
| | |
| addSectionRow(container, 'Inputs') | | addSectionRow(container, 'Inputs') |
| addFullRow(container, askHtml, 'padding:0.2em 0.4em;', true) | | addFullRow(container, askHtml, 'padding:0.2em 0.4em;', true) |
| Line 198: |
Line 207: |
| end | | end |
|
| |
|
| -- Mods section: Query for mod subobjects and display | | -- Mods section: use count query to check if there are any mods |
| local modsQueryWikitext = | | local modsCountWikitext = |
| '{{#ask:\n' .. | | '{{#ask:\n' .. |
| ' [[Has CRT model::' .. fullPageName .. ']]\n' .. | | ' [[Has CRT model::' .. fullPageName .. ']]\n' .. |
| ' [[Has mod URL::+]]\n' .. | | ' [[Has mod URL::+]]\n' .. |
| ' |?Has mod type=type\n' ..
| | ' |format=count\n' .. |
| ' |?Has mod description=description\n' ..
| |
| ' |?Has mod feasible=feasible\n' ..
| |
| ' |?Has mod URL=url\n' ..
| |
| ' |format=broadtable\n' .. | |
| ' |headers=hide\n' ..
| |
| ' |link=none\n' ..
| |
| '}}' | | '}}' |
| local modsResult = frame:preprocess(modsQueryWikitext) | | local modCount = frame:preprocess(modsCountWikitext) |
|
| | local hasMods = modCount and tonumber(trim(modCount)) and tonumber(trim(modCount)) > 0 |
| -- DEBUG: Always show mods section with raw query result
| |
| addSectionRow(container, 'Mods (DEBUG)')
| |
| local debugDiv = container:tag('div') | |
| css(debugDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em; background:#ffe0e0; font-family:monospace; font-size:80%; white-space:pre-wrap; word-break:break-all;')
| |
| debugDiv:wikitext('Query result length: ' .. tostring(#(modsResult or '')) .. '\n\nRaw result:\n' .. (modsResult or 'NIL'))
| |
|
| |
| -- Parse mods and build display
| |
| local mods = {}
| |
| local hasMods = false
| |
|
| |
| if modsResult then
| |
| -- Match each table row
| |
| for rowContent in modsResult:gmatch('<tr[^>]*>(.-)</tr>') do
| |
| local cells = {}
| |
| -- Extract content from each <td>
| |
| for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do
| |
| -- Strip any remaining HTML tags and get just the text
| |
| local cleanContent = cellContent:gsub('<[^>]+>', '')
| |
| table.insert(cells, trim(cleanContent))
| |
| end
| |
|
| |
| -- DEBUG: Show what we parsed from each row
| |
| local rowDebug = container:tag('div')
| |
| css(rowDebug, 'grid-column: 1 / -1; padding:0.2em 0.4em; background:#e0ffe0; font-family:monospace; font-size:80%;')
| |
| rowDebug:wikitext('Row cells: ' .. #cells .. ' | ' .. table.concat(cells, ' | '))
| |
|
| |
| -- cells[1] = subobject, cells[2] = type, cells[3] = description, cells[4] = feasible, cells[5] = url
| |
| if #cells >= 5 then
| |
| local modType = cells[2]
| |
| local modDescription = cells[3]
| |
| local modFeasible = cells[4]
| |
| local modUrl = cells[5]
| |
|
| |
| if modType and modUrl then
| |
| table.insert(mods, {
| |
| type = modType,
| |
| description = modDescription,
| |
| feasible = modFeasible,
| |
| url = modUrl
| |
| })
| |
| hasMods = true
| |
| end
| |
| end
| |
| end
| |
| end
| |
|
| |
| -- DEBUG: Show parsed mods count
| |
| local countDebug = container:tag('div')
| |
| css(countDebug, 'grid-column: 1 / -1; padding:0.2em 0.4em; background:#e0e0ff; font-family:monospace; font-size:80%;')
| |
| countDebug:wikitext('Parsed mods count: ' .. #mods .. ', hasMods: ' .. tostring(hasMods))
| |
| | | |
| -- Display mods section if there are any mods
| |
| if hasMods then | | if hasMods then |
| | local modsQueryWikitext = |
| | '{{#ask:\n' .. |
| | ' [[Has CRT model::' .. fullPageName .. ']]\n' .. |
| | ' [[Has mod URL::+]]\n' .. |
| | ' |?Has mod type=type\n' .. |
| | ' |?Has mod description=description\n' .. |
| | ' |?Has mod feasible=feasible\n' .. |
| | ' |?Has mod URL=url\n' .. |
| | ' |format=ul\n' .. |
| | ' |template=CRT mod inline\n' .. |
| | ' |named args=yes\n' .. |
| | ' |searchlabel=\n' .. |
| | '}}' |
| | local modsResult = frame:preprocess(modsQueryWikitext) |
| | |
| addSectionRow(container, 'Mods') | | addSectionRow(container, 'Mods') |
| | | addFullRow(container, modsResult, 'padding:0.2em 0.4em;', true) |
| local modsDiv = container:tag('div')
| |
| css(modsDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em;')
| |
|
| |
| local ul = mw.html.create('ul')
| |
| ul:css('margin', '0'):css('padding-left', '1.5em')
| |
|
| |
| for _, mod in ipairs(mods) do
| |
| local li = ul:tag('li')
| |
|
| |
| -- Determine display text
| |
| local displayText = mod.type
| |
| if mod.type == 'Other' and mod.description then
| |
| displayText = mod.description
| |
| elseif mod.description then
| |
| displayText = mod.type .. ' – ' .. mod.description
| |
| end
| |
|
| |
| -- Check if mod is not feasible
| |
| local isFeasible = mod.feasible ~= 'No'
| |
|
| |
| if isFeasible then
| |
| -- Normal link for feasible mods
| |
| li:wikitext('[' .. mod.url .. ' ' .. displayText .. ']')
| |
| else
| |
| -- Red styling with X for impossible mods
| |
| local notFeasibleSpan = mw.html.create('span')
| |
| notFeasibleSpan:css('color', '#dc2626') -- Red color
| |
| notFeasibleSpan:wikitext('✗ ')
| |
|
| |
| local linkSpan = mw.html.create('span')
| |
| linkSpan:css('color', '#dc2626')
| |
| linkSpan:wikitext('[' .. mod.url .. ' ' .. displayText .. ']')
| |
|
| |
| local notPossibleLabel = mw.html.create('span')
| |
| notPossibleLabel:css('color', '#dc2626')
| |
| notPossibleLabel:css('font-style', 'italic')
| |
| notPossibleLabel:css('font-size', '0.9em')
| |
| notPossibleLabel:wikitext(' (not possible)')
| |
|
| |
| li:node(notFeasibleSpan)
| |
| li:node(linkSpan)
| |
| li:node(notPossibleLabel)
| |
| end
| |
| end
| |
|
| |
| modsDiv:node(ul)
| |
| end | | end |
|
| |
|