Content deleted Content added
Alistair3149 (talk | contribs) No edit summary |
Alistair3149 (talk | contribs) No edit summary |
||
Line 4: | Line 4: | ||
-- TODO: |
-- TODO: |
||
-- - Make functions generic |
-- - Make functions generic |
||
-- - Support multiple conditions |
|||
-- - Support more SMW inline query conditions other than category |
-- - Support more SMW inline query conditions other than category |
||
-- - Implement i18n |
-- - Implement i18n |
||
Line 19: | Line 20: | ||
local navplate = require( 'Module:Navplate' ) |
local navplate = require( 'Module:Navplate' ) |
||
local template = mw.loadJsonData( 'Module:Navplate/Manufacturers/data.json' ); |
local template = mw.loadJsonData( 'Module:Navplate/Manufacturers/data.json' ); |
||
local mfu = require( 'Module:Manufacturer' )._manufacturer |
|||
--- Queries the SMW Store |
--- Queries the SMW Store |
||
--- @param string conditions for SMW query |
|||
--- @return table |
--- @return table |
||
function methodtable.getSmwData( self, |
function methodtable.getSmwData( self, conditions ) |
||
-- Cache multiple calls |
-- Cache multiple calls |
||
if self.smwData ~= nil then |
if self.smwData ~= nil then |
||
Line 30: | Line 33: | ||
local askData = { |
local askData = { |
||
'[[:+]]', |
'[[:+]]', |
||
'[[' .. |
'[[' .. conditions .. ']]', |
||
'?#-=page', |
'?#-=page', |
||
'?Category#' |
'?Category#' |
||
Line 65: | Line 68: | ||
local conditions = navplateRow[ 'conditions' ] |
local conditions = navplateRow[ 'conditions' ] |
||
if conditions ~= nil then |
|||
for _, result in pairs( data ) do |
for _, result in pairs( data ) do |
||
-- Match category |
-- Match category |
||
local categories = result[ 'Category' ] |
|||
local categories = result[ 'Category' ] |
|||
if categories ~= nil and type( categories ) == 'table' then |
|||
for _, category in pairs( categories ) do |
|||
if category == conditions then |
|||
-- Create row if it does not exist already |
|||
navplateData[ i ] = |
if navplateData[ i ] == nil then |
||
navplateData[ i ] = { |
|||
label = label, |
|||
} |
pages = {} |
||
} |
|||
end |
|||
⚫ | |||
end |
end |
||
⚫ | |||
end |
end |
||
end |
end |
||
Line 96: | Line 101: | ||
--- @return string |
--- @return string |
||
function methodtable.make( self ) |
function methodtable.make( self ) |
||
local manufacturer = mfu( self.frameArgs[ 1 ] ) and mfu( self.frameArgs[ 1 ] ).name or self.frameArgs[ 1 ] |
|||
if manufacturer == nil then |
|||
local hatnote = require( 'Module:Hatnote' )._hatnote |
|||
return hatnote( |
|||
'Missing manufacturer parmeter', |
|||
{ icon = 'WikimediaUI-Error.svg' } |
|||
) |
|||
end |
|||
local args = { |
local args = { |
||
subtitle = 'Products of', |
subtitle = 'Products of', |
||
title = |
title = manufacturer |
||
} |
} |
||
local |
local conditions = 'Category:' .. manufacturer |
||
local data = self:getSmwData( conditions ) |
|||
if data ~= nil then |
if data ~= nil then |
||
local navplateData = self:buildNavplateData( data ) |
local navplateData = self:buildNavplateData( data ) |
||
Line 120: | Line 137: | ||
args = args |
args = args |
||
}) |
}) |
||
end |
|||
--- Set the frame and load args |
|||
--- @param frame table |
|||
function methodtable.setFrame( self, frame ) |
|||
self.currentFrame = frame |
|||
self.frameArgs = require( 'Module:Arguments' ).getArgs( frame ) |
|||
end |
end |
||
Line 125: | Line 149: | ||
--- |
--- |
||
--- @return table NavplateManufacturers |
--- @return table NavplateManufacturers |
||
function NavplateManufacturers.new( self |
function NavplateManufacturers.new( self ) |
||
local instance = { |
local instance = {} |
||
category = 'Category:Greycat Industrial' |
|||
} |
|||
setmetatable( instance, metatable ) |
setmetatable( instance, metatable ) |
||
return instance |
return instance |
||
end |
end |
||
Line 140: | Line 164: | ||
function NavplateManufacturers.main( frame ) |
function NavplateManufacturers.main( frame ) |
||
local instance = NavplateManufacturers:new() |
local instance = NavplateManufacturers:new() |
||
instance:setFrame( frame ) |
|||
return instance:make() |
return instance:make() |
Revision as of 00:59, 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 multiple conditions
-- - 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' );
local mfu = require( 'Module:Manufacturer' )._manufacturer
--- Queries the SMW Store
--- @param string conditions for SMW query
--- @return table
function methodtable.getSmwData( self, conditions )
-- Cache multiple calls
if self.smwData ~= nil then
return self.smwData
end
local askData = {
'[[:+]]',
'[[' .. conditions .. ']]',
'?#-=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' ]
local conditions = navplateRow[ 'conditions' ]
if conditions ~= nil then
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 == 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
end
if navplateData[ i ] ~= nil then
i = i + 1
end
end
return navplateData
end
--- Outputs the table
---
--- @return string
function methodtable.make( self )
local manufacturer = mfu( self.frameArgs[ 1 ] ) and mfu( self.frameArgs[ 1 ] ).name or self.frameArgs[ 1 ]
if manufacturer == nil then
local hatnote = require( 'Module:Hatnote' )._hatnote
return hatnote(
'Missing manufacturer parmeter',
{ icon = 'WikimediaUI-Error.svg' }
)
end
local args = {
subtitle = 'Products of',
title = manufacturer
}
local conditions = 'Category:' .. manufacturer
local data = self:getSmwData( conditions )
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' ]
-- Probably there is a cleaner way but it works :D
args[ 'list' .. i ] = '[[' .. table.concat( row[ 'pages' ], ']][[' ) .. ']]'
end
end
end
-- mw.logObject( args )
return navplate.navplateTemplate({
args = args
})
end
--- Set the frame and load args
--- @param frame table
function methodtable.setFrame( self, frame )
self.currentFrame = frame
self.frameArgs = require( 'Module:Arguments' ).getArgs( frame )
end
--- New Instance
---
--- @return table NavplateManufacturers
function NavplateManufacturers.new( self )
local instance = {}
setmetatable( instance, metatable )
return instance
end
--- "Main" entry point
---
--- @param frame table Invocation frame
--- @return string
function NavplateManufacturers.main( frame )
local instance = NavplateManufacturers:new()
instance:setFrame( frame )
return instance:make()
end
return NavplateManufacturers