mNo edit summary |
mNo edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 61: | Line 61: | ||
team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(result.p2, game, size)):node('[[' .. result.p2 .. '|<div style="font-size: 0.8rem;">' .. string.gsub(result.p2, game .. '/', '') .. '</div>]]')) | team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(result.p2, game, size)):node('[[' .. result.p2 .. '|<div style="font-size: 0.8rem;">' .. string.gsub(result.p2, game .. '/', '') .. '</div>]]')) | ||
else | else | ||
team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(nil, game, size)):node('<div style="font-size: 0.8rem;">TBD</div>')) | |||
end | end | ||
Latest revision as of 05:18, 29 October 2023
Documentation for this module may be created at Module:Infobox/Widget/Upcoming matches/doc
local cargo = mw.ext.cargo
local Functions = require('Module:Functions')
local getTeamLogo = Functions.getTeamLogo
local prizeToString = Functions.prizeToString
local timeUntil = Functions.timeUntil
local stringifyDate = Functions.stringifyDate
local p = {}
function p.get(tournament, team)
local currentDate = os.date('%Y-%m-%d')
-- Get live matches
local tables = 'AllMatches'
local fields = '_pageName, p1, p2, date, bestof'
local playerPage = mw.title.getCurrentTitle().text
team = team or ''
local cargoArgs = {
where = '_pageName LIKE "' .. tournament .. '/%" AND (date is NOT NULL AND date <= "' .. currentDate .. '") AND (winner IS NULL OR winner = 0) AND ((p1 = "' .. team .. '" OR p2 = "' .. team .. '") OR (p1 = "' .. playerPage .. '" OR p2 = "' .. playerPage .. '"))',
orderBy = 'date'
}
local results = cargo.query(tables, fields, cargoArgs)
local container = mw.html.create('table'):addClass('w-100 tc')
if #results > 0 then
p.matchHtml(container, results, 'true')
end
-- Check for upcoming matches
cargoArgs.where = '_pageName LIKE "' .. tournament .. '/%" AND (date is NOT NULL AND date > "' .. currentDate .. '") AND (winner IS NULL OR winner = 0) AND ((p1 = "' .. team .. '" OR p2 = "' .. team .. '") OR (p1 = "' .. playerPage .. '" OR p2 = "' .. playerPage .. '"))'
results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
p.matchHtml(container, results)
end
return container
end
function p.matchHtml(container, results, live)
local game = mw.text.split(results[1]._pageName, '/')[1]
for i = 1, #results do
local result = results[i]
local row = mw.html.create('tr')
local time = mw.html.create('td'):attr('style', 'padding: 4px; font-size: 0.8rem;')
local team1 = mw.html.create('td'):attr('style', 'padding: 4px;')
local vs = mw.html.create('td'):attr('style', 'padding: 4px;'):node(mw.html.create('abbr'):attr('title', 'Best-of-' .. result.bestof):wikitext('Bo' .. result.bestof))
local team2 = mw.html.create('td'):attr('style', 'padding: 4px;')
if live then time:wikitext('LIVE') else time:wikitext(timeUntil(result.date)) end
local styleLeft = 'display: flex; column-gap: 0.2rem;justify-content: end; align-items: center;'
local styleRight = 'display: flex; column-gap: 0.2rem;justify-content: start; align-items: center;'
local size = '20x20px'
if result.p1 then
team1:node(mw.html.create('div'):attr('style', styleLeft):node('[[' .. result.p1 .. '|<div style="font-size: 0.8rem; text-align: right;">' .. string.gsub(result.p1, game .. '/', '') .. '</div>]]'):node(getTeamLogo(result.p1, game, size)))
else
team1:node(mw.html.create('div'):attr('style', styleLeft):node('<div style="font-size: 0.8rem; text-align: right;">TBD</div>'):node(getTeamLogo(nil, game, size)))
end
if result.p2 then
team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(result.p2, game, size)):node('[[' .. result.p2 .. '|<div style="font-size: 0.8rem;">' .. string.gsub(result.p2, game .. '/', '') .. '</div>]]'))
else
team2:node(mw.html.create('div'):attr('style', styleRight):node(getTeamLogo(nil, game, size)):node('<div style="font-size: 0.8rem;">TBD</div>'))
end
row:node(time):node(team1):node(vs):node(team2)
container:node(row)
end
end
return p