Content deleted Content added
Alistair3149 (talk | contribs) No edit summary |
Alistair3149 (talk | contribs) No edit summary |
||
Line 59: | Line 59: | ||
local navplateData = {} |
local navplateData = {} |
||
-- Lua tables has no concept of order, need to iterate it manually |
|||
⚫ | |||
⚫ | |||
⚫ | |||
local label = navplateRow[ 'label' ] |
local label = navplateRow[ 'label' ] |
||
for _, result in pairs( data ) do |
for _, result in pairs( data ) do |
||
-- Match category |
-- Match category |
||
local categories = result[ 'Category' ] |
local categories = result[ 'Category' ] |
||
Line 67: | Line 70: | ||
for _, category in pairs( categories ) do |
for _, category in pairs( categories ) do |
||
if category == navplateRow[ 'conditions' ] then |
if category == navplateRow[ 'conditions' ] then |
||
-- Create row if it does not exist already |
|||
if navplateData[ i ] == nil then |
|||
navplateData[ i ] = { |
|||
label = label, |
|||
pages = {} |
|||
} |
|||
end |
end |
||
table.insert( navplateData[ |
table.insert( navplateData[ i ][ 'pages' ], result[ 'page' ] ) |
||
end |
end |
||
end |
end |
||
end |
end |
||
end |
|||
if navplateData[ i ] ~= nil then |
|||
i = i + 1 |
|||
end |
end |
||
end |
end |
||
Line 93: | Line 104: | ||
local navplateData = self:buildNavplateData( data ) |
local navplateData = self:buildNavplateData( data ) |
||
mw.logObject( navplateData ) |
mw.logObject( navplateData ) |
||
if navplateData ~= nil then |
if navplateData ~= nil then |
||
for i, row in ipairs( navplateData ) do |
|||
⚫ | |||
args[ 'label' .. i ] = row[ 'label' ] |
|||
args[ 'list' .. i ] = table.concat( row[ 'pages' ] ) |
|||
end |
|||
end |
end |
||
end |
end |
||
Revision as of 00:21, 6 February 2024
This documentation is transcluded from Module:Navplate/Manufacturers/doc. Changes can be proposed in the talk page.
Module:Navplate/Manufacturers is shared across the Star Citizen Wikis.
This module is shared across the Star Citizen Wikis. Any changes should also be relayed to the GitHub repository.
This module is unused.
This module is neither invoked by a template nor required/loaded by another module. If this is in error, make sure to add
{{Documentation}}
/{{No documentation}}
to the calling template's or parent's module documentation.Function list |
---|
-- This is barebone but the idea is to make a generic module that
-- build any navplate from template defined from data.json
--
-- TODO:
-- - Make functions generic
-- - Support more SMW inline query conditions other than category
-- - Implement i18n
-- - Support group headers
-- - Support icon
local NavplateManufacturers = {}
local metatable = {}
local methodtable = {}
metatable.__index = methodtable
local common = require( 'Module:Common' )
local navplate = require( 'Module:Navplate' )
local template = mw.loadJsonData( 'Module:Navplate/Manufacturers/data.json' );
--- Queries the SMW Store
--- @return table
function methodtable.getSmwData( self, category )
-- Cache multiple calls
if self.smwData ~= nil then
return self.smwData
end
local askData = {
'[[:+]]',
'[[' .. self.category .. ']]',
'?#-=page',
'?Category#'
}
local data = mw.smw.ask( askData )
if data == nil or data[ 1 ] == nil then
return nil
end
--mw.logObject( data )
-- Init self.smwData
if self.smwData == nil then
self.smwData = {}
end
self.smwData = data
return self.smwData
end
--- Build a table of data that represents the navplate from SMW data based on the template
---
--- @return table
function methodtable.buildNavplateData( self, data )
local navplateData = {}
-- Lua tables has no concept of order, need to iterate it manually
local i = 1
for _, navplateRow in pairs( template[ 'content' ] ) do
local label = navplateRow[ 'label' ]
for _, result in pairs( data ) do
-- Match category
local categories = result[ 'Category' ]
if categories ~= nil and type( categories ) == 'table' then
for _, category in pairs( categories ) do
if category == navplateRow[ 'conditions' ] then
-- Create row if it does not exist already
if navplateData[ i ] == nil then
navplateData[ i ] = {
label = label,
pages = {}
}
end
table.insert( navplateData[ i ][ 'pages' ], result[ 'page' ] )
end
end
end
end
if navplateData[ i ] ~= nil then
i = i + 1
end
end
return navplateData
end
--- Outputs the table
---
--- @return string
function methodtable.make( self )
local args = {
subtitle = 'Products of',
title = 'Manufacturer'
}
local data = self:getSmwData( self.category )
if data ~= nil then
local navplateData = self:buildNavplateData( data )
mw.logObject( navplateData )
if navplateData ~= nil then
for i, row in ipairs( navplateData ) do
args[ 'label' .. i ] = row[ 'label' ]
args[ 'list' .. i ] = table.concat( row[ 'pages' ] )
end
end
end
-- mw.logObject( args )
return navplate.navplateTemplate({
args = args
})
end
--- New Instance
---
--- @return table NavplateManufacturers
function NavplateManufacturers.new( self, frameArgs )
local instance = {
category = 'Category:Greycat Industrial'
}
setmetatable( instance, metatable )
return instance
end
--- "Main" entry point
---
--- @param frame table Invocation frame
--- @return string
function NavplateManufacturers.main( frame )
local instance = NavplateManufacturers:new()
return instance:make()
end
return NavplateManufacturers