Module:Infobox location
From TwogPedia
Documentation for this module may be created at Module:Infobox location/doc
local getArgs = require('Module:Arguments').getArgs
local Links = require('Module:Links')
local Header = require('Module:Infobox/Widget/Header')
local Subheader = require('Module:Infobox/Widget/Subheader')
local LinksWidget = require('Module:Infobox/Widget/Links')
local SponsorsWidget = require('Module:Infobox/Widget/Sponsors')
local LocationWidget = require('Module:Infobox/Widget/Location')
local RowWidget = require('Module:Infobox/Widget/Row')
local cargo = mw.ext.cargo
local Flags = require('Module:Flags')
local Infobox = {}
function Infobox.main(frame)
local args = getArgs(frame)
local currentTitle = mw.title.getCurrentTitle().text
local headerNode
if args.logoAll or args.logoLight or args.logoDark then
headerNode = Header.make(args.title or currentTitle, args.logoLight, args.logoDark, args.logoAll)
elseif args.franchise or args.company then
local currentDate = os.date('%Y-%m-%d')
local company = args.franchise or args.company
company = 'Companies/' .. company
local tables = 'Logos'
local fields = '_pageName, logoLight, logoDark, logoAll, start, end'
local cargoArgs = {
where = '_pageName="' .. company .. '" 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].logoAll ) then
headerNode = Header.make(args.title or currentTitle, nil, nil, results[1].logoAll)
else
headerNode = Header.make(args.title or currentTitle, results[1].logoLight, results[1].logoDark)
end
end
else
headerNode = Header.make(args.title or currentTitle)
end
local container = mw.html.create('div'):addClass('ib grid-infobox')
local titleContainer = mw.html.create('div')
:addClass('carousel-image-container')
:attr('id', 'image-container-small')
:node(headerNode)
container:node(titleContainer)
local infoContainer = mw.html.create('div'):addClass('info-container grid')
local titleParts = mw.text.split(mw.title.getCurrentTitle().text, "/")
local companyName = titleParts[2] or mw.title.getCurrentTitle().text
local companyRow = mw.html.create('div')
:addClass('ib-row')
:css('column-gap', '0', 'important')
local labelDiv = mw.html.create('div'):addClass('ib-rowName')
local valueDiv = mw.html.create('div')
:wikitext(companyName)
:css('font-weight', '700')
:css('font-size', '24px')
:css('color', '#ECEBEB')
companyRow:node(labelDiv)
companyRow:node(valueDiv)
infoContainer:node(companyRow)
if args.closed then
infoContainer:node(RowWidget.make('Closed', args.closed or 'TBD'))
end
if args.opened then
infoContainer:node(RowWidget.make('Opened', args.opened))
end
-- if args.type then
-- infoContainer:node(RowWidget.make('Type', args.type))
-- end
local locationsType = {
arena = { name = 'Arena', img = 'Arena.png' },
vr = { name = 'VR', img = 'VR.png' },
stadium = { name = 'Stadium', img = 'Stadium.png' },
internet_cafe = { name = 'Internet café', img = 'Internet Cafe.png' },
bar = { name = 'Bar', img = 'Bar.png' },
shop = { name = 'Shop', img = 'Shop.png' },
bootcamp = { name = 'Bootcamp', img = 'Bootcamp.png' },
mobile = { name = 'Mobile', img = 'Mobile.png' },
convention_center = { name = 'Convention Center', img = 'Convention Center.png' },
hotel = { name = 'Hotel', img = 'Hotel.png' },
educational = { name = 'educational', img = 'Educational.png' }
}
if args.type then
-- local typeDiv = mw.html.create('div'):addClass('type-icon-locations'):wikitext('Received args.type: ' .. args.type)
-- infoContainer:node(typeDiv)
local normalizedType = string.gsub(args.type, "%s+", " "):lower()
local typesList = {}
for type in string.gmatch(normalizedType, '([^,]+)') do
table.insert(typesList, type)
end
local allMapped = true
for _, type in ipairs(typesList) do
local mapping = locationsType[type]
if not mapping then
allMapped = false
break
end
end
if allMapped then
for _, type in ipairs(typesList) do
local mapping = locationsType[type]
local typeIcon = '[[File:' .. mapping.img .. '|20px|alt=' .. mapping.name .. ']]'
local typeDiv = mw.html.create('div'):addClass('type-icon-locations')
:wikitext(typeIcon .. ' ' .. mapping.name)
local rowHtml = mw.html.create('div'):addClass('ib-row')
:node(mw.html.create('div'):addClass('ib-rowName'):wikitext('Type: '))
:node(mw.html.create('div'):node(typeDiv))
infoContainer:node(rowHtml)
end
else
-- local errorDiv = mw.html.create('div'):addClass('type-icon-locations'):wikitext('No mapping found for: ' .. args.type)
-- infoContainer:node(errorDiv)
infoContainer:node(RowWidget.make('Type', args.type))
end
end
if args.country then
infoContainer:node(RowWidget.make('Location', LocationWidget.make(args.country, args.city, 'Locations', args.state)))
end
if args.address then
infoContainer:node(RowWidget.make('Address', args.address))
end
if args.capacity then
infoContainer:node(RowWidget.make('Capacity', args.capacity))
end
if args.franchise then
infoContainer:node(RowWidget.make('Franchise', args.franchise, frame, 'Companies/' ))
if args.nosponsors == 'No' then
local tables = 'Sponsors'
local fields = 'id, startRef, startRefName, endRef, endRefName'
local cargoArgs = {
where = '_pageName="Companies/' ..args.franchise .. '"'
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
infoContainer:node(RowWidget.make('Sponsors', SponsorsWidget.make(results, frame)))
end
end
end
if args.company then
infoContainer:node(RowWidget.make('Company', args.company, true, 'Companies/'))
end
if args.sponsors and args.franchise == nil then
infoContainer:node(RowWidget.make('Sponsors', SponsorsWidget.make(args.sponsors, frame) ))
end
if args.locationsponsors then
local text = args.sponsors ~= nil and 'Location specific sponsors' or 'Sponsors'
infoContainer:node(RowWidget.make(text, SponsorsWidget.make(args.locationsponsors , frame)))
end
-- Check if there is a "links" argument and then do magic to add them all to arguments
if args.links then
local splitLinks = mw.text.split(args.links, ',')
for i = 1, #splitLinks do
local split = mw.text.split(splitLinks[i], '=')
args[split[1]] = split[2]
end
end
local linksContainer = mw.html.create('div'):addClass('ib-links-container')
local transformedLinks = Links.transform(args)
local fullLinks = LinksWidget.make(transformedLinks, 'team')
linksContainer:node(fullLinks)
container:node(infoContainer)
container:node(linksContainer)
return container
end
return Infobox
No categories