Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Events: Difference between revisions

From Deepspace Lore
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..."
 
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
-- Config: full LI roster, update here if new characters are added
local ALL_CHARACTERS = {
    "Xavier",
    "Zayne",
    "Rafayel",
    "Sylus",
    "Caleb"
}
-- Split a string on a delimiter, trim whitespace from each part
local function splitAndTrim( str, sep )
    local result = {}
    for part in str:gmatch( "[^" .. sep .. "]+" ) do
        local trimmed = part:match( "^%s*(.-)%s*$" )
        if trimmed ~= "" then
            table.insert( result, trimmed )
        end
    end
    return result
end
-- Resolve characters field: expands "All" to full roster
local function resolveCharacters( raw )
    if not raw or raw == "" then
        return {}
    end
    local trimmed = raw:match( "^%s*(.-)%s*$" )
    if trimmed == "All" then
        return ALL_CHARACTERS
    end
    return splitAndTrim( raw, ";" )
end


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


    -- Split characters string on ; into a table
     local characters = resolveCharacters( args.characters )
     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({
     bucket("events").put({
Line 17: Line 44:
         label      = args.label      or "",
         label      = args.label      or "",
         type        = args.type        or "",
         type        = args.type        or "",
        subtype    = args.subtype    or "",
         image      = args.image      or "",
         image      = args.image      or "",
         start      = args.start      or "",
         start      = args.start      or "",
Line 27: Line 55:
end
end


-- Render an events table, optionally filtered by type or character
-- Render events list as a wikitable
function p.list(frame)
function p.list( frame )
     local args = frame.args
     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")
     local results = bucket("events")
         .select("name", "label", "type", "image", "start", "end", "description", "characters")
         .select("name", "label", "type", "subtype", "start", "end", "description")
         .orderBy("start", "desc")
         .orderBy("start", "desc")
 
         .run()
    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
     if not results or #results == 0 then
Line 52: Line 68:
     end
     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 = {}
     local out = {}
     table.insert(out, '{| class="wikitable sortable"')
     table.insert( out, '{| class="wikitable sortable"' )
     table.insert(out, '! Name !! Type !! Image !! Start !! End !! Description')
     table.insert( out, '! Name !! Type !! Subtype !! Start !! End !! Description' )


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


         local chars = ""
         if name ~= "" then
        if row.characters and #row.characters > 0 then
            if label ~= name then
             chars = table.concat(row.characters, ", ")
                link = "[[" .. name .. "|" .. label .. "]]"
             else
                link = "[[" .. name .. "]]"
            end
        else
            link = label
         end
         end


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


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


return p
return p

Revision as of 01:22, 25 April 2026

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

local p = {}

-- Config: full LI roster, update here if new characters are added
local ALL_CHARACTERS = {
    "Xavier",
    "Zayne",
    "Rafayel",
    "Sylus",
    "Caleb"
}

-- Split a string on a delimiter, trim whitespace from each part
local function splitAndTrim( str, sep )
    local result = {}
    for part in str:gmatch( "[^" .. sep .. "]+" ) do
        local trimmed = part:match( "^%s*(.-)%s*$" )
        if trimmed ~= "" then
            table.insert( result, trimmed )
        end
    end
    return result
end

-- Resolve characters field: expands "All" to full roster
local function resolveCharacters( raw )
    if not raw or raw == "" then
        return {}
    end
    local trimmed = raw:match( "^%s*(.-)%s*$" )
    if trimmed == "All" then
        return ALL_CHARACTERS
    end
    return splitAndTrim( raw, ";" )
end

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

    local characters = resolveCharacters( args.characters )

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

    return ""
end

-- Render events list as a wikitable
function p.list( frame )
    local args = frame.args

    local results = bucket("events")
        .select("name", "label", "type", "subtype", "start", "end", "description")
        .orderBy("start", "desc")
        .run()

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

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

    for _, row in ipairs( results ) do
        local label = ( row.label and row.label ~= "" ) and row.label or row.name
        local name  = ( row.name  and row.name  ~= "" ) and row.name  or ""
        local link

        if name ~= "" then
            if label ~= name then
                link = "[[" .. name .. "|" .. label .. "]]"
            else
                link = "[[" .. name .. "]]"
            end
        else
            link = label
        end

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

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

return p