Module:LocationsLanding: Difference between revisions

From TwogPedia
(Created page with "local cargo = mw.ext.cargo local Flags = require('Module:Flags') local p= {} function p.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, _rowID, country, city, closed' local cargoArgs = { orderBy = '_rowID DESC', limit = 30 } local results = cargo.query(tables, fields, cargoArgs) local container = mw.html.creat...")
 
mNo edit summary
 
Line 5: Line 5:


function p.main(frame)
function p.main(frame)
local currentTitle = mw.title.getCurrentTitle().text
local empty = true
local empty = true


Line 12: Line 11:
local fields = '_pageName, _rowID, country, city, closed'
local fields = '_pageName, _rowID, country, city, closed'
local cargoArgs = {
local cargoArgs = {
orderBy = '_rowID DESC',
orderBy = 'country, _rowID DESC',
         limit = 30
         limit = 200
}
}
local results = cargo.query(tables, fields, cargoArgs)
local results = cargo.query(tables, fields, cargoArgs)
    local fullString = ''


local container = mw.html.create('div')
local container = mw.html.create('div')
Line 24: Line 25:
if #results > 0 then
if #results > 0 then
empty = false
empty = false
        local country = Flags.CountryName(results[1].country)
fullString = fullString .. '<tabber>|-|' .. country .. '='
local country = Flags.CountryName(results[1].country)
local country = Flags.CountryName(results[1].country)
Line 40: Line 43:
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')
                countryCell= mw.html.create('th')
        :wikitext('Country')
locationCell = mw.html.create('th')
:wikitext('City')
statusCell = mw.html.create('th')
:wikitext('Status')
Table:node(titleRow:node(nameCell):node(countryCell):node(locationCell):node(statusCell))
end
local eventRow = mw.html.create('tr'):addClass('bodyRow')
local eventRow = mw.html.create('tr'):addClass('bodyRow')
Line 59: Line 81:
Table:node(eventRow:node(name):node(countryDiv):node(city):node(status))
Table:node(eventRow:node(name):node(countryDiv):node(city):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:node(Table)
        return container:wikitext(frame:preprocess(fullString))
-- return container:node(Table)
end
end

Latest revision as of 07:53, 7 June 2023

Documentation for this module may be created at Module:LocationsLanding/doc

local cargo = mw.ext.cargo
local Flags = require('Module:Flags')

local p= {}

function p.main(frame)
	local empty = true

	-- Check if there are any interviews for this page
	local tables = 'Locations'
	local fields = '_pageName, _rowID, country, city, closed'
	local cargoArgs = {
		orderBy = 'country, _rowID DESC',
        limit = 200
	}
	local results = cargo.query(tables, fields, cargoArgs)

    local fullString = ''

	local container = mw.html.create('div')
		-- :node(mw.html.create('h2'):wikitext('Locations'))
    local Table = mw.html.create('table')
			:addClass('striped-table')

	if #results > 0 then
		empty = false
        local country = Flags.CountryName(results[1].country)
		fullString = fullString .. '<tabber>|-|' .. country .. '='
		local country = Flags.CountryName(results[1].country)
	
		local titleRow = mw.html.create('tr')
			:addClass('headerRow')
		local nameCell = mw.html.create('th')
			:wikitext('Name')
		local countryCell= mw.html.create('th')
			:wikitext('Country')
        local locationCell = mw.html.create('th')
			:wikitext('City')
		local statusCell = mw.html.create('th')
			:wikitext('Status')
		Table:node(titleRow:node(nameCell):node(countryCell):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')
                countryCell= mw.html.create('th')
			        :wikitext('Country')
				locationCell = mw.html.create('th')
					:wikitext('City')
				statusCell = mw.html.create('th')
					:wikitext('Status')
				Table:node(titleRow:node(nameCell):node(countryCell):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'):addClass('tc')
            local countryDiv = mw.html.create('td'):addClass('tc')
			local flagDiv = mw.html.create('div'):addClass('flag')
			--local location = mw.html.create('td')
				-- :node(flagDiv)
			
			if result.country ~= '' then 
                local flag = Flags.icon(result.country)
			    countryDiv:node(flagDiv:wikitext(flag))
            end
			if result.city then city:wikitext(result.city) end
			
			local status = mw.html.create('td'):wikitext(result.closed == '1' and 'Closed' or 'Open')

			Table:node(eventRow:node(name):node(countryDiv):node(city):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))
		-- return container:node(Table)
	end
	
end

return p