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 11:43, 30 January 2026 by Esportsamaze (talk | contribs) (Created page with "local p = {} local cargo = mw.ext.cargo local html = mw.html -- ============================================================ -- HELPER: Sanitize -- ============================================================ local function clean(s) if not s then return nil end return s:gsub("[\r\n]", ""):gsub("^%s*(.-)%s*$", "%1") end -- ============================================================ -- 1. PLAYERS LIST -- ==========================================================...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}
local cargo = mw.ext.cargo
local html = mw.html

-- ============================================================
-- HELPER: Sanitize
-- ============================================================
local function clean(s)
    if not s then return nil end
    return s:gsub("[\r\n]", ""):gsub("^%s*(.-)%s*$", "%1")
end

-- ============================================================
-- 1. PLAYERS LIST
-- ============================================================
function p.players(frame)
    local args = frame.args
    local offset = tonumber(args.offset) or 0
    local limit = 50
    
    -- Query the existing 'Players' table
    local results = cargo.query(
        "Players",
        "_pageName, id, real_name, image, current_team, role, nationality",
        {
            orderBy = "id ASC",
            limit = limit,
            offset = offset
        }
    )
    
    local container = html.create('div'):addClass('db-list-container')
    
    if not results or #results == 0 then
        return '<div style="padding:40px; text-align:center; color:#64748b;">No players found.</div>'
    end
    
    for _, row in ipairs(results) do
        local div = container:tag('div'):addClass('db-row player-row')
        
        -- 1. Image
        local imgDiv = div:tag('div'):addClass('db-img')
        if row.image and row.image ~= "" then
            imgDiv:wikitext('[[File:' .. row.image .. '|50px|link=' .. row._pageName .. ']]')
        else
            imgDiv:wikitext('[[File:Player_Placeholder.png|50px|link=' .. row._pageName .. ']]')
        end
        
        -- 2. Identity (ID + Real Name)
        local idDiv = div:tag('div'):addClass('db-info')
        idDiv:tag('div'):addClass('db-title'):wikitext('[[' .. row._pageName .. '|' .. row.id .. ']]')
        idDiv:tag('div'):addClass('db-subtitle'):wikitext(row.real_name or "")
        
        -- 3. Team (Right Side)
        local teamDiv = div:tag('div'):addClass('db-meta')
        if row.current_team and row.current_team ~= "" then
            -- Check if team logo exists logic could go here, but keeping it simple for speed
            teamDiv:wikitext('[[File:' .. row.current_team .. '.png|25px|link=' .. row.current_team .. ']] [[' .. row.current_team .. ']]')
        else
            teamDiv:css('opacity','0.5'):wikitext("Free Agent")
        end
        
        -- 4. Role Pill
        local roleDiv = div:tag('div'):addClass('db-status')
        if row.role then
            local rClass = "role-def"
            local r = row.role:lower()
            if r:find("igl") then rClass = "role-igl"
            elseif r:find("fragger") then rClass = "role-frag"
            elseif r:find("sniper") then rClass = "role-snip"
            end
            roleDiv:tag('span'):addClass('role-badge ' .. rClass):wikitext(row.role)
        end
    end
    
    -- Pagination Controls
    local nav = container:tag('div'):addClass('pagination-controls')
    if offset > 0 then
        nav:tag('span'):addClass('page-btn'):wikitext('[' .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().text, {offset=math.max(0, offset-limit)})) .. ' « Previous]')
    end
    if #results == limit then
        nav:tag('span'):addClass('page-btn'):wikitext('[' .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().text, {offset=offset+limit})) .. ' Next »]')
    end
    
    return tostring(container)
end

-- ============================================================
-- 2. TEAMS LIST
-- ============================================================
function p.teams(frame)
    local args = frame.args
    local offset = tonumber(args.offset) or 0
    local limit = 50
    
    -- Query the 'Teams' table
    local results = cargo.query(
        "Teams",
        "_pageName, name, image, image_dark, status, country",
        {
            orderBy = "name ASC",
            limit = limit,
            offset = offset
        }
    )
    
    local container = html.create('div'):addClass('db-list-container')
    
    if not results or #results == 0 then
        return '<div style="padding:40px; text-align:center; color:var(--text-muted);">No teams found in database.<br><small>Edit and Save a Team page to register it.</small></div>'
    end
    
    for _, row in ipairs(results) do
        local div = container:tag('div'):addClass('db-row team-row')
        
        -- 1. Logo
        local imgFile = row.image
        if not imgFile or imgFile == "" then imgFile = "Shield_team.png" end
        
        div:tag('div'):addClass('db-img'):wikitext('[[File:' .. imgFile .. '|50px|link=' .. row._pageName .. ']]')
        
        -- 2. Name + Country
        local info = div:tag('div'):addClass('db-info')
        info:tag('div'):addClass('db-title'):wikitext('[[' .. row._pageName .. '|' .. row.name .. ']]')
        
        if row.country then
            local flag = "Flag_" .. row.country .. ".png"
            info:tag('div'):addClass('db-subtitle'):wikitext('[[File:' .. flag .. '|15px|link=]] ' .. row.country)
        end
        
        -- 3. Status Badge
        local statusDiv = div:tag('div'):addClass('db-status')
        local sClass = "status-active"
        local sText = row.status or "Active"
        if sText:lower() ~= "active" then sClass = "status-inactive" end
        
        statusDiv:tag('span'):addClass('status-badge ' .. sClass):wikitext(sText)
    end
    
    -- Pagination Controls
    local nav = container:tag('div'):addClass('pagination-controls')
    if offset > 0 then
        nav:tag('span'):addClass('page-btn'):wikitext('[' .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().text, {offset=math.max(0, offset-limit)})) .. ' « Previous]')
    end
    if #results == limit then
        nav:tag('span'):addClass('page-btn'):wikitext('[' .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().text, {offset=offset+limit})) .. ' Next »]')
    end
    
    return tostring(container)
end

return p