Module:Calendar: Difference between revisions
From eSportsAmaze
More actions
Esportsamaze (talk | contribs) No edit summary |
Esportsamaze (talk | contribs) No edit summary |
||
| Line 3: | Line 3: | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame:getParent().args | |||
local tournament = args.tournament | |||
local game = args.game | |||
local stage = args.stage | |||
local exclude_stage = args.exclude_stage | |||
local whereParts = {} | |||
if tournament and tournament ~= "" then table.insert(whereParts, "tournament='" .. tournament:gsub("'", "\\'") .. "'") end | |||
if game and game ~= "" then table.insert(whereParts, "game='" .. game:gsub("'", "\\'") .. "'") end | |||
if stage and stage ~= "" then | |||
table.insert(whereParts, "stage='" .. stage:gsub("'", "\\'") .. "'") | |||
end | |||
if exclude_stage and exclude_stage ~= "" then | |||
table.insert(whereParts, "stage!='" .. exclude_stage:gsub("'", "\\'") .. "'") | |||
end | |||
local whereClause = table.concat(whereParts, " AND ") | |||
if whereClause == "" then whereClause = "1=1" end | |||
-- ADDED STREAM TO QUERY | |||
local results = cargo.query("Tournament_Schedule", "tournament, game, match_type, date, stage, stream, day_data", { where = whereClause, orderBy = "date ASC", limit = 500 }) | |||
if not results or #results == 0 then | |||
return "<div style='padding:20px; text-align:center; color:var(--text-muted); background:var(--bg-card); border-radius:8px; border:1px solid var(--border-light);'>No schedule data found. Add matches using the MatchDay template.</div>" | |||
end | |||
local scheduleByDate = {} | |||
for _, row in ipairs(results) do | |||
local d = row.date | |||
if not scheduleByDate[d] then scheduleByDate[d] = {} end | |||
table.insert(scheduleByDate[d], { | |||
tournament = row.tournament, game = row.game, match_type = row.match_type, stage = row.stage, stream = row.stream, | |||
data = mw.text.jsonDecode(row.day_data) | |||
}) | |||
end | |||
local jsonString = mw.text.jsonEncode(scheduleByDate) | |||
local root = mw.html.create('div'):addClass('esports-calendar-container') | |||
root:tag('div'):addClass('calendar-data'):css('display', 'none'):wikitext(jsonString) | |||
local calLeft = root:tag('div'):addClass('calendar-left') | |||
local header = calLeft:tag('div'):addClass('calendar-header') | |||
header:tag('div'):addClass('cal-prev'):wikitext('❮') | |||
header:tag('div'):addClass('cal-month-year'):wikitext('Loading...') | |||
header:tag('div'):addClass('cal-next'):wikitext('❯') | |||
local gridWrap = calLeft:tag('div'):addClass('calendar-grid-wrapper') | |||
gridWrap:tag('div'):addClass('calendar-grid-days'):wikitext('<div>Mon</div><div>Tue</div><div>Wed</div><div>Thu</div><div>Fri</div><div>Sat</div><div>Sun</div>') | |||
gridWrap:tag('div'):addClass('calendar-grid-dates') | |||
local calRight = root:tag('div'):addClass('calendar-right') | |||
calRight:tag('div'):addClass('cal-details-content') | |||
return tostring(root) | |||
end | end | ||
return p | return p | ||
Revision as of 02:41, 23 February 2026
Documentation for this module may be created at Module:Calendar/doc
local p = {}
local cargo = mw.ext.cargo
function p.main(frame)
local args = frame:getParent().args
local tournament = args.tournament
local game = args.game
local stage = args.stage
local exclude_stage = args.exclude_stage
local whereParts = {}
if tournament and tournament ~= "" then table.insert(whereParts, "tournament='" .. tournament:gsub("'", "\\'") .. "'") end
if game and game ~= "" then table.insert(whereParts, "game='" .. game:gsub("'", "\\'") .. "'") end
if stage and stage ~= "" then
table.insert(whereParts, "stage='" .. stage:gsub("'", "\\'") .. "'")
end
if exclude_stage and exclude_stage ~= "" then
table.insert(whereParts, "stage!='" .. exclude_stage:gsub("'", "\\'") .. "'")
end
local whereClause = table.concat(whereParts, " AND ")
if whereClause == "" then whereClause = "1=1" end
-- ADDED STREAM TO QUERY
local results = cargo.query("Tournament_Schedule", "tournament, game, match_type, date, stage, stream, day_data", { where = whereClause, orderBy = "date ASC", limit = 500 })
if not results or #results == 0 then
return "<div style='padding:20px; text-align:center; color:var(--text-muted); background:var(--bg-card); border-radius:8px; border:1px solid var(--border-light);'>No schedule data found. Add matches using the MatchDay template.</div>"
end
local scheduleByDate = {}
for _, row in ipairs(results) do
local d = row.date
if not scheduleByDate[d] then scheduleByDate[d] = {} end
table.insert(scheduleByDate[d], {
tournament = row.tournament, game = row.game, match_type = row.match_type, stage = row.stage, stream = row.stream,
data = mw.text.jsonDecode(row.day_data)
})
end
local jsonString = mw.text.jsonEncode(scheduleByDate)
local root = mw.html.create('div'):addClass('esports-calendar-container')
root:tag('div'):addClass('calendar-data'):css('display', 'none'):wikitext(jsonString)
local calLeft = root:tag('div'):addClass('calendar-left')
local header = calLeft:tag('div'):addClass('calendar-header')
header:tag('div'):addClass('cal-prev'):wikitext('❮')
header:tag('div'):addClass('cal-month-year'):wikitext('Loading...')
header:tag('div'):addClass('cal-next'):wikitext('❯')
local gridWrap = calLeft:tag('div'):addClass('calendar-grid-wrapper')
gridWrap:tag('div'):addClass('calendar-grid-days'):wikitext('<div>Mon</div><div>Tue</div><div>Wed</div><div>Thu</div><div>Fri</div><div>Sat</div><div>Sun</div>')
gridWrap:tag('div'):addClass('calendar-grid-dates')
local calRight = root:tag('div'):addClass('calendar-right')
calRight:tag('div'):addClass('cal-details-content')
return tostring(root)
end
return p