Module:ArtistList

local p = {} local cargo = mw.ext.cargo local Util = require 'Module:Util' local List = require 'Module:ListUtil'

function p._artistList(args) local heroesQuery = List.group_by(cargo.query('Units', 'Artist=artist,_pageName=page,Name=name,CONCAT(0)=resplendent', { where = "Artist IS NOT NULL AND IFNULL(Properties__full,'') NOT LIKE '%generic%'", groupBy = 'Artist,_pageName', limit = 1000, }), function (x) return x.artist end) local heroesQueryR = List.group_by(cargo.query('ResplendentHero=R,Units=U', 'R.Artist=artist,U._pageName=page,U.Name=name,CONCAT(1)=resplendent', { join = 'R.Unit=U.WikiName', where = 'R.Artist IS NOT NULL AND U.WikiName IS NOT NULL', groupBy = 'R.artist,U.WikiName', limit = 1000, }), function (x) return x.artist end)

local artists = cargo.query('Artists', 'Name,_pageName=Page,NameUSEN,Company', {		groupBy = 'Name',		orderBy = 'NameUSEN',		limit = 1000,	})

-- Initialize the table local tbl = mw.html.create('table') :addClass('wikitable default sortable') :css('text-align','center') :css('width','66%')

-- Add table headers tbl:tag('th') :wikitext('Artist')

tbl:tag('th') :wikitext('Units')

-- Go through all the artists for _, artist in ipairs(artists) do		local allHeroes = List.concat(heroesQuery[artist.Name] or {}, heroesQueryR[artist.Name] or {}) if #allHeroes > 0 then local tr = tbl:tag('tr')

-- Add the artist name + link tr:tag('td'):wikitext(('%s%s%s'):format(artist.Page, artist.NameUSEN, artist.Name ~= artist.NameUSEN and (' (%s)'):format(artist.Name) or '', artist.Company ~=  and (' / %s'):format(artist.Company) or ))

-- Create a table where we'll add all the heroes the artist has drawn. local heroTable = tr:tag('td'):css('padding', '8px'):tag('div') :css('display', 'flex'):css('flex-flow', 'wrap'):css('justify-content', 'center')

-- Add all the heroes + portrait icons to the hero table table.sort(allHeroes, function (x, y) return x.name < y.name or (x.name == y.name and x.resplendent < y.resplendent) end) for _, hero in ipairs(allHeroes) do				heroTable:tag('div') :css('margin', '3px') :wikitext(('%s %s'):format(Util.getHeroIcon(hero.page, '75px', hero.resplendent == '1'), hero.page, hero.name)) end end end

return tostring(tbl) end

function p.artistList(frame) return p._artistList end

return p