(Created page with "local cargo = mw.ext.cargo local Flags = require('Module:Flags') local PageLocations = {} function PageLocations.main(frame) local currentTitle = mw.title.getCurrentTitle().text local empty = true -- Check if there are any interviews for this page local tables = 'Locations' local fields = '_pageName, franchise, country, city, closed' local cargoArgs = { where = 'franchise="' .. currentTitle .. '"', orderBy = 'country, closed' } local results = cargo.query(...") |
mNo edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
local cargoArgs = { | local cargoArgs = { | ||
where = 'franchise="' .. currentTitle .. '"', | where = 'franchise="' .. currentTitle .. '"', | ||
orderBy = 'country, closed' | orderBy = 'country, city, closed' | ||
} | } | ||
local results = cargo.query(tables, fields, cargoArgs) | local results = cargo.query(tables, fields, cargoArgs) | ||
local | |||
local fullString = '' | |||
local container = mw.html.create() | local container = mw.html.create() | ||
:node(mw.html.create('h2'):wikitext('Locations')) | |||
if #results > 0 then | if #results > 0 then | ||
empty = false | empty = false | ||
local country = Flags.CountryName(results[1].country) | |||
fullString = fullString .. '<tabber>|-|' .. country .. '=' | |||
local Table = mw.html.create('table') | |||
:addClass('striped-table') | |||
local titleRow = mw.html.create('tr') | local titleRow = mw.html.create('tr') | ||
:addClass('headerRow') | :addClass('headerRow') | ||
Line 29: | Line 34: | ||
:wikitext('Name') | :wikitext('Name') | ||
local locationCell = mw.html.create('th') | local locationCell = mw.html.create('th') | ||
:wikitext(' | :wikitext('City') | ||
local statusCell = mw.html.create('th') | local statusCell = mw.html.create('th') | ||
:wikitext('Status') | :wikitext('Status') | ||
Table:node(titleRow:node(nameCell):node(locationCell):node(statusCell)) | |||
for r = 1, #results do | for r = 1, #results do | ||
local result = results[r] | local result = results[r] | ||
if results[r-1] and results[r-1].country ~= result.country then | |||
country = Flags.CountryName(result.country) | |||
fullString = fullString .. tostring(mw.clone(Table)) .. '|-|' .. country .. '=' | |||
Table = mw.html.create('table') | |||
:addClass('striped-table') | |||
titleRow = mw.html.create('tr') | |||
:addClass('headerRow') | |||
nameCell = mw.html.create('th') | |||
:wikitext('Name') | |||
locationCell = mw.html.create('th') | |||
:wikitext('City') | |||
statusCell = mw.html.create('th') | |||
:wikitext('Status') | |||
Table:node(titleRow:node(nameCell):node(locationCell):node(statusCell)) | |||
end | |||
local eventRow = mw.html.create('tr'):addClass('bodyRow') | local eventRow = mw.html.create('tr'):addClass('bodyRow') | ||
local name = mw.html.create('td'):wikitext('[[' .. result._pageName .. ']]') | local name = mw.html.create('td'):wikitext('[[' .. result._pageName .. ']]') | ||
-- local city = mw.html.create('td'):wikitext(result.city) | |||
local flagDiv = mw.html.create('div'):addClass('flag') | local flagDiv = mw.html.create('div'):addClass('flag') | ||
local location = mw.html.create('td') | local location = mw.html.create('td') | ||
:node(flagDiv) | :node(flagDiv) | ||
local flag = Flags.icon(result.country) | local flag = Flags.icon(result.country) | ||
flagDiv:wikitext(flag) | flagDiv:wikitext(flag) | ||
flagDiv:wikitext(result.city) | flagDiv:wikitext(result.city) | ||
local status = mw.html.create('td'):wikitext(result.closed == '1' and 'Closed' or 'Open') | local status = mw.html.create('td'):wikitext(result.closed == '1' and 'Closed' or 'Open') | ||
-- Table:node(eventRow:node(name):node(city):node(status)) | |||
Table:node(eventRow:node(name):node(location):node(status)) | |||
end | end | ||
fullString = fullString .. tostring(Table) | |||
end | end | ||
fullString = fullString .. '</tabber>' | |||
if empty then | if empty then | ||
return '<span class="d-none"></span>' | return '<span class="d-none"></span>' | ||
else | else | ||
return container | return container:wikitext(frame:preprocess(fullString)) | ||
end | end | ||
Latest revision as of 22:18, 19 February 2024
Documentation for this module may be created at Module:PageLocations/doc
local cargo = mw.ext.cargo local Flags = require('Module:Flags') local PageLocations = {} function PageLocations.main(frame) local currentTitle = mw.title.getCurrentTitle().text local empty = true -- Check if there are any interviews for this page local tables = 'Locations' local fields = '_pageName, franchise, country, city, closed' local cargoArgs = { where = 'franchise="' .. currentTitle .. '"', orderBy = 'country, city, closed' } local results = cargo.query(tables, fields, cargoArgs) local fullString = '' local container = mw.html.create() :node(mw.html.create('h2'):wikitext('Locations')) if #results > 0 then empty = false local country = Flags.CountryName(results[1].country) fullString = fullString .. '<tabber>|-|' .. country .. '=' local Table = mw.html.create('table') :addClass('striped-table') local titleRow = mw.html.create('tr') :addClass('headerRow') local nameCell = mw.html.create('th') :wikitext('Name') local locationCell = mw.html.create('th') :wikitext('City') local statusCell = mw.html.create('th') :wikitext('Status') Table:node(titleRow:node(nameCell):node(locationCell):node(statusCell)) for r = 1, #results do local result = results[r] if results[r-1] and results[r-1].country ~= result.country then country = Flags.CountryName(result.country) fullString = fullString .. tostring(mw.clone(Table)) .. '|-|' .. country .. '=' Table = mw.html.create('table') :addClass('striped-table') titleRow = mw.html.create('tr') :addClass('headerRow') nameCell = mw.html.create('th') :wikitext('Name') locationCell = mw.html.create('th') :wikitext('City') statusCell = mw.html.create('th') :wikitext('Status') Table:node(titleRow:node(nameCell):node(locationCell):node(statusCell)) end local eventRow = mw.html.create('tr'):addClass('bodyRow') local name = mw.html.create('td'):wikitext('[[' .. result._pageName .. ']]') -- local city = mw.html.create('td'):wikitext(result.city) local flagDiv = mw.html.create('div'):addClass('flag') local location = mw.html.create('td') :node(flagDiv) local flag = Flags.icon(result.country) flagDiv:wikitext(flag) flagDiv:wikitext(result.city) local status = mw.html.create('td'):wikitext(result.closed == '1' and 'Closed' or 'Open') -- Table:node(eventRow:node(name):node(city):node(status)) Table:node(eventRow:node(name):node(location):node(status)) end fullString = fullString .. tostring(Table) end fullString = fullString .. '</tabber>' if empty then return '<span class="d-none"></span>' else return container:wikitext(frame:preprocess(fullString)) end end return PageLocations