Module:CRTModel: Difference between revisions
No edit summary |
No edit summary |
||
| Line 20: | Line 20: | ||
end | end | ||
local function addSectionRow( | local function addSectionRow(container, title) | ||
local | local section = container:tag('div') | ||
css( | css(section, 'grid-column: 1 / -1; text-align:center; padding:0.5em; background:#e0e0e0; font-weight:bold;') | ||
section:wikitext(title) | |||
end | end | ||
local function addRow( | local function addRow(container, label, valueHtmlOrWikitext, isRawHtml) | ||
local | local labelDiv = container:tag('div') | ||
css( | css(labelDiv, 'padding:0.2em 0.4em; font-weight:bold; text-align:left;') | ||
labelDiv:wikitext(label) | |||
local | local valueDiv = container:tag('div') | ||
css( | css(valueDiv, 'padding:0.2em 0.4em;') | ||
if isRawHtml then | if isRawHtml then | ||
valueDiv:node(mw.html.create('span'):wikitext(valueHtmlOrWikitext)) | |||
else | else | ||
valueDiv:wikitext(valueHtmlOrWikitext) | |||
end | end | ||
end | end | ||
local function addFullRow( | local function addFullRow(container, valueHtmlOrWikitext, cssText, isRawHtml) | ||
local | local fullDiv = container:tag('div') | ||
css(fullDiv, 'grid-column: 1 / -1; ' .. (cssText or '')) | |||
if isRawHtml then | if isRawHtml then | ||
fullDiv:wikitext(valueHtmlOrWikitext) | |||
else | else | ||
fullDiv:wikitext(valueHtmlOrWikitext) | |||
end | end | ||
end | end | ||
| Line 79: | Line 75: | ||
local standards_semantic = trim(args.standards_semantic) | local standards_semantic = trim(args.standards_semantic) | ||
local | local container = mw.html.create('div') | ||
container:addClass('infobox') | |||
container:addClass('infobox-crt-model') | |||
css( | css(container, 'float:right; clear:right; margin:0 0 1em 1em; width:22em; border:1px solid #a2a9b1; background:#f8f9fa; font-size:88%; line-height:1.5em; display:grid; grid-template-columns:auto 1fr; gap:3px; padding:3px;') | ||
-- Title row (no background color, centered, bold) | -- Title row (no background color, centered, bold) | ||
addFullRow( | addFullRow( | ||
container, | |||
(brand or '') .. ' ' .. (model_code or ''), | (brand or '') .. ' ' .. (model_code or ''), | ||
'text-align:center; font-size:125%; font-weight:bold; padding:0.5em;', | 'text-align:center; font-size:125%; font-weight:bold; padding:0.5em;', | ||
| Line 95: | Line 91: | ||
local file = image_main:gsub('^File:', '') | local file = image_main:gsub('^File:', '') | ||
addFullRow( | addFullRow( | ||
container, | |||
string.format('[[File:%s|frameless|300px]]', file), | string.format('[[File:%s|frameless|300px]]', file), | ||
'text-align:center; padding:0;', | 'text-align:center; padding:0;', | ||
| Line 106: | Line 102: | ||
local file = model_3d:gsub('^File:', '') | local file = model_3d:gsub('^File:', '') | ||
addFullRow( | addFullRow( | ||
container, | |||
string.format('[[File:%s]]', file), | string.format('[[File:%s]]', file), | ||
'text-align:center; padding:0;', | 'text-align:center; padding:0;', | ||
| Line 113: | Line 109: | ||
end | end | ||
addSectionRow( | addSectionRow(container, 'Overview') | ||
-- Brand row using #formredlink (must preprocess) | -- Brand row using #formredlink (must preprocess) | ||
| Line 122: | Line 118: | ||
) | ) | ||
local brandHtml = frame:preprocess(brandWikitext) | local brandHtml = frame:preprocess(brandWikitext) | ||
addRow( | addRow(container, 'Brand', brandHtml, true) | ||
end | end | ||
if model_code then | if model_code then | ||
addRow( | addRow(container, 'Model', model_code, false) | ||
else | else | ||
addRow( | addRow(container, 'Model', '', false) | ||
end | end | ||
if crt_type then | if crt_type then | ||
addRow( | addRow(container, 'Type', crt_type, false) | ||
end | end | ||
if screen_size_in then | if screen_size_in then | ||
addRow( | addRow(container, 'Screen size', screen_size_in .. '″', false) | ||
end | end | ||
if tvl then | if tvl then | ||
addRow( | addRow(container, 'TVL', tvl, false) | ||
end | end | ||
| Line 147: | Line 143: | ||
) | ) | ||
local chassisHtml = frame:preprocess(chassisWikitext) | local chassisHtml = frame:preprocess(chassisWikitext) | ||
addRow( | addRow(container, 'Chassis', chassisHtml, true) | ||
end | end | ||
-- ECID row: build as a normal external link wikitext; preprocess not required, but fine. | -- ECID row: build as a normal external link wikitext; preprocess not required, but fine. | ||
local ecidWikitext = string.format('[{{fullurl:%s|curid=%d}} EC%d]', pageName, pageId, pageId) | local ecidWikitext = string.format('[{{fullurl:%s|curid=%d}} EC%d]', pageName, pageId, pageId) | ||
addRow( | addRow(container, 'ECID', frame:preprocess(ecidWikitext), true) | ||
-- Dimensions section: show if we have height/width/depth OR weight | -- Dimensions section: show if we have height/width/depth OR weight | ||
if height or width or depth or weight then | if height or width or depth or weight then | ||
addSectionRow( | addSectionRow(container, 'Dimensions') | ||
if height or width or depth then | if height or width or depth then | ||
| Line 162: | Line 158: | ||
local w = width or '–' | local w = width or '–' | ||
local d = depth or '–' | local d = depth or '–' | ||
addRow( | addRow(container, 'H × W × D', string.format('%s × %s × %s', h, w, d), false) | ||
end | end | ||
| Line 168: | Line 164: | ||
if weight then | if weight then | ||
local weightWikitext = '{{#show: ' .. fullPageName .. ' |?Weight # lb }} / {{#show: ' .. fullPageName .. ' |?Weight # kg }}' | local weightWikitext = '{{#show: ' .. fullPageName .. ' |?Weight # lb }} / {{#show: ' .. fullPageName .. ' |?Weight # kg }}' | ||
addRow( | addRow(container, 'Weight', frame:preprocess(weightWikitext), true) | ||
end | end | ||
end | end | ||
| Line 188: | Line 184: | ||
-- Only display Inputs section if the query returned content (not just whitespace) | -- Only display Inputs section if the query returned content (not just whitespace) | ||
if askHtml and trim(askHtml) then | if askHtml and trim(askHtml) then | ||
addSectionRow( | addSectionRow(container, 'Inputs') | ||
addFullRow( | addFullRow(container, askHtml, 'padding:0.2em 0.4em;', true) | ||
end | end | ||
-- Only display Standards section if standards_semantic has content | -- Only display Standards section if standards_semantic has content | ||
if standards_semantic then | if standards_semantic then | ||
addSectionRow( | addSectionRow(container, 'Standards') | ||
addFullRow( | addFullRow(container, standards_semantic, 'padding:0.2em 0.4em;', false) | ||
end | end | ||
-- Documents section | -- Documents section | ||
addSectionRow( | addSectionRow(container, 'Documents') | ||
-- Build the upload link | -- Build the upload link | ||
| Line 222: | Line 218: | ||
local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0 | local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0 | ||
-- Create the content | -- Create the content div | ||
local | local docsDiv = container:tag('div') | ||
css(docsDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em;') | |||
css( | |||
if hasDocuments then | if hasDocuments then | ||
| Line 246: | Line 241: | ||
-- Parse the HTML table - extract data from <td> tags | -- Parse the HTML table - extract data from <td> tags | ||
if docsResult then | if docsResult then | ||
-- Match each table row | -- Match each table row | ||
| Line 274: | Line 268: | ||
end | end | ||
docsDiv:node(ul) | |||
-- Add upload link as a button | -- Add upload link as a button | ||
local uploadDiv = mw.html.create('div') | local uploadDiv = mw.html.create('div') | ||
uploadDiv:css('margin-top', '0.5em'):css('text-align', 'center') | uploadDiv:css('margin-top', '0.5em'):css('text-align', 'center') | ||
uploadDiv:wikitext('[' .. tostring(uploadUrl) .. ' <span style="display:inline-block;padding:0.5rem 1rem;background-color:#eff6ff;color:#1d4ed8;border:1px solid #bfdbfe;border-radius:0.375rem;font-size:0.875rem;font-weight:500;text-decoration:none;">Upload a document</span>]') | uploadDiv:wikitext('[' .. tostring(uploadUrl) .. ' <span style="display:inline-block;padding:0.5rem 1rem;background-color:#eff6ff;color:#1d4ed8;border:1px solid #bfdbfe;border-radius:0.375rem;font-size:0.875rem;font-weight:500;text-decoration:none;">Upload a document</span>]') | ||
docsDiv:node(uploadDiv) | |||
else | else | ||
-- Just show the upload link as a button | -- Just show the upload link as a button | ||
local uploadDiv = mw.html.create('div') | local uploadDiv = mw.html.create('div') | ||
uploadDiv:css('text-align', 'center') | uploadDiv:css('text-align', 'center') | ||
uploadDiv:wikitext('[' .. tostring(uploadUrl) .. ' <span style="display:inline-block;padding:0.5rem 1rem;background-color:#eff6ff;color:#1d4ed8;border:1px solid #bfdbfe;border-radius:0.375rem;font-size:0.875rem;font-weight:500;text-decoration:none;">Upload a document</span>]') | uploadDiv:wikitext('[' .. tostring(uploadUrl) .. ' <span style="display:inline-block;padding:0.5rem 1rem;background-color:#eff6ff;color:#1d4ed8;border:1px solid #bfdbfe;border-radius:0.375rem;font-size:0.875rem;font-weight:500;text-decoration:none;">Upload a document</span>]') | ||
docsDiv:node(uploadDiv) | |||
end | end | ||
| Line 341: | Line 335: | ||
-- Display links section if there are any links | -- Display links section if there are any links | ||
if hasLinks then | if hasLinks then | ||
addSectionRow( | addSectionRow(container, 'Archival Links') | ||
-- Add links in order: Database, Manufacturer, Retailer | -- Add links in order: Database, Manufacturer, Retailer | ||
| Line 352: | Line 346: | ||
table.insert(linksHtml, '[' .. link.url .. ' ' .. link.source .. ']') | table.insert(linksHtml, '[' .. link.url .. ' ' .. link.source .. ']') | ||
end | end | ||
addRow( | addRow(container, linkType, table.concat(linksHtml, '<br>'), true) | ||
end | end | ||
end | end | ||
| Line 358: | Line 352: | ||
-- Contribute section | -- Contribute section | ||
addSectionRow( | addSectionRow(container, 'Contribute') | ||
-- Build the edit link URL | -- Build the edit link URL | ||
| Line 369: | Line 363: | ||
) | ) | ||
-- Create the edit button | -- Create the edit button div | ||
local | local editDiv = container:tag('div') | ||
css(editDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em; text-align:center;') | |||
css( | |||
-- Add edit button with primary action styling | -- Add edit button with primary action styling | ||
editDiv:wikitext('[' .. tostring(editUrl) .. ' <span style="display:inline-block;padding:0.5rem 1rem;background-color:#2563eb;color:#ffffff;border:1px solid #2563eb;border-radius:0.375rem;font-size:0.875rem;font-weight:500;text-decoration:none;cursor:pointer;">Edit this data</span>]') | |||
return tostring( | return tostring(container) | ||
end | end | ||
return p | return p | ||