Module:Variants: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
Im Wired In (talk | contribs) (Fix error when no variant smw data exists, and add tracking category) |
(Add logic for main variants table (so they are sorted the same)) |
||
Line 8: | Line 8: | ||
end |
end |
||
function |
function get_table_info(args, get_images) |
||
-- Format the search result as [[Page]]. At the moment, don't include profession data in the table |
|||
local page = entry[1] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
local variant_name = args.variant or mw.title.getCurrentTitle().fullText |
local variant_name = args.variant or mw.title.getCurrentTitle().fullText |
||
local query = { |
local query = { |
||
'[[Variant of::'..variant_name..']]', |
'[[Variant of::'..variant_name..']]', |
||
-- '?Profession A', |
|||
'?Profession Level A', |
'?Profession Level A', |
||
-- '?Profession B', |
|||
'?Profession Level B', |
'?Profession Level B', |
||
get_images and '?Image#64px;x64px = Image' or nil, |
|||
limit = args.limit or 500, |
limit = args.limit or 500, |
||
} |
} |
||
local smw_data = mw.smw.ask(query) |
local smw_data = mw.smw.ask(query) |
||
if not smw_data then |
if not smw_data then |
||
return |
return nil |
||
end |
end |
||
table.sort(smw_data, sort_entries) |
table.sort(smw_data, sort_entries) |
||
return smw_data |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return table_contents |
|||
end |
end |
||
function p. |
function p.variants_header(args) |
||
local |
local smw_data = get_table_info(args) |
||
local contents |
|||
⚫ | |||
if smw_data then |
|||
local html = mw.html.create('div'):addClass('variants-header'):wikitext(table_contents) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
else |
|||
contents = '[[Category:Empty variant list]]' |
|||
⚫ | |||
return mw.html.create('div') |
|||
:addClass('variants-header') |
|||
:wikitext(contents) |
|||
:done() |
|||
end |
end |
||
Line 46: | Line 46: | ||
local args = frame:getParent().args |
local args = frame:getParent().args |
||
args.variant = args[1] or args.variant |
args.variant = args[1] or args.variant |
||
return p. |
return p.variants_header(args) |
||
⚫ | |||
⚫ | |||
local smw_data = get_table_info(args, true) |
|||
if not smw_data then |
|||
return ':No variants found.' |
|||
end |
|||
local table = mw.html.create('table') |
|||
:addClass('sortable wikitable') |
|||
:tag('tr') |
|||
:tag('th') |
|||
:attr{ colspan = '2' } |
|||
:wikitext('Item') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Level') |
|||
:done() |
|||
:done() |
|||
for _, entry in ipairs(smw_data) do |
|||
table |
|||
:tag('tr') |
|||
:tag('td') |
|||
:css{ ['border-right'] = 'none' } |
|||
:wikitext(entry.Image) |
|||
:done() |
|||
:tag('td') |
|||
:css{ ['border-left'] = 'none' } |
|||
:wikitext(entry[1]) |
|||
:done() |
|||
:tag('td') |
|||
:wikitext(entry['Profession Level A']) |
|||
:done() |
|||
:done() |
|||
end |
|||
⚫ | |||
end |
|||
function p.main_table(frame) |
|||
local args = frame:getParent().args |
|||
args.variant = args[1] or args.variant |
|||
return p.variants_table(args) |
|||
end |
end |
||