Jump to content

Module:Alert list: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
trying something
loading tables
Line 1: Line 1:
local p = {}
local p = {}
local standardIcons = require('Module:Standard icons')
local standardIcons = require('Module:Standard icons')
local iconTable = standardIcons.getIconTable()
local labelTable = standardIcons.getLabelTable()


local function renderNotification(args, index)
local function renderNotification(args, index)
local typeKey = args['type' .. index]
local typeKey = args['type' .. index]
local icon = args['icon' .. index] or (typeKey and standardIcons.iconTable[typeKey]) or nil
local icon = args['icon' .. index] or iconTable[typeKey]
local label = args['label' .. index] or (typeKey and standardIcons.labelTable[typeKey]) or nil
local label = args['label' .. index] or labelTable[typeKey]
local msg = args['msg' .. index]
local msg = args['msg' .. index]
local action = args['action' .. index]
local action = args['action' .. index]

Revision as of 03:13, 29 April 2023

local p = {}
local standardIcons = require('Module:Standard icons')
local iconTable = standardIcons.getIconTable()
local labelTable = standardIcons.getLabelTable()

local function renderNotification(args, index)
    local typeKey = args['type' .. index]
    local icon = args['icon' .. index] or iconTable[typeKey]
    local label = args['label' .. index] or labelTable[typeKey]
    local msg = args['msg' .. index]
    local action = args['action' .. index]
    local time = args['time' .. index]

    if not icon or not label then
        return ''
    end

    local notification = {
        '* [[File:' .. icon .. "|25px|link=]] <span class='notification-list-label'>" .. label .. "</span>",
    }

    if msg and msg ~= '' then
        table.insert(notification, '*: ' .. msg)
    end

    if action and action ~= '' then
        table.insert(notification, '*: ' .. action)
    end
    
    if time and time ~= '' then
        table.insert(notification, '*: <small>' .. time .. '</small>')
    end

    return table.concat(notification, '\n')
end

function p.main(frame)
    local args = frame:getParent().args
    local output = {}

    for i = 1, math.huge do
        local notification = renderNotification(args, i)

        if notification == '' then
            break
        end

        table.insert(output, notification)
    end

    return '<div class="notification-list">\n' .. table.concat(output, '\n') .. '\n</div>'
end

return p