Module:CompanyLanding: Difference between revisions
From TwogPedia
mNo edit summary |
mNo edit summary |
||
(7 intermediate revisions by the same user not shown) | |||
Line 31: | Line 31: | ||
function p.query(page) | function p.query(page) | ||
local tables = 'Companies' | local tables = 'Companies' | ||
local fields = '_pageName | local fields = '_pageName, country' | ||
local cargoArgs = { | local cargoArgs = { | ||
limit = limit, | limit = limit, | ||
offset = (page - 1) * limit, | offset = (page - 1) * limit, | ||
orderBy = ' | orderBy = '_pageName ASC' | ||
-- orderBy = 'SUBSTRING(_pageName, LENGTH("Companies/" + 1)' | -- orderBy = 'SUBSTRING(_pageName, LENGTH("Companies/" + 1)' | ||
} | } | ||
Line 49: | Line 49: | ||
if #results > 0 then | if #results > 0 then | ||
local letter = VariablesLua.varexists('firstLetter') and VariablesLua.var('firstLetter') or string.upper(string.sub( | local pageDisplayName = string.gsub(results[1]._pageName, 'Companies/', '') | ||
local letter = VariablesLua.varexists('firstLetter') and VariablesLua.var('firstLetter') or string.upper(string.sub(pageDisplayName, 1, 1)) | |||
if VariablesLua.varexists('firstLetter') and VariablesLua.var('firstLetter') ~= string.upper(string.sub( | if VariablesLua.varexists('firstLetter') and VariablesLua.var('firstLetter') ~= string.upper(string.sub(pageDisplayName, 1, 1)) then list = list .. tostring(mw.html.create('div'):css('font-weight', '800'):wikitext(letter)) end | ||
if page == 1 then list = list .. tostring(mw.html.create('div'):css('font-weight', '800'):wikitext(letter)) end | |||
for i = 1, #results do | for i = 1, #results do | ||
local result = results[i] | local result = results[i] | ||
pageDisplayName = mw.ext.displaytitle.get(result._pageName) | |||
local firstLetter = string.upper(string.sub( | local firstLetter = string.upper(string.sub(pageDisplayName, 1, 1)) | ||
-- Create new list for entries with next starting letter | -- Create new list for entries with next starting letter | ||
Line 63: | Line 64: | ||
end | end | ||
local company = mw.html.create('li'):wikitext('[[' .. result._pageName | local company = mw.html.create('li'):wikitext('[[' .. result._pageName .. ']]') | ||
list = list .. tostring(company) | list = list .. tostring(company) |
Latest revision as of 08:23, 16 January 2024
Documentation for this module may be created at Module:CompanyLanding/doc
local cargo = mw.ext.cargo
local VariablesLua = mw.ext.VariablesLua
local getArgs = require('Module:Arguments').getArgs
local p = {}
local limit = 25
function p.Main(frame)
local args = getArgs(frame)
if args.more then return p.html(args.page or 1) end
local tableContainer = mw.html.create('div')
-- tableContainer:node(mw.html.create('h2'):wikitext('Companies'))
local listContainer = mw.html.create('div'):attr('id', 'list__container')
tableContainer:node(listContainer)
local html = p.html(args.page or 1)
if html == nil or html == '' then
return tableContainer:wikitext('No companies in the database')
else
listContainer:node(html)
local loadMore = frame:callParserFunction{ name = '#widget', args = { 'Pagination', id = 'list__container', template = 'CompanyLanding'} }
tableContainer:node(loadMore)
end
return tableContainer
end
function p.query(page)
local tables = 'Companies'
local fields = '_pageName, country'
local cargoArgs = {
limit = limit,
offset = (page - 1) * limit,
orderBy = '_pageName ASC'
-- orderBy = 'SUBSTRING(_pageName, LENGTH("Companies/" + 1)'
}
local results = cargo.query(tables, fields, cargoArgs)
return results
end
function p.html(page)
local results = p.query(page)
local list = ''
local ulDiv = mw.html.create('div')
if #results > 0 then
local pageDisplayName = string.gsub(results[1]._pageName, 'Companies/', '')
local letter = VariablesLua.varexists('firstLetter') and VariablesLua.var('firstLetter') or string.upper(string.sub(pageDisplayName, 1, 1))
if VariablesLua.varexists('firstLetter') and VariablesLua.var('firstLetter') ~= string.upper(string.sub(pageDisplayName, 1, 1)) then list = list .. tostring(mw.html.create('div'):css('font-weight', '800'):wikitext(letter)) end
if page == 1 then list = list .. tostring(mw.html.create('div'):css('font-weight', '800'):wikitext(letter)) end
for i = 1, #results do
local result = results[i]
pageDisplayName = mw.ext.displaytitle.get(result._pageName)
local firstLetter = string.upper(string.sub(pageDisplayName, 1, 1))
-- Create new list for entries with next starting letter
if firstLetter ~= letter then
list = list .. tostring(mw.html.create('div'):css('font-weight', '800'):wikitext(firstLetter))
letter = firstLetter
end
local company = mw.html.create('li'):wikitext('[[' .. result._pageName .. ']]')
list = list .. tostring(company)
end
VariablesLua.vardefine('firstLetter', letter)
else
return nil
end
return list
end
return p
No categories