No edit summary |
mNo edit summary |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local stringifyDate = require('Module:Functions').stringifyDate | |||
local Flags = require('Module:Flags') | local Flags = require('Module:Flags') | ||
local cargo = mw.ext.cargo | |||
local Organization = {} | local Organization = {} | ||
Line 8: | Line 9: | ||
function Organization.main(frame) | function Organization.main(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
if VariablesLua.varexists('Employees') == false or VariablesLua.var('Employees') == '' then return '' end | |||
local tables = mw.text.split(VariablesLua.var( 'Employees' ), '&&&') | |||
-- Get all unique properties from Person templates | -- Get all unique properties from Person templates | ||
properties = {} | properties = {} | ||
for | for i = 1, #tables do | ||
local values = mw.text.jsonDecode( | local values = mw.text.jsonDecode(tables[i]) | ||
for key2, value2 in pairs ( values ) do | for key2, value2 in pairs ( values ) do | ||
if string.find(mw.text.jsonEncode(properties), '"' .. key2 .. '"') then | if string.find(mw.text.jsonEncode(properties), '"' .. key2 .. '"') then | ||
else | else | ||
table.insert(properties, key2) | table.insert(properties, key2) | ||
Line 76: | Line 80: | ||
tableContainer:node(titleRow) | tableContainer:node(titleRow) | ||
-- Go through all the Person template instances | -- Go through all the Person template instances | ||
for | for i = 1, #tables do | ||
local values = mw.text.jsonDecode( | local values = mw.text.jsonDecode(tables[i]) | ||
local personRow = mw.html.create('tr') | local personRow = mw.html.create('tr') | ||
personRow:addClass('bodyRow') | personRow:addClass('bodyRow') | ||
if ( string.find(properties, '"id"') ) then | -- if ( string.find(properties, '"id"') ) then | ||
-- local idCell = mw.html.create('th') | |||
-- idCell:wikitext('ID') | |||
-- titleRow:node(idCell) | |||
end | -- end | ||
-- Check if person is added for the name and nationality | |||
local tables = 'People' | |||
local fields = '_pageName, nationality, name, romanized' | |||
local pageName = values.id or '' | |||
local cargoArgs = { | |||
where = '_pageName="People/' .. pageName .. '"' | |||
} | |||
local results = cargo.query(tables, fields, cargoArgs) | |||
if #results > 0 then | |||
values.name = results[1].romanized or results[1].name or values.name | |||
values.flag = results[1].nationality or values.flag | |||
end | |||
if values.id then | if values.id then | ||
local | local idFlagDiv = mw.html.create('div'):addClass('flag') | ||
local id = mw.html.create('td') | local id = mw.html.create('td') | ||
:addClass('linkID') | :addClass('linkID') | ||
:node( | :node(idFlagDiv) | ||
if ( values.flag ) then | if ( values.flag ) then | ||
local | local idFlag = Flags.icon(values.flag, 'Management') | ||
idFlagDiv:wikitext(idFlag) | |||
end | end | ||
local link = mw.title.new('People' .. values.id) and 'People/' .. values.id or 'People/' .. values.id .. '|' .. values.id | |||
idFlagDiv:wikitext('<span>[[' .. link .. '|' .. values.id .. ']]</span>') | |||
personRow:node(id) | |||
end | end | ||
if values.name then | if values.name then | ||
Line 126: | Line 147: | ||
:wikitext(values.position) | :wikitext(values.position) | ||
local joindate = mw.html.create('td') | local joindate = mw.html.create('td') | ||
joindate:wikitext(values.joindate) | joindate:wikitext(stringifyDate(values.joindate)) | ||
personRow:node(position):node(joindate) | personRow:node(position):node(joindate) | ||
Line 142: | Line 163: | ||
local inactiveDate = mw.html.create('td') | local inactiveDate = mw.html.create('td') | ||
:addClass('tc') | :addClass('tc') | ||
:wikitext(values.inactivedate or '-') | :wikitext(stringifyDate(values.inactivedate) or '-') | ||
personRow:node(inactiveDate) | personRow:node(inactiveDate) | ||
end | end | ||
Line 157: | Line 178: | ||
titleRow:node(personRow) | titleRow:node(personRow) | ||
end | end | ||
VariablesLua.vardefine( 'Employees', '') | |||
return tableContainer | return tableContainer | ||
end | end | ||
return Organization | return Organization |
Latest revision as of 08:33, 25 April 2024
Documentation for this module may be created at Module:Organization/doc
local getArgs = require('Module:Arguments').getArgs
local stringifyDate = require('Module:Functions').stringifyDate
local Flags = require('Module:Flags')
local cargo = mw.ext.cargo
local Organization = {}
local VariablesLua = mw.ext.VariablesLua
function Organization.main(frame)
local args = getArgs(frame)
if VariablesLua.varexists('Employees') == false or VariablesLua.var('Employees') == '' then return '' end
local tables = mw.text.split(VariablesLua.var( 'Employees' ), '&&&')
-- Get all unique properties from Person templates
properties = {}
for i = 1, #tables do
local values = mw.text.jsonDecode(tables[i])
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 i = 1, #tables do
local values = mw.text.jsonDecode(tables[i])
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
-- Check if person is added for the name and nationality
local tables = 'People'
local fields = '_pageName, nationality, name, romanized'
local pageName = values.id or ''
local cargoArgs = {
where = '_pageName="People/' .. pageName .. '"'
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
values.name = results[1].romanized or results[1].name or values.name
values.flag = results[1].nationality or values.flag
end
if values.id then
local idFlagDiv = mw.html.create('div'):addClass('flag')
local id = mw.html.create('td')
:addClass('linkID')
:node(idFlagDiv)
if ( values.flag ) then
local idFlag = Flags.icon(values.flag, 'Management')
idFlagDiv:wikitext(idFlag)
end
local link = mw.title.new('People' .. values.id) and 'People/' .. values.id or 'People/' .. values.id .. '|' .. values.id
idFlagDiv:wikitext('<span>[[' .. link .. '|' .. values.id .. ']]</span>')
personRow:node(id)
end
if values.name then
local flagDiv = mw.html.create('div'):addClass('flag')
local name = mw.html.create('td')
:addClass('playerName')
:node(flagDiv)
if values.flag and values.id == nil then
local flag = Flags.icon(values.flag, 'Management')
flagDiv:wikitext(flag)
end
flagDiv: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(stringifyDate(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(stringifyDate(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
VariablesLua.vardefine( 'Employees', '')
return tableContainer
end
return Organization