Module:KnownRecordings: Difference between revisions

From Weezerpedia
m (Admin moved page Module:SongRecordingTable to Module:KnownRecordings without leaving a redirect)
No edit summary
Tag: Reverted
Line 14: Line 14:
     local args = frame:getParent().args
     local args = frame:getParent().args
     local rows = {}
     local rows = {}
    local index = 1  -- Start with the first row


     -- Dynamically generate rows until no more data is found
     -- Iterate over the rows, each containing a set of data for a single row in the table
     while args["title" .. index] or args["performers" .. index] do
     local data = args[1] or ""
         local performers = args["performers" .. index] or ""
    local rowData = {}
         local title = args["title" .. index] or ""
   
         local filename = args["filename" .. index] or ""
    -- Split the input data by pipe separator to get each row's data
         local date = args["date" .. index] or ""
    for entry in string.gmatch(data, "([^|]+)") do
         local location = args["location" .. index] or ""
        table.insert(rowData, entry)
         local length = args["length" .. index] or ""
    end
         local appearedOn = args["appearedOn" .. index] or ""
   
         local notes = args["notes" .. index] or ""
    -- Determine how many rows there are based on the number of columns (9 in this case)
         local status = args["status" .. index] or "unknown"
    local numRows = math.floor(#rowData / 9)
   
    for i = 0, numRows - 1 do
        -- Each row will have 9 elements (artist, title, filename, date, location, length, album, notes, status)
        local startIdx = i * 9 + 1
        local row = {}
        for j = 0, 8 do
            table.insert(row, rowData[startIdx + j])
        end
       
        -- Extract row fields
         local artist = row[1]
         local title = row[2]
         local filename = row[3]
         local date = row[4]
         local location = row[5]
         local length = row[6]
         local album = row[7]
         local notes = row[8]
         local status = row[9] or "unknown"
       
        -- Determine the background color based on the status
         local color = statusColors[status:lower()] or statusColors["unknown"]
         local color = statusColors[status:lower()] or statusColors["unknown"]
          
          
        -- Wrap filename with <samp> for monospace display
         -- Create table row with background color and no-wrap for filename
        local filenameFormatted = string.format('<samp>%s</samp>', filename)
         local rowHTML = string.format(
       
             '<tr%s><td>%s</td><td>%s</td><td><samp>%s</samp></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
         -- Create table row with background color and no-wrap for the filename column
         local row = string.format(
             '<tr%s><td>%s</td><td>%s</td><td style="white-space: nowrap;">%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
             color and (' style="background-color:' .. color .. ';"') or "",
             color and (' style="background-color:' .. color .. ';"') or "",
             performers, title, filenameFormatted, date, location, length, appearedOn, notes
             artist, title, filename, date, location, length, album, notes
         )
         )
         table.insert(rows, row)
         table.insert(rows, rowHTML)
       
        index = index + 1  -- Move to the next row
     end
     end


     -- Create table header
     -- Combine all rows into a table
     local header = [[
     local tableHTML = string.format('<table class="wikitable" style="margin:0.5em; font-size:.8em; border:1px solid #aaa; width:100%%;">%s</table>', table.concat(rows))
        <tr>
      
            <th>Performer(s)</th>
     -- Use the correct MediaWiki caption markup without extra single quotes
            <th>Title</th>
     local captionHTML = '|+style="caption-side:top; text-align:left;"|<small><i>[[Weezerpedia:Known recordings|about this table]]</i></small>'
            <th>Filename</th>
            <th>Date of recording</th>
            <th>Recording location</th>
            <th>Length</th>
            <th>Appeared on</th>
            <th>Notes</th>
        </tr>
     ]]
 
     -- Add caption below the table using MediaWiki-compatible syntax
     local caption = mw.text.tag(
        'caption',
        { style = 'caption-side: bottom; text-align: right;' },
        mw.text.tag(
            'small',
            nil,
            mw.text.tag(
                'i',
                nil,
                '[[' .. 'Weezerpedia:Known recordings|about this table' .. ']]'
            )
        )
    )


     -- Combine header, caption, and rows into a styled table
     -- Return the table with the caption
     return string.format(
     return tableHTML .. captionHTML
        '<table class="wikitable" style="margin:0.5em; font-size:.8em;">%s%s%s</table>',
        caption,
        header,
        table.concat(rows)
    )
end
end


return p
return p

Revision as of 12:08, 27 November 2024

Documentation for this module may be created at Module:KnownRecordings/doc

local p = {}

-- Define the color map based on the status
local statusColors = {
    released = "#aaffaa",
    unreleased = "#ffaaaa",
    ["partially released"] = "#ffffaa",
    duplicate = "#cccccc",
    unknown = nil
}

-- Main function to render the table
function p.renderTable(frame)
    local args = frame:getParent().args
    local rows = {}

    -- Iterate over the rows, each containing a set of data for a single row in the table
    local data = args[1] or ""
    local rowData = {}
    
    -- Split the input data by pipe separator to get each row's data
    for entry in string.gmatch(data, "([^|]+)") do
        table.insert(rowData, entry)
    end
    
    -- Determine how many rows there are based on the number of columns (9 in this case)
    local numRows = math.floor(#rowData / 9)
    
    for i = 0, numRows - 1 do
        -- Each row will have 9 elements (artist, title, filename, date, location, length, album, notes, status)
        local startIdx = i * 9 + 1
        local row = {}
        for j = 0, 8 do
            table.insert(row, rowData[startIdx + j])
        end
        
        -- Extract row fields
        local artist = row[1]
        local title = row[2]
        local filename = row[3]
        local date = row[4]
        local location = row[5]
        local length = row[6]
        local album = row[7]
        local notes = row[8]
        local status = row[9] or "unknown"
        
        -- Determine the background color based on the status
        local color = statusColors[status:lower()] or statusColors["unknown"]
        
        -- Create table row with background color and no-wrap for filename
        local rowHTML = string.format(
            '<tr%s><td>%s</td><td>%s</td><td><samp>%s</samp></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
            color and (' style="background-color:' .. color .. ';"') or "",
            artist, title, filename, date, location, length, album, notes
        )
        table.insert(rows, rowHTML)
    end

    -- Combine all rows into a table
    local tableHTML = string.format('<table class="wikitable" style="margin:0.5em; font-size:.8em; border:1px solid #aaa; width:100%%;">%s</table>', table.concat(rows))
    
    -- Use the correct MediaWiki caption markup without extra single quotes
    local captionHTML = '|+style="caption-side:top; text-align:left;"|<small><i>[[Weezerpedia:Known recordings|about this table]]</i></small>'

    -- Return the table with the caption
    return tableHTML .. captionHTML
end

return p