No edit summary |
No edit summary |
||
Line 94: | Line 94: | ||
-- Add captain to cargo table if it's active roster | -- Add captain to cargo table if it's active roster | ||
if args.status == 'active' then | if args.status == 'active' then | ||
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Squads', captain = | frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Squads', captain = values.id}} | ||
end | end | ||
Revision as of 23:40, 6 September 2022
Documentation for this module may be created at Module:Squad/doc
local getArgs = require('Module:Arguments').getArgs
local Flags = require('Module:Flags')
local Squad = {}
local VariablesLua = mw.ext.VariablesLua
function Squad.main(frame)
local args = getArgs(frame)
-- Get all unique properties from Person templates
properties = {}
for key, value in ipairs (args) do
local values = mw.text.jsonDecode(value)
for key2, value2 in pairs ( values ) do
if string.find(mw.text.jsonEncode(properties), '"' .. key2 .. '"') then
else
table.insert(properties, key2)
end
end
end
properties = mw.text.jsonEncode(properties)
local tableContainer = mw.html.create('table')
tableContainer:addClass('striped-table')
local titleRow = mw.html.create('tr')
titleRow:addClass('headerRow')
local idCell = mw.html.create('th')
idCell:wikitext('ID')
local nameCell = mw.html.create('th')
nameCell:wikitext('Name')
local positionCell = mw.html.create('th')
positionCell:addClass('position')
positionCell:wikitext('Position')
local joindateCell = mw.html.create('th')
joindateCell:wikitext('Join Date')
titleRow:node(idCell):node(nameCell):node(positionCell):node(joindateCell)
-- If status is not active, then see what other th tags need to be added
if ( args.status ~= 'active' ) then
if ( string.find(properties, '"leavedate"') ) then
local leaveDate = mw.html.create('th')
leaveDate:wikitext('Leave Date')
titleRow:node(leaveDate)
end
if ( string.find(properties, '"inactivedate"') ) then
local inactiveDate = mw.html.create('th')
inactiveDate:wikitext('Inactive Since')
titleRow:node(inactiveDate)
end
if ( string.find(properties, '"newteam"') ) then
local newTeam = mw.html.create('th')
newTeam:wikitext('New team')
titleRow:node(newTeam)
end
end
titleRow:node(titleHeader)
tableContainer:node(titleRow)
local currentTitle = mw.title.getCurrentTitle().text
local gameCategory = mw.text.split(currentTitle, '/')[1]
-- Go through all the Person template instances
for key, value in ipairs (args) do
local values = mw.text.jsonDecode(value)
local personRow = mw.html.create('tr')
personRow:addClass('person')
local id = mw.html.create('td')
id:addClass('playerID')
if ( values.flag ) then
flag = Flags.icon(values.flag, gameCategory)
id:wikitext(flag)
end
--Check if page with id exists and if it does, then link to it, otherwise string only
local pageExists = frame:callParserFunction('#ifexist', values.id, 'yes', 'no' )
if ( pageExists == 'yes' ) then
id:wikitext('<span>[[' .. values.id .. '|' .. values.id .. ']]</span>')
else
id:wikitext('<span>'.. values.id ..'</span>')
end
if ( values.captain ) then
-- Add captain to cargo table if it's active roster
if args.status == 'active' then
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Squads', captain = values.id}}
end
-- VariablesLua.vardefine(currentTitle .. 'captain', values.id)
id:wikitext('<span class="captain">[[File:Captain-32px.png|Captain|link=Category:'.. gameCategory .. '/Captains|Captain]]</span>')
end
mw.log('CARGOARGS')
mw.log(cargoStoreArgs)
mw.logObject(cargoStoreArgs)
local name = mw.html.create('td')
name:addClass('playerName')
name:wikitext(values.name)
local role = ''
if values.role then
role = ' (' .. values.role .. ')'
end
-- Add coach and manager to cargo table if exist
mw.log(string.upper(values.position))
if string.upper(values.position) == 'COACH' and args.status == 'active' then
mw.log('PEAKSIN COACHI LISAMA')
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Squads', coach = values.id}}
end
if string.upper(values.position) == 'MANAGER' and args.status == 'active' then
mw.log('PEAKSIN MANAGERI LISAMA')
frame:callParserFunction{name = '#cargo_store:', args = {_table = 'Squads', manager = values.id}}
end
local position = mw.html.create('td')
:addClass('position')
:wikitext(values.position .. role)
local joindate = mw.html.create('td')
joindate:wikitext(values.joindate)
personRow:node(id):node(name):node(position):node(joindate)
-- If not active squad, then go add additional columns to table
if ( args.status ~= 'active' ) then
if ( string.find(properties, '"leavedate"') ) then
local leaveText = mw.html.create('td')
:addClass('tc')
:wikitext(values.leavedate or '-')
personRow:node(leaveText)
end
if ( string.find(properties, '"inactivedate"') ) then
local inactiveDate = mw.html.create('td')
:addClass('tc')
:wikitext(values.inactivedate or '-')
personRow:node(inactiveDate)
end
if ( string.find(properties, '"newteam"')) then
local newTeam = mw.html.create('td')
if values.newteam then
--Check if page newteam exists and if it does, then link to it, otherwise string only
local pageExists = frame:callParserFunction('#ifexist', gameCategory .. '/' .. values.newteam, 'yes', 'no' )
if ( pageExists == 'yes' ) then
newTeam:wikitext('<span>[[' .. gameCategory .. '/' .. values.newteam .. '|' .. values.newteam .. ']]</span>')
else
newTeam:wikitext(values.newteam)
end
else
newTeam:wikitext('')
end
personRow:node(newTeam)
end
end
titleRow:node(personRow)
end
return tableContainer
end
return Squad