Module:Infobox location: Difference between revisions

From TwogPedia
mNo edit summary
No edit summary
 
(4 intermediate revisions by one other user not shown)
Line 15: Line 15:
function Infobox.main(frame)
function Infobox.main(frame)
local args = getArgs(frame)
local args = getArgs(frame)
   
 
local currentTitle = mw.title.getCurrentTitle().text
local currentTitle = mw.title.getCurrentTitle().text
local headerNode
local headerNode
Line 42: Line 42:
end
end
local container = mw.html.create('div')
local container = mw.html.create('div'):addClass('ib grid-infobox')
:addClass('ib')
container:node(headerNode):node(Subheader.make('Location Information'))
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
if args.closed then
container:node(RowWidget.make('Closed', args.closed or 'TBD'))
infoContainer:node(RowWidget.make('Closed', args.closed or 'TBD'))
end
end
if args.opened then
if args.opened then
container:node(RowWidget.make('Opened', args.opened))
infoContainer:node(RowWidget.make('Opened', args.opened))
end
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
if args.type then
container:node(RowWidget.make('Type', args.type))
    -- 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
end
 
if args.country then
if args.country then
container:node(RowWidget.make('Location', LocationWidget.make(args.country, args.city, 'Locations', args.state)))
infoContainer:node(RowWidget.make('Location', LocationWidget.make(args.country, args.city, 'Locations', args.state)))
end
end
if args.address then
if args.address then
container:node(RowWidget.make('Address', args.address))
infoContainer:node(RowWidget.make('Address', args.address))
end
end
if args.capacity then
if args.capacity then
container:node(RowWidget.make('Capacity', args.capacity))
infoContainer:node(RowWidget.make('Capacity', args.capacity))
end
end
if args.franchise and args.nosponsors == nil then
   
container:node(RowWidget.make('Franchise', 'Companies/' .. args.franchise, frame))
if args.franchise then
local tables = 'Sponsors'
        infoContainer:node(RowWidget.make('Franchise', args.franchise, frame, 'Companies/' ))
local fields = 'id, startRef, startRefName, endRef, endRefName'
        if  args.nosponsors == 'No' then
local cargoArgs = {
    local tables = 'Sponsors'
where = '_pageName="' ..args.franchise .. '"'
    local fields = 'id, startRef, startRefName, endRef, endRefName'
}
    local cargoArgs = {
local results = cargo.query(tables, fields, cargoArgs)
    where = '_pageName="Companies/' ..args.franchise .. '"'
if #results > 0 then
    }
    container:node(RowWidget.make('Sponsors', SponsorsWidget.make(results, frame)))
    local results = cargo.query(tables, fields, cargoArgs)
end
    if #results > 0 then
        infoContainer:node(RowWidget.make('Sponsors', SponsorsWidget.make(results, frame)))
    end
        end
end
end
if args.company then
if args.company then
container:node(RowWidget.make('Company', 'Companies/' .. args.company, true))
infoContainer:node(RowWidget.make('Company', args.company, true, 'Companies/'))
end
end


if args.sponsors and args.franchise == nil then
if args.sponsors and args.franchise == nil then
container:node(RowWidget.make('Sponsors', SponsorsWidget.make(args.sponsors, frame) ))
infoContainer:node(RowWidget.make('Sponsors', SponsorsWidget.make(args.sponsors, frame) ))
end
end
if args.locationsponsors then
if args.locationsponsors then
         local text = args.sponsors ~= nil and 'Location specific sponsors' or 'Sponsors'
         local text = args.sponsors ~= nil and 'Location specific sponsors' or 'Sponsors'
container:node(RowWidget.make(text, SponsorsWidget.make(args.locationsponsors , frame)))
infoContainer:node(RowWidget.make(text, SponsorsWidget.make(args.locationsponsors , frame)))
end
end
container:node(Subheader.make('Links'))
-- Check if there is a "links" argument and then do magic to add them all to arguments
-- Check if there is a "links" argument and then do magic to add them all to arguments
Line 107: Line 186:
end
end
end
end
local linksContainer = mw.html.create('div'):addClass('ib-links-container')
local transformedLinks = Links.transform(args)
local transformedLinks = Links.transform(args)
local fullLinks = LinksWidget.make(transformedLinks, 'team')
local fullLinks = LinksWidget.make(transformedLinks, 'team')
container:node(fullLinks)
linksContainer:node(fullLinks)
container:node(infoContainer)
    container:node(linksContainer)
   
return container
return container
end
end


return Infobox
return Infobox

Latest revision as of 02:57, 26 April 2025

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