Module:Participants list team: Difference between revisions

From TwogPedia
No edit summary
mNo edit summary
Line 2: Line 2:


local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local makeFlag = require('Module:Player/Flag').makeFlag
local makeFlag = require('Module:People/Flag').makeFlag
local Links = require('Module:Links')
local Links = require('Module:Links')


Line 12: Line 12:


local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')
local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')
 
local container = mw.html.create('div')
local container = mw.html.create('div')
:addClass('p-team-container')
:addClass('p-team-container')
Line 25: Line 25:


local participant = mw.html.create('div')
local participant = mw.html.create('div')
local team = nil
if pValues.team then
if pValues.team then
-- Check if shorthand of a team was used
local tables = 'Teams'
local fields = '_pageName, shorthand'
local cargoArgs = {
where = '_pageName LIKE "' .. gameCategory .. '/%" AND shorthand = "' .. pValues.team .. '"'
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then team = results[1]._pageName else team = gameCategory .. '/' .. pValues.team end
local teamName = mw.html.create('div')
local teamName = mw.html.create('div')
:addClass('tc fw-600')
:addClass('tc fw-600')
:wikitext('[['.. gameCategory .. '/' .. pValues.team ..']]')
:wikitext('[['.. team ..']]')
if pValues.notes then
if pValues.notes then
local notesList = mw.text.split(pValues.notes, ',')
local notesList = mw.text.split(pValues.notes, ',')
Line 45: Line 55:
local players = {}
local players = {}
local playersDb = ''
for i = 1, teamsize, 1 do
for i = 1, teamsize, 1 do
if pValues['p'.. i] then
if pValues['p'.. i] then
Line 51: Line 62:
playerId = pValues['p'.. i .. 'link'] .. '|' .. pValues['p'.. i]
playerId = pValues['p'.. i .. 'link'] .. '|' .. pValues['p'.. i]
end
end
playersDb = playersDb .. (pValues['p'.. i .. 'link'] or 'People/' .. pValues['p'.. i]) .. ','
local flag = makeFlag(pValues['p'.. i .. 'flag'], pValues['p'.. i .. 'link'] or pValues['p'.. i], gameCategory)
local flag = makeFlag(pValues['p'.. i .. 'flag'], pValues['p'.. i .. 'link'] or 'People/' .. pValues['p'.. i], gameCategory)


players['p'.. i] = mw.html.create('tr')
players['p'.. i] = mw.html.create('tr')
Line 69: Line 80:
end
end
if team ~= nil and string.len(playersDb) > 0 then
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Participants', team = team, players = playersDb}}
end
if pValues.s then
if pValues.s then
local playerId = pValues.s
local playerId = 'People/' .. pValues.s .. '|' .. pValues.s
if pValues['slink'] then
if pValues['slink'] then
playerId = pValues['slink'] .. '|' .. pValues.s
playerId = pValues['slink'] .. '|' .. pValues.s
end
end
local flag = makeFlag(pValues['sflag'], pValues['slink'] or pValues.s, gameCategory)
local flag = makeFlag(pValues['sflag'], pValues['slink'] or 'People/' .. pValues.s, gameCategory)
local sub = mw.html.create('tr')
local sub = mw.html.create('tr')
Line 83: Line 98:
if pValues.c then
if pValues.c then
local playerId = pValues.c
local playerId = 'People/' .. pValues.c .. '|' .. pValues.c
if pValues['clink'] then
if pValues['clink'] then
playerId = pValues['clink'] .. '|' .. pValues.c
playerId = pValues['clink'] .. '|' .. pValues.c
end
end
local flag = makeFlag(pValues['cflag'], pValues['clink'] or pValues.c, gameCategory)
local flag = makeFlag(pValues['cflag'], pValues['clink'] or 'People/' .. pValues.c, gameCategory)


local coach = mw.html.create('tr')
local coach = mw.html.create('tr')
Line 107: Line 123:
local logo = pValues.logoLight or pValues.logoDark
local logo = pValues.logoLight or pValues.logoDark
relativeParent:node(Participants.createLogo(logo))
relativeParent:node(Participants.createLogo(logo))
else
elseif pValues.team then
-- Look up Cargo table for team images
-- Look up Cargo table for team images
local tables = 'TeamLogos'
local tables = 'Logos'
local fields = '_pageName, logoLight, logoDark, logoAll, start, end'
local fields = '_pageName, logoLight, logoDark, logoAll, iconAll, iconLight, iconDark, start, end'
local currentDate = os.date('%Y-%m-%d')
local currentDate = os.date('%Y-%m-%d')
local cargoArgs = {
local cargoArgs = {
where = '(_pageName = "' .. gameCategory .. '/' .. pValues.team.. '" OR _pageName= "' .. pValues.team.. '") AND  (start is NULL OR start < "' .. currentDate .. '") AND (end is NULL OR end > "' .. currentDate .. '")'
where = '_pageName = "' .. team .. '" AND  (start is NULL OR start < "' .. currentDate .. '") AND (end is NULL OR end > "' .. currentDate .. '")'
}
}
local results = cargo.query(tables, fields, cargoArgs)
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
if #results > 0 then
if results[1].logoAll then
if results[1].iconAll then
relativeParent:node(Participants.createLogo(results[1].iconAll))
elseif results[1].iconLight and results[1].iconDark then
relativeParent:node(Participants.createLogo(results[1].iconLight, 'light')):node(Participants.createLogo(results[1].iconDark, 'dark'))
elseif results[1].logoAll then
relativeParent:node(Participants.createLogo(results[1].logoAll))
relativeParent:node(Participants.createLogo(results[1].logoAll))
elseif results[1].logoLight and results[1].logoDark then
elseif results[1].logoLight and results[1].logoDark then
relativeParent:node(Participants.createLogo(results[1].logoLight, 'light')):node(Participants.createLogo(results[1].logoDark, 'dark'))
relativeParent:node(Participants.createLogo(results[1].logoLight, 'light')):node(Participants.createLogo(results[1].logoDark, 'dark'))
else  
else
local logo = results[1].logoLight or results[1].logoDark
local logo = results[1].iconLight or results[1].iconDark or results[1].logoLight or results[1].logoDark
relativeParent:node(Participants.createLogo(logo))
relativeParent:node(Participants.createLogo(logo))
end
end
Line 142: Line 162:
end
end
local wrapper = mw.html.create('div')
local wrapper = mw.html.create('div')
if args.showtoggle then
 
if args.showToggle then
local toggle = mw.html.create('div')
local toggle = mw.html.create('div')
:attr('id', 'team-toggle')
:attr('id', 'team-toggle')

Revision as of 11:17, 29 September 2023

Documentation for this module may be created at Module:Participants list team/doc

local cargo = mw.ext.cargo

local getArgs = require('Module:Arguments').getArgs
local makeFlag = require('Module:People/Flag').makeFlag
local Links = require('Module:Links')

local Participants = {}


function Participants.main(frame)
	local args = getArgs(frame)

	local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')

	local container = mw.html.create('div')
		:addClass('p-team-container')
	
	local teamsize = args.teamsize

	local currentTitle = mw.title.getCurrentTitle().text
	local gameCategory = mw.text.split(currentTitle, '/')[1]
	
	for key, value in ipairs (args) do
		local pValues = mw.text.jsonDecode(value)

		local participant = mw.html.create('div')
		local team = nil
		
		if pValues.team then
			-- Check if shorthand of a team was used
			local tables = 'Teams'
			local fields = '_pageName, shorthand'
			local cargoArgs = {
				where = '_pageName LIKE "' .. gameCategory .. '/%" AND shorthand = "' .. pValues.team .. '"'
			}
			local results = cargo.query(tables, fields, cargoArgs)
			if #results > 0 then team = results[1]._pageName else team = gameCategory .. '/' .. pValues.team end

			local teamName = mw.html.create('div')
				:addClass('tc fw-600')
				:wikitext('[['.. team ..']]')
			if pValues.notes then
				local notesList = mw.text.split(pValues.notes, ',')
				for i, v in ipairs (notesList) do
					v = mw.text.trim(v)
					teamName:node(mw.html.create('sup'):attr('title', 'Note ' .. v):wikitext(v))
				end
			end
			participant:node(teamName)
		end
		
		-- Create list of players
		local playerList = mw.html.create('table')
			:addClass('table-bordered players')
		
		local players = {}
		local playersDb = ''
		for i = 1, teamsize, 1 do
			if pValues['p'.. i] then
				local playerId = pValues['p'.. i]
				if pValues['p'.. i .. 'link'] then
					playerId = pValues['p'.. i .. 'link'] .. '|' .. pValues['p'.. i]
				end
				playersDb = playersDb .. (pValues['p'.. i .. 'link'] or 'People/' .. pValues['p'.. i]) .. ','
				local flag = makeFlag(pValues['p'.. i .. 'flag'], pValues['p'.. i .. 'link'] or 'People/' .. pValues['p'.. i], gameCategory)

				players['p'.. i] = mw.html.create('tr')
					:node(mw.html.create('th'):wikitext(i))
				
				local td = mw.html.create('td')

				if flag then
					td:wikitext(flag)
				end
				
				td:wikitext('[['.. playerId ..']]')
				players['p'.. i]:node(td)
				playerList:node(players['p'.. i])
			end
		end
		
		if team ~= nil and string.len(playersDb) > 0 then
			frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Participants', team = team, players = playersDb}}
		end

		if pValues.s then
			local playerId = 'People/' .. pValues.s .. '|' .. pValues.s
			if pValues['slink'] then
				playerId = pValues['slink'] .. '|' .. pValues.s
			end
			local flag = makeFlag(pValues['sflag'], pValues['slink'] or 'People/' .. pValues.s, gameCategory)
			
			local sub = mw.html.create('tr')
				:node(mw.html.create('th'):node(mw.html.create('abbr'):attr('title', 'Substitute'):wikitext('S')))
				:node(mw.html.create('td'):wikitext(flag):wikitext('[['.. playerId ..']]'))
			playerList:node(sub)
		end
		
		if pValues.c then
			local playerId = 'People/' .. pValues.c .. '|' .. pValues.c
			if pValues['clink'] then
				playerId = pValues['clink'] .. '|' .. pValues.c
			end
			
			local flag = makeFlag(pValues['cflag'], pValues['clink'] or 'People/' .. pValues.c, gameCategory)

			local coach = mw.html.create('tr')
				:node(mw.html.create('th'):node(mw.html.create('abbr'):attr('title', 'Coach'):wikitext('C')))
				:node(mw.html.create('td'):wikitext(flag):wikitext('[['.. playerId ..']]'))
			playerList:node(coach)
		end
		
		local relativeParent = mw.html.create('div')
			:addClass('team-list')
			:node(playerList)
		

		if pValues.logoAll then
			relativeParent:node(Participants.createLogo(pValues.logoAll))
		elseif pValues.logoLight and pValues.logoDark then
			relativeParent:node(Participants.createLogo(pValues.logoLight, 'light')):node(Participants.createLogo(pValues.logoDark, 'dark'))
		elseif pValues.logoLight or pValues.logoDark then
			local logo = pValues.logoLight or pValues.logoDark
			relativeParent:node(Participants.createLogo(logo))
		elseif pValues.team then
			-- Look up Cargo table for team images
			local tables = 'Logos'
			local fields = '_pageName, logoLight, logoDark, logoAll, iconAll, iconLight, iconDark, start, end'
			local currentDate = os.date('%Y-%m-%d')
			local cargoArgs = {
				where = '_pageName = "' .. team .. '" AND  (start is NULL OR start < "' .. currentDate .. '") AND (end is NULL OR end > "' .. currentDate .. '")'
			}
			local results = cargo.query(tables, fields, cargoArgs)
			if #results > 0 then
				if results[1].iconAll then
					relativeParent:node(Participants.createLogo(results[1].iconAll))
				elseif results[1].iconLight and results[1].iconDark then
					relativeParent:node(Participants.createLogo(results[1].iconLight, 'light')):node(Participants.createLogo(results[1].iconDark, 'dark'))
				elseif results[1].logoAll then
					relativeParent:node(Participants.createLogo(results[1].logoAll))
				elseif results[1].logoLight and results[1].logoDark then
					relativeParent:node(Participants.createLogo(results[1].logoLight, 'light')):node(Participants.createLogo(results[1].logoDark, 'dark'))
				else  
					local logo = results[1].iconLight or results[1].iconDark or results[1].logoLight or results[1].logoDark
					relativeParent:node(Participants.createLogo(logo))
				end
			else 
				relativeParent:node(Participants.createLogo())
			end
		end
		
		participant:node(relativeParent)
		
		if pValues.qualifier then
			local qualifier = mw.html.create('div')
				:addClass('team-list-qualifier')
				:wikitext(pValues.qualifier)
			participant:node(qualifier)
		end
		
		container:node(participant)
	end
	local wrapper = mw.html.create('div')

	if args.showToggle then
		local toggle = mw.html.create('div')
			:attr('id', 'team-toggle')
			:wikitext('Show Players')
		wrapper:node(toggle):node(container)
	else
		wrapper:node(container)	
	end
	
	return wrapper
end

function Participants.createLogo(url, class)
	local className = class and class .. ' h-100' or 'h-100'
	local logoURL = url and url or 'Team_placeholder_dark.png'
	local logoContainer = mw.html.create('div')
		:addClass(className)
	local logo = mw.html.create('div')
		:addClass('team-list-logo')
		:node('[[File:' .. logoURL .. '|190px]]')
	logoContainer:node(logo)
	return logoContainer
end

return Participants