Module:Lists: Difference between revisions
From eSportsAmaze
More actions
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 -- ==========================================================..." |
Esportsamaze (talk | contribs) No edit summary |
||
| Line 12: | Line 12: | ||
-- ============================================================ | -- ============================================================ | ||
-- 1. PLAYERS LIST | -- 1. PLAYERS LIST (Updated with ALL Roles) | ||
-- ============================================================ | -- ============================================================ | ||
function p.players(frame) | function p.players(frame) | ||
| Line 19: | Line 19: | ||
local limit = 50 | local limit = 50 | ||
local results = cargo.query( | local results = cargo.query( | ||
"Players", | "Players", | ||
| Line 47: | Line 46: | ||
end | end | ||
-- 2. Identity | -- 2. Identity | ||
local idDiv = div:tag('div'):addClass('db-info') | local idDiv = div:tag('div'):addClass('db-info') | ||
idDiv:tag('div'):addClass('db-title'):wikitext('[[' .. row._pageName .. '|' .. row.id .. ']]') | idDiv:tag('div'):addClass('db-title'):wikitext('[[' .. row._pageName .. '|' .. row.id .. ']]') | ||
idDiv:tag('div'):addClass('db-subtitle'):wikitext(row.real_name or "") | idDiv:tag('div'):addClass('db-subtitle'):wikitext(row.real_name or "") | ||
-- 3. Team | -- 3. Team | ||
local teamDiv = div:tag('div'):addClass('db-meta') | local teamDiv = div:tag('div'):addClass('db-meta') | ||
if row.current_team and row.current_team ~= "" then | if row.current_team and row.current_team ~= "" then | ||
teamDiv:wikitext('[[File:' .. row.current_team .. '.png|25px|link=' .. row.current_team .. ']] [[' .. row.current_team .. ']]') | teamDiv:wikitext('[[File:' .. row.current_team .. '.png|25px|link=' .. row.current_team .. ']] [[' .. row.current_team .. ']]') | ||
else | else | ||
| Line 61: | Line 59: | ||
end | end | ||
-- 4. Role Pill | -- 4. Role Pill (UPDATED LOGIC) | ||
local roleDiv = div:tag('div'):addClass('db-status') | local roleDiv = div:tag('div'):addClass('db-status') | ||
if row.role then | if row.role then | ||
local rClass = "role-def" | local rClass = "role-def" | ||
local r = row.role:lower() | local r = row.role:lower() | ||
-- Priority Order: Specific roles first | |||
if r:find("igl") then rClass = "role-igl" | if r:find("igl") then rClass = "role-igl" | ||
elseif r:find(" | elseif r:find("entry") then rClass = "role-entry" | ||
elseif r:find("assault") then rClass = "role-assault" | |||
elseif r:find("support") then rClass = "role-support" | |||
elseif r:find("medic") then rClass = "role-support" | |||
elseif r:find("scout") then rClass = "role-scout" | |||
elseif r:find("sniper") then rClass = "role-snip" | elseif r:find("sniper") then rClass = "role-snip" | ||
elseif r:find("coach") then rClass = "role-coach" | |||
elseif r:find("analyst") then rClass = "role-coach" | |||
elseif r:find("manager") then rClass = "role-manager" | |||
elseif r:find("fragger") then rClass = "role-assault" -- Fallback for generic fragger | |||
end | end | ||
roleDiv:tag('span'):addClass('role-badge ' .. rClass):wikitext(row.role) | roleDiv:tag('span'):addClass('role-badge ' .. rClass):wikitext(row.role) | ||
end | end | ||
end | end | ||
-- Pagination | -- Pagination | ||
local nav = container:tag('div'):addClass('pagination-controls') | local nav = container:tag('div'):addClass('pagination-controls') | ||
if offset > 0 then | if offset > 0 then | ||
| Line 94: | Line 103: | ||
local limit = 50 | local limit = 50 | ||
local results = cargo.query( | local results = cargo.query( | ||
"Teams", | "Teams", | ||
| Line 114: | Line 122: | ||
local div = container:tag('div'):addClass('db-row team-row') | local div = container:tag('div'):addClass('db-row team-row') | ||
local imgFile = row.image | local imgFile = row.image | ||
if not imgFile or imgFile == "" then imgFile = "Shield_team.png" end | if not imgFile or imgFile == "" then imgFile = "Shield_team.png" end | ||
| Line 120: | Line 127: | ||
div:tag('div'):addClass('db-img'):wikitext('[[File:' .. imgFile .. '|50px|link=' .. row._pageName .. ']]') | div:tag('div'):addClass('db-img'):wikitext('[[File:' .. imgFile .. '|50px|link=' .. row._pageName .. ']]') | ||
local info = div:tag('div'):addClass('db-info') | local info = div:tag('div'):addClass('db-info') | ||
info:tag('div'):addClass('db-title'):wikitext('[[' .. row._pageName .. '|' .. row.name .. ']]') | info:tag('div'):addClass('db-title'):wikitext('[[' .. row._pageName .. '|' .. row.name .. ']]') | ||
| Line 129: | Line 135: | ||
end | end | ||
local statusDiv = div:tag('div'):addClass('db-status') | local statusDiv = div:tag('div'):addClass('db-status') | ||
local sClass = "status-active" | local sClass = "status-active" | ||
local sText = row.status or "Active" | local sText = row.status or "Active" | ||
if sText:lower() ~= "active" then sClass = "status-inactive" end | if sText:lower() ~= "active" then sClass = "status-inactive" end | ||
statusDiv:tag('span'):addClass('status-badge ' .. sClass):wikitext(sText) | statusDiv:tag('span'):addClass('status-badge ' .. sClass):wikitext(sText) | ||
end | end | ||
local nav = container:tag('div'):addClass('pagination-controls') | local nav = container:tag('div'):addClass('pagination-controls') | ||
if offset > 0 then | if offset > 0 then | ||
Revision as of 11:51, 30 January 2026
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 (Updated with ALL Roles)
-- ============================================================
function p.players(frame)
local args = frame.args
local offset = tonumber(args.offset) or 0
local limit = 50
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
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
local teamDiv = div:tag('div'):addClass('db-meta')
if row.current_team and row.current_team ~= "" then
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 (UPDATED LOGIC)
local roleDiv = div:tag('div'):addClass('db-status')
if row.role then
local rClass = "role-def"
local r = row.role:lower()
-- Priority Order: Specific roles first
if r:find("igl") then rClass = "role-igl"
elseif r:find("entry") then rClass = "role-entry"
elseif r:find("assault") then rClass = "role-assault"
elseif r:find("support") then rClass = "role-support"
elseif r:find("medic") then rClass = "role-support"
elseif r:find("scout") then rClass = "role-scout"
elseif r:find("sniper") then rClass = "role-snip"
elseif r:find("coach") then rClass = "role-coach"
elseif r:find("analyst") then rClass = "role-coach"
elseif r:find("manager") then rClass = "role-manager"
elseif r:find("fragger") then rClass = "role-assault" -- Fallback for generic fragger
end
roleDiv:tag('span'):addClass('role-badge ' .. rClass):wikitext(row.role)
end
end
-- Pagination
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
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')
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 .. ']]')
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
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
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