Module:Studio sessions

local p = {}

local function createTableHeaders(root) local tableRoot = root:tag('table') tableRoot:addClass('wikitable') :addClass('sortable') local headerRow = tableRoot:tag('tr') headerRow:tag('th') :css('padding-right', '5px') :css('font-weight', 'bold') :wikitext('Year') headerRow:tag('th') :css('padding-right', '5px') :css('font-weight', 'bold') :wikitext('Session') headerRow:tag('th') :css('padding-right', '5px') :css('font-weight', 'bold') :wikitext('Artist') -- headerRow:tag('th') -- 	:css('padding-right', '5px') -- 	:css('font-weight', 'bold') -- 	:wikitext('Albums') return tableRoot end

function p._generateTable local cargo = mw.ext.cargo local results = cargo.query(		'studio_sessions',		'era, YEAR(date_from)=year, _pageName=page_title, artist',		{ orderBy = 'date_from ASC' }	) -- First group by era local results_by_era = {} for r = 1, #results do		local result = results[r] if results_by_era[result['era']] == nil then results_by_era[result['era']] = {} end table.insert(results_by_era[result['era']], result) end

local root = mw.html.create local tableRoot = nil

local last_era = nil for era, sessions in pairs(results_by_era) do root:wikitext('\n\n==' .. era .. '==') :newline tableRoot = createTableHeaders(root)

for _i, session in ipairs(sessions) do			local tableRow = tableRoot:tag('tr') tableRow:tag('td') :wikitext(session['year']) tableRow:tag('td') :wikitext( .. session['page_title'] .. ) tableRow:tag('td') :wikitext( .. session['artist'] .. ) end

-- tableRow:tag('Albums') -- 	:wikitext(result['Albums']) end

return tostring(root) end

function p.main return p._generateTable end

return p