Module:SpoilerFreeSchedule

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_esports = require('Module:EsportsUtil') local util_form = require('Module:FormUtil') local util_html = require('Module:HtmlUtil') local util_table = require("Module:TableUtil") local util_text = require('Module:TextUtil') local util_time = require('Module:TimeUtil') local util_toggle = require('Module:ToggleUtil') local util_vars = require('Module:VarsUtil') local i18n = require('Module:i18nUtil') local PHASE_SETTINGS = { { 		toggle = 'UpcomingNo', hidden = '_tog_object _toggle_inithide', when = '<', title = '[Show/Hide] Completed Matches' },	{		toggle = 'UpcomingYes', hidden = '', when = '>', title = '[Show/Hide] Upcoming Matches' } }

local SQA = require('Module:ScheduleQueryAbstract'):extends local h = {}

local p = {} function p.main(frame) local args = util_args.merge return SQA(args[1]):run(args) end

function SQA:init(page) self:super('init', page) table.insert(self.columns, 1, 'Match') table.insert(self.columns, 1, 'Round') util_table.push(self.columns, 'VodsStream') self.widths.Round = 75 self.widths.Match = 300 self.widths.VodsStream = 125 self.hideTBD = false end

function SQA:run(args) local output = mw.html.create self:printOutputInitialText(output) local tbl = output:tag('table'):addClass('wikitable'):css('text-align','center') for _, phase in ipairs(PHASE_SETTINGS) do		self:printPhaseStart(tbl, phase) local result = util_cargo.queryAndCast(self:makeQuery(phase.when)) for _, row in ipairs(result) do local tr = tbl:tag('tr'):addClass('_tog_object _toggle ' .. phase.toggle):addClass(phase.hidden) tr:tag('td'):wikitext(row.Tab or row.Round or ''):done self:printMatch(tr, row) self:printDateAndTime(tr, row) h.printVodsOrStream(tr, row) end end return output end

function SQA:printOutputInitialText(output) output:wikitext(('Click here to view tournament page.'):format(self.page)) util_html.clear(output) self:printCalendarExportFormLink(output) util_html.clear(output) self:printToggler(output) end

function SQA:printCalendarExportFormLink(output) local url = util_form.fullURL({ template = 'MCE', form = 'MatchCalendarExport' }, { self.page }) output:wikitext(util_text.extLink(url, 'Click here'), ' to create a CSV export of this event to your calendar.') end

function SQA:printPhaseStart(tbl, phase) tbl:tag('tr') :tag('th') :attr('colspan',#self.columns) :addClass('_tog_object _toggler-' .. phase.toggle) :wikitext(phase.title) self:printWidthRow(tbl) local tr = tbl:tag('tr'):addClass('_tog_object _toggle ' .. phase.toggle):addClass(phase.hidden) self:printHeadings(tr) end

function SQA:makeQuery(when) return { tables = { 'MatchSchedule=MS', 'MatchScheduleGame=MSG' }, join = { 'MS.UniqueMatch=MSG.UniqueMatch' }, fields = { 'MS.Team1', 'MS.Team2', 'MS.Tab', 'MS.Round', 'MS.DateTime_UTC=UTC', 'MS.Stream', 'MS.DST', 'MS.HasTime [boolean]', 'MS.BestOf', 'MS.UniqueMatch', 'MS.Vod', },		where = ('MS.OverviewPage="%s" AND MS.DateTime_UTC %s NOW'):format(self.page, when), groupBy = 'MS.UniqueMatch', orderBy = 'MS.DateTime_UTC', } end

function h.printVodsOrStream(tr, row) if row.Vod then tr:tag('td'):wikitext(string.format('[%s VOD]', row.Vod)) elseif row.Stream then tr:tag('td'):wikitext(string.format('[%s Stream]', row.Stream)) else tr:tag('td'):wikitext('Stream') end return end

return p