Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 01:05, 25 April 2026 by WinterLampost (talk | contribs) (Created page with "local p = {} -- Store event data into Bucket, called via Template:EventStore function p.store(frame) local args = frame.args -- Split characters string on ; into a table local characters = {} if args.characters and args.characters ~= "" then for c in args.characters:gmatch("[^;]+") do table.insert(characters, c:match("^%s*(.-)%s*$")) -- trim whitespace end end bucket("events").put({ name = args.name...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

-- Store event data into Bucket, called via Template:EventStore
function p.store(frame)
    local args = frame.args

    -- Split characters string on ; into a table
    local characters = {}
    if args.characters and args.characters ~= "" then
        for c in args.characters:gmatch("[^;]+") do
            table.insert(characters, c:match("^%s*(.-)%s*$")) -- trim whitespace
        end
    end

    bucket("events").put({
        name        = args.name        or "",
        label       = args.label       or "",
        type        = args.type        or "",
        image       = args.image       or "",
        start       = args.start       or "",
        ["end"]     = args["end"]      or "",
        characters  = characters,
        description = args.description or ""
    })

    return ""
end

-- Render an events table, optionally filtered by type or character
function p.list(frame)
    local args = frame.args
    local filter_type      = args.type      or nil
    local filter_character = args.character or nil
    local filter_year      = args.year      or nil

    local q = bucket("events")
        .select("name", "label", "type", "image", "start", "end", "description", "characters")
        .orderBy("start", "desc")

    if filter_type then
        q = q.where({"type", filter_type})
    end

    if filter_character then
        q = q.where({"characters", filter_character})
    end

    local results = q.run()

    if not results or #results == 0 then
        return "No events found."
    end

    -- Optional year filter (post-query, since start is TEXT)
    if filter_year then
        local filtered = {}
        for _, row in ipairs(results) do
            if row.start:sub(1, 4) == filter_year then
                table.insert(filtered, row)
            end
        end
        results = filtered
    end

    -- Build wikitable
    local out = {}
    table.insert(out, '{| class="wikitable sortable"')
    table.insert(out, '! Name !! Type !! Image !! Start !! End !! Description')

    for _, row in ipairs(results) do
        local image_cell = ""
        if row.image and row.image ~= "" then
            image_cell = "[[File:" .. row.image .. "|80px]]"
        end

        local chars = ""
        if row.characters and #row.characters > 0 then
            chars = table.concat(row.characters, ", ")
        end

        local label = row.label or row.name or ""

        table.insert(out, "|-")
        table.insert(out, string.format(
            "| %s || %s || %s || %s || %s || %s",
            label,
            row.type,
            image_cell,
            row.start,
            row["end"],
            row.description or ""
        ))
    end

    table.insert(out, "|}")
    return table.concat(out, "\n")
end

return p