Jump to content

Module:Infobox cabinet members

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Zackmann08 (talk | contribs) at 21:33, 18 September 2018 (WIP). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs

local p = {}
function p.infobox(frame, args)
	if not args then
		args = getArgs(frame)
	end
	mw.logObject(args)
	local root = mw.html.create()
	local columns = '4'
	-- local host = args['host']
	-- local hostColor = '#ccccff'
	-- local defaultRowColor = '#f8f9fa'
	-- local flagTemplate = args['flag_template'] or 'flagteam'
	-- local event = args['event']
	-- local totalGold = 0
	-- local totalSilver = 0
	-- local totalBronze = 0

	root = root
		:tag('table')
		:addClass('infobox')
		:css('width', 'auto')
		:css('text-align', 'left')
		:css('line-height', '1.2em')
		:css('margin-left', '1em')
		:css('margin-right', '0em')
		:css('float', 'right')
		:css('clear', 'right')

	root
		:tag('tr'):tag('td')
			:attr('colspan', columns)
			:css('text-align', 'center')
			:wikitext(args['topimage'])
		:tag('tr'):tag('td')
			:attr('colspan', columns)
			:css('text-align', 'center')
			:wikitext(args['topcaption'])
		:tag('tr'):tag('th')
			:attr('colspan', columns)
			:css('line-height','1.5em')
			:css('font-size','110%')
			:css('background','#DCDCDC')
			:css('text-align', 'center')
			:wikitext(args['above'])
--TODO: Use infobox image!
		:tag('tr'):tag('td')
			:attr('colspan', columns)
			:css('text-align', 'center')
			:wikitext(args['image'])
		:tag('tr'):tag('td')
			:attr('colspan', columns)
			:css('text-align', 'center')
			:wikitext(args['caption'])
		:tag('tr')
			:tag('th')
				:wikitext('Office')
			:tag('th')
				:wikitext('Name')
			:tag('th')
				:wikitext('Party')
			:tag('th')
				:wikitext('Term')
		:tag('tr')
			:tag('td')
				:attr('colspan', columns)
				:css('background', '#000')
		
		local officeNums = {}
		
		for k,v in pairs(args) do
			k = ''..k
			local num = k:match('^office(%d+)$') 
			if num then table.insert(officeNums, tonumber(num)) end
		end
		mw.logObject(officeNums)
				
	-- Build the office parts
		-- :tag('tr')
		-- 	:tag('td')
		-- 		:attr('rowspan','5')
		-- 		:wikitext(args['office1'])
		-- 	:tag('th')
		-- 		:css('font-weight', 'bold')
		-- 		:wikitext(args['name1a'])
		-- 	:tag('td')
		-- 		:wikitext(args['party1a'])
		-- 	:tag('td')
		-- 		:wikitext(args['term1a'])
	
	
	
	-- root:tag('caption')
	-- 	:wikitext(args['caption'])
	-- -- add the header row
	-- root:tag('tr')
	-- 		:tag('th')
	-- 			:wikitext('Rank')
	-- 		:tag('th')
	-- 			:wikitext('Nation')
	-- 		:tag('th')
	-- 			:addClass('headerSort')
	-- 			:css('width', '6em')
	-- 			:css('background-color', 'gold')
	-- 			:wikitext('Gold')
	-- 		:tag('th')
	-- 			:addClass('headerSort')
	-- 			:css('width', '6em')
	-- 			:css('background-color', 'silver')
	-- 			:wikitext('Silver')
	-- 		:tag('th')
	-- 			:addClass('headerSort')
	-- 			:css('width', '6em')
	-- 			:css('background-color', '#c96')
	-- 			:wikitext('Bronze')
	-- 		:tag('th')
	-- 			:css('width', '6em')
	-- 			:wikitext('Total')
	
	-- -- enumerate the rows
	-- local rowNums = {}
	
	-- for k,v in pairs(args) do
	-- 	k = ''..k
	-- 	local nation = k:match('^gold_([A-Z][A-Z][A-Z])$') 
	-- 	if nation then
	-- 		local total = tonumber(args['total' .. nation]) or (
	-- 			(tonumber(args['gold_' .. nation]) or 0) + 
	-- 			(tonumber(args['silver_' .. nation]) or 0) +
	-- 			(tonumber(args['bronze_' .. nation]) or 0))
	-- 		table.insert(rowNums, {total, nation}) 
	-- 	end
	-- end
	-- mw.logObject(rowNums)
	
	-- table.sort(rowNums, function (a, b) return a[1] > b[1] end)
	
	-- local lasttotal, lastspan, lastrankcell = -1, 1, nil
	-- for i, anum in ipairs(rowNums) do
	-- 	local IOC = anum[2]
	-- 	local name   = args['name_' .. IOC]
	-- 	local gold   = args['gold_' .. IOC]
	-- 	local silver = args['silver_' .. IOC]
	-- 	local bronze = args['bronze_' .. IOC]
	-- 	local isHost = args['host_' .. IOC]
	-- 	-- this is mainly for the parameter names example so you can override it.
	-- 	local total  = args['total_' .. IOC] or gold + silver + bronze
	-- 	local color
	-- 	if isHost then color = hostColor else color = defaultRowColor end

	-- 	if args['grand_total'] then else
	-- 			totalGold = totalGold + gold
	-- 			totalSilver = totalSilver + silver
	-- 			totalBronze = totalBronze + bronze
	-- 	end
	-- 	local nation
	-- 	if name then
	-- 		nation = name
	-- 	else
	-- 		nation = mw.getCurrentFrame():expandTemplate({title = flagTemplate, args = { IOC , event } })
	-- 	end

	-- 	local row = root:tag('tr'):css('background-color', color)
	-- 	-- if (flagTemplate and event) then
	-- 	-- 	nation = mw.getCurrentFrame():expandTemplate({title = flagTemplate, args = { nation, event } })
	-- 	-- end
	-- 	if total == lasttotal then
	-- 		lastspan = lastspan + 1
	-- 		lastrankcell:attr('rowspan',lastspan)
	-- 	else
	-- 		lastspan = 1
	-- 		lastrankcell = row:tag('td'):wikitext(i)
	-- 		lasttotal = total
	-- 	end
	-- 	row:tag('td')
	-- 			:css('text-align','left')
	-- 			:wikitext(nation)
	-- 		:tag('td')
	-- 			:wikitext(gold)
	-- 		:tag('td')
	-- 			:wikitext(silver)
	-- 		:tag('td')
	-- 			:wikitext(bronze)
	-- 		:tag('td')
	-- 			:wikitext(total)
	-- end

	-- root:tag('tr')
	-- 	:addClass('sortbottom')
	-- 	:tag('th')
	-- 		:wikitext('Totals')
	-- 		:attr('colspan',2)
	-- 	:tag('th')
	-- 		:wikitext(args['total_gold'] or totalGold)
	-- 	:tag('th')
	-- 		:wikitext(args['total_silver'] or totalSilver)
	-- 	:tag('th')
	-- 		:wikitext(args['total_bronze'] or totalBronze)
	-- 	:tag('th')
	-- 		:wikitext(args['grand_total'] or totalGold+totalSilver+totalBronze)

	-- if host then
	-- 	root
	-- 		:tag('p')
	-- 			:wikitext(host)
	-- 			:tag('span')
	-- 				:css('background-color', hostColor)
	-- 				:css('text-align', 'center')
	-- 				:css('padding', '2px')
	-- 				:css('margin', '2px')
	-- 				:css('border', '1px solid darkgray')
	-- 				:css('float', 'left')
	-- 				:css('height', '1em')
	-- 				:wikitext('   ')
	-- end

	return tostring(root)
end
return p