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

Module:Calendar: Difference between revisions

From eSportsAmaze
Created page with "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 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 local whereClause = table.concat(whereParts, " AND ") if whereClause ==..."
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
local function sqlEscape(s)
    if not s then return "" end
    s = s:gsub("\\", "\\\\")
    s = s:gsub("'", "\\'")
    return s
end


function p.main(frame)
function p.main(frame)
Line 6: Line 13:
local tournament = args.tournament
local tournament = args.tournament
local game = args.game
local game = args.game
local stage = args.stage
local exclude_stage = args.exclude_stage


local whereParts = {}
local whereParts = {}
if tournament and tournament ~= "" then
if tournament and tournament ~= "" then table.insert(whereParts, "tournament='" .. sqlEscape(tournament) .. "'") end
table.insert(whereParts, "tournament='" .. tournament:gsub("'", "\\'") .. "'")
if game and game ~= "" then table.insert(whereParts, "game='" .. sqlEscape(game) .. "'") end
 
if stage and stage ~= "" then
table.insert(whereParts, "stage='" .. sqlEscape(stage) .. "'")  
end
end
if game and game ~= "" then
if exclude_stage and exclude_stage ~= "" then  
table.insert(whereParts, "game='" .. game:gsub("'", "\\'") .. "'")
table.insert(whereParts, "stage!='" .. sqlEscape(exclude_stage) .. "'")  
end
end


Line 18: Line 30:
if whereClause == "" then whereClause = "1=1" end
if whereClause == "" then whereClause = "1=1" end


-- Fetch all schedule data
-- ADDED STREAM TO QUERY
local results = cargo.query(
local results = cargo.query("Tournament_Schedule", "tournament, game, match_type, date, stage, stream, day_data", { where = whereClause, orderBy = "date ASC", limit = 500 })
"Tournament_Schedule",
"tournament, game, match_type, date, stage, day_data",
{ where = whereClause, orderBy = "date ASC", limit = 500 }
)


if not results or #results == 0 then
if not results or #results == 0 then
return "<div class='calendar-empty' style='padding:20px; text-align:center; background:var(--bg-card); border-radius:8px; border:1px solid var(--border-light);'>No schedule data found. Add matches using the MatchDay template.</div>"
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
end


-- Group data by Date
local scheduleByDate = {}
local scheduleByDate = {}
for _, row in ipairs(results) do
for _, row in ipairs(results) do
local d = row.date
local d = row.date
if not scheduleByDate[d] then scheduleByDate[d] = {} end
if not scheduleByDate[d] then scheduleByDate[d] = {} end
local raw = row.day_data
if not raw or raw == "" then raw = "[]" end
local ok, decoded = pcall(mw.text.jsonDecode, raw)
local data = ok and decoded or {}
table.insert(scheduleByDate[d], {
table.insert(scheduleByDate[d], {
tournament = row.tournament,
tournament = row.tournament, game = row.game, match_type = row.match_type, stage = row.stage, stream = row.stream,
game = row.game,
data = data
match_type = row.match_type,
stage = row.stage,
data = mw.text.jsonDecode(row.day_data)
})
})
end
end


local jsonString = mw.text.jsonEncode(scheduleByDate)
local jsonString = mw.text.jsonEncode(scheduleByDate)
-- Build UI Container
local root = mw.html.create('div'):addClass('esports-calendar-container')
local root = mw.html.create('div'):addClass('esports-calendar-container')


-- Hidden Data Island for JS to read
root:tag('div'):addClass('calendar-data'):css('display', 'none'):wikitext(jsonString)
root:tag('script')
:attr('type', 'application/json')
:addClass('calendar-data')
:wikitext(jsonString)


-- Left Side: The Calendar Grid
local calLeft = root:tag('div'):addClass('calendar-left')
local calLeft = root:tag('div'):addClass('calendar-left')
local header = calLeft:tag('div'):addClass('calendar-header')
local header = calLeft:tag('div'):addClass('calendar-header')
header:tag('button'):addClass('cal-prev'):wikitext('<i class="fa-solid fa-chevron-left"></i>')
 
header:tag('div'):addClass('cal-prev'):wikitext('&#10094;')
header:tag('div'):addClass('cal-month-year'):wikitext('Loading...')
header:tag('div'):addClass('cal-month-year'):wikitext('Loading...')
header:tag('button'):addClass('cal-next'):wikitext('<i class="fa-solid fa-chevron-right"></i>')
header:tag('div'):addClass('cal-next'):wikitext('&#10095;')


local gridWrap = calLeft:tag('div'):addClass('calendar-grid-wrapper')
local gridWrap = calLeft:tag('div'):addClass('calendar-grid-wrapper')
local daysRow = gridWrap:tag('div'):addClass('calendar-grid-days')
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>')
daysRow:wikitext('<div>Sun</div><div>Mon</div><div>Tue</div><div>Wed</div><div>Thu</div><div>Fri</div><div>Sat</div>')
gridWrap:tag('div'):addClass('calendar-grid-dates')
gridWrap:tag('div'):addClass('calendar-grid-dates') -- JS fills this


-- Right Side: The Details Panel
local calRight = root:tag('div'):addClass('calendar-right')
local calRight = root:tag('div'):addClass('calendar-right')
calRight:tag('div'):addClass('cal-details-placeholder')
calRight:tag('div'):addClass('cal-details-content')
:wikitext('<i class="fa-regular fa-calendar-days" style="font-size:3em; color:var(--border-thick); margin-bottom:15px; display:block;"></i>Select a highlighted date to view the schedule.')
calRight:tag('div'):addClass('cal-details-content'):css('display', 'none')


return tostring(root)
return tostring(root)

Latest revision as of 01:30, 3 March 2026

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

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

local function sqlEscape(s)
    if not s then return "" end
    s = s:gsub("\\", "\\\\")
    s = s:gsub("'", "\\'")
    return s
end

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='" .. sqlEscape(tournament) .. "'") end
if game and game ~= "" then table.insert(whereParts, "game='" .. sqlEscape(game) .. "'") end

if stage and stage ~= "" then 
table.insert(whereParts, "stage='" .. sqlEscape(stage) .. "'") 
end
if exclude_stage and exclude_stage ~= "" then 
table.insert(whereParts, "stage!='" .. sqlEscape(exclude_stage) .. "'") 
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

local raw = row.day_data
if not raw or raw == "" then raw = "[]" end
local ok, decoded = pcall(mw.text.jsonDecode, raw)
local data = ok and decoded or {}

table.insert(scheduleByDate[d], {
tournament = row.tournament, game = row.game, match_type = row.match_type, stage = row.stage, stream = row.stream,
data = 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('&#10094;')
header:tag('div'):addClass('cal-month-year'):wikitext('Loading...')
header:tag('div'):addClass('cal-next'):wikitext('&#10095;')

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