Module:CRTModel: Difference between revisions
No edit summary |
No edit summary |
||
| Line 196: | Line 196: | ||
-- Documents section | -- Documents section | ||
addSectionRow(tbl, 'Documents') | addSectionRow(tbl, 'Documents') | ||
-- Build the upload link | -- Build the upload link | ||
| Line 219: | Line 208: | ||
) | ) | ||
-- | -- Query for documents and build the list in Lua | ||
local hasDocuments = | local documentsQueryWikitext = | ||
'{{#ask:\n' .. | |||
' [[Category:Documents]]\n' .. | |||
' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | |||
' |?Has document type\n' .. | |||
' |?Has document URL\n' .. | |||
' |format=count\n' .. | |||
'}}' | |||
local documentCount = frame:preprocess(documentsQueryWikitext) | |||
local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0 | |||
if hasDocuments then | if hasDocuments then | ||
-- | -- Get the actual document data using #show for each document | ||
-- First, get the list of document page names | |||
local docPagesQueryWikitext = | |||
-- | |||
local | |||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
' [[Category:Documents]]\n' .. | ' [[Category:Documents]]\n' .. | ||
' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | ' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | ||
' | | ' |limit=100\n' .. | ||
'}}' | '}}' | ||
local docPagesResult = frame:preprocess(docPagesQueryWikitext) | |||
-- Build links manually - use #show to get properties for each document | |||
local docListHtml = '<ul style="margin:0; padding-left:1.5em;">' | |||
-- | -- Parse document page names from the result | ||
-- The result format is typically "PageName1, PageName2, ..." or line-separated | |||
for docPage in docPagesResult:gmatch('[^\n,]+') do | |||
' | docPage = trim(docPage) | ||
if docPage and docPage ~= '' then | |||
-- Get document type and URL for this page | |||
local docTypeWikitext = '{{#show:' .. docPage .. '|?Has document type}}' | |||
local docUrlWikitext = '{{#show:' .. docPage .. '|?Has document URL}}' | |||
local docType = trim(frame:preprocess(docTypeWikitext)) | |||
local docUrl = trim(frame:preprocess(docUrlWikitext)) | |||
if docUrl and docUrl ~= '' then | |||
local linkText = docType or 'Document' | |||
docListHtml = docListHtml .. '<li>[' .. docUrl .. ' ' .. linkText .. ']</li>' | |||
end | |||
end | |||
end | |||
docListHtml = docListHtml .. '</ul>' | |||
-- | -- Add the documents list and upload link | ||
local | local combinedHtml = docListHtml .. '<div style="margin-top:0.5em; font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>' | ||
addFullRow(tbl, | addFullRow(tbl, combinedHtml, 'padding:0.2em 0.4em;', false) | ||
else | else | ||
-- Just show the upload link | -- Just show the upload link | ||
local | local uploadLinkWikitext = '<div style="font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>' | ||
addFullRow(tbl, | addFullRow(tbl, uploadLinkWikitext, 'padding:0.2em 0.4em;', false) | ||
end | end | ||