Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki

To edit the documentation or categories for this module, click here. This module has an i18n file. Click here to edit it.


local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_form = require('Module:FormUtil')
local util_game = require('Module:GameUtil')
local util_esports = require('Module:EsportsUtil')
local util_html = require("Module:HtmlUtil")
local util_map = require('Module:MapUtil')
local util_table = require('Module:TableUtil')
local util_text = require("Module:TextUtil")
local util_vars = require('Module:VarsUtil')
local i18n = require('Module:i18nUtil')
local Team = require('Module:TeamClass')

local ColumnShowHide = require('Module:ColumnShowHide')
local LCS = require('Module:LuaClassSystem')

local h = {}

local p = LCS.class()

p.CLASSES = { RB3 = 'pbh-divider', RP3 = 'pbh-divider', BB5 = 'pbh-divider' }

p.S7_PICK_COLUMNS = { 'BB1', 'RB1', 'BB2', 'RB2', 'BB3', 'RB3', 'BP1', 'RP1-2', 'BP2-3', 'RP3', 'RB4', 'BB4', 'RB5', 'BB5', 'RP4', 'BP4-5', 'RP5' }
p.ROLE_COLUMNS = { 'BR1', 'BR2', 'BR3', 'BR4', 'BR5', 'RR1', 'RR2', 'RR3', 'RR4', 'RR5' }

p.OUTRO_COLUMNS = { 'SB', 'MH', 'VOD' }

p.CELLORDER = {
	BB1 = { 'Team1Ban1', classes = { 'pbh-ban', 'pbh-blue', } },
	RB1 = { 'Team2Ban1', classes = { 'pbh-ban', 'pbh-red', } },
	BB2 = { 'Team1Ban2', classes = { 'pbh-ban', 'pbh-blue', } },
	RB2 = { 'Team2Ban2', classes = { 'pbh-ban', 'pbh-red', } },
	BB3 = { 'Team1Ban3', classes = { 'pbh-ban', 'pbh-blue', } },
	RB3 = { 'Team2Ban3', classes = { 'pbh-ban', 'pbh-red', 'pbh-divider' } },
	
	BP1 = { 'Team1Pick1', classes = { 'pbh-blue', }, mandatory = true },
	['RP1-2'] = { 'Team2Pick1', 'Team2Pick2', classes = { 'pbh-red', }, mandatory = true },
	['BP2-3'] = { 'Team1Pick2', 'Team1Pick3', classes = { 'pbh-blue', }, mandatory = true },
	RP3 = { 'Team2Pick3', classes = { 'pbh-red', 'pbh-divider' }, mandatory = true },
	
	BB4 = { 'Team1Ban4', classes = { 'pbh-ban', 'pbh-blue', } },
	RB4 = { 'Team2Ban4', classes = { 'pbh-ban', 'pbh-red', } },
	RB5 = { 'Team2Ban5', classes = { 'pbh-ban', 'pbh-red', } },
	BB5 = { 'Team1Ban5', classes = { 'pbh-ban', 'pbh-blue', 'pbh-divider' } },
	
	RP4 = { 'Team2Pick4', classes = { 'pbh-red', }, mandatory = true },
	['BP4-5'] = { 'Team1Pick4', 'Team1Pick5', classes = { 'pbh-blue', }, mandatory = true },
	RP5 = { 'Team2Pick5', classes = { 'pbh-red', }, mandatory = true },
}

function p:init(args, page, queryClass, formatterClass)
	self.args = args
	self.page = page
	self.queryClass = queryClass
	self.formatterClass = formatterClass
	if util_args.castAsBool(args.debug) then
		self.DEBUG = true
	end
	args.team = Team(args.team)
	i18n.init('PickBanHistory')
end

function p:run()
	if not self.page then return '' end
	self.formatterClass.CELLORDER = self.CELLORDER
	self.formatterClass.ROLE_COLUMNS = self.ROLE_COLUMNS
	self.OUTRO_COLUMNS = self.formatterClass:concatRoleHeaders(self.OUTRO_COLUMNS, self.ROLE_COLUMNS)
	self.COLUMNS = util_table.mergeArrays(
		self.formatterClass.INTRO_COLUMNS,
		self.S7_PICK_COLUMNS,
		self.OUTRO_COLUMNS
	)
	self.formatterClass.COLUMNS = self.COLUMNS
	local result = self:makeAndRunQuery()
	if #result == 0 then return '' end
	self:formatResults(result)
	return self:makeOutput(result)
end

-- cargo
function p:makeAndRunQuery()
	return util_cargo.queryAndCast(self.queryClass:makeQuery())
end

-- format data (mostly delegated)
function p:formatResults(result)
	util_map.selfRowsInPlace(self, result, self.formatRow)
end

function p:formatRow(row)
	self.formatterClass:formatRow(row)
end

-- make output
function p:getEntityDisplayName()
	if self.args.display then return self.args.display end
	return self:queryEntityDisplayName() or self.page
end

function p:queryEntityDisplayName()
	return self.queryClass:queryEntityDisplayName()
end

function p:makeOutput(result)
	local output = mw.html.create()
	output:wikitext(i18n.print('introMessage'), '\n')
	self:printTable(output, result)
	output:node(self.formatterClass:makeColorPicker())
	return output
end

function p:printTable(outer, formatted)
	local div = outer:tag('div'):attr('id','pbh-outer'):addClass('wide-content-scroll')
	ColumnShowHide.printToggles(div, self.COLUMNS)
	local tbl = div:tag('table')
		:addClass('wikitable plainlinks hoverable-rows')
		:attr('id','pbh-table')
	ColumnShowHide.printTableClass(tbl)
	self:printHeader(tbl)
	for _, row in ipairs(formatted) do
		local tr = tbl:tag('tr')
		for _, col in ipairs(self.COLUMNS) do
			local td = tr:tag('td')
			td:wikitext(row.data[col])
			for attr, val in pairs(row.attrs[col] or {}) do
				td:attr(attr,val)
			end
			for _, class in ipairs(row.classes[col] or {}) do
				td:addClass(class or '')
			end
		end
	end
	return tbl
end

function p:printHeader(tbl)
	local tr = util_html.printColspanHeader(
		tbl,
		i18n.print('title', self.queryClass:queryEntityMarkup()),
		#self.COLUMNS
	)
	local th = util_html.lastChild(tr)
	self:printLinkToTextOnly(th)
	local tr = tbl:tag('tr')
	for k, cellPreload in ipairs(self.COLUMNS) do
		tr:tag('th'):wikitext(cellPreload)
		:addClass(self.CLASSES[cellPreload])
	end
	return tr
end

function p:printLinkToTextOnly(th)
	local entityName = self:queryEntityDisplayName()
	local formInfo = self.queryClass.FORM_INFO
	return self.formatterClass:printLinkToTextOnly(th, formInfo, entityName)
end

return p
Advertisement