Documentation for this module may be created at Module:Organization/doc
local getArgs = require('Module:Arguments').getArgs
local Flags = require('Module:Flags')
local Organization = {}
local VariablesLua = mw.ext.VariablesLua
function Organization.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')
if args.title then
local title = mw.html.create('tr')
:addClass('headerRow'):node(mw.html.create('th'):addClass('table-title'):attr('colspan', 10):wikitext(args.title))
tableContainer:node(title)
end
local titleRow = mw.html.create('tr')
titleRow:addClass('headerRow')
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')
if ( string.find(properties, '"id"') ) then
local idCell = mw.html.create('th')
idCell:wikitext('ID')
titleRow:node(idCell)
end
titleRow: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, '"newcompany"') ) then
local newCompany = mw.html.create('th')
newCompany:wikitext('New company')
titleRow:node(newCompany)
end
end
titleRow:node(titleHeader)
tableContainer:node(titleRow)
-- 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('bodyRow')
if ( string.find(properties, '"id"') ) then
local idCell = mw.html.create('th')
idCell:wikitext('ID')
titleRow:node(idCell)
end
if values.id then
local id = mw.html.create('td')
id:addClass('linkID')
if ( values.flag ) then
local flag = Flags.icon(values.flag, 'Management')
id:wikitext(flag)
end
id:wikitext('<span>[[' .. values.id .. ']]</span>')
end
if values.name then
local name = mw.html.create('td')
:addClass('playerName')
if values.flag and values.id == nil then
local flag = Flags.icon(values.flag, 'Management')
name:wikitext(flag)
end
name:wikitext(values.name)
if string.find(properties, '"id"') == nil and values.id then
name:attr('colspan', 2)
end
personRow:node(name)
end
local position = mw.html.create('td')
:addClass('tc')
:wikitext(values.position)
local joindate = mw.html.create('td')
joindate:wikitext(values.joindate)
personRow: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, '"newcompany"')) then
local newComapny = mw.html.create('td')
if values.newteam then
newComapny:wikitext('[[' .. values.newteam .. ']]')
end
personRow:node(newComapny)
end
end
titleRow:node(personRow)
end
return tableContainer
end
return Organization