Modul:PledgeVehicleGrid
Weitere Optionen
| Function list |
|---|
| L 75 — manufacturerEyebrow L 98 — flightReadyLabel L 292 — buildSpec L 311 — gridHtml L 359 — smwGrid L 398 — p.main |
Rendert die Pledge-Fahrzeugliste als sortierbare, filterbare Datentabelle. Auf diesem Wiki (SMW-Backend) läuft der Einstieg über eine SMW-Datentabellen-Abfrage mit deutschen Spaltenbeschriftungen (Modul:DataGrid/Smw); der AG-Grid-Pfad der englischen Schwester-Wiki läuft hier nicht (keine AG-Grid-Extension).
Für Editoren
Eine rufende Vorlage existiert auf diesem Wiki noch nicht; nach Anlage ruft sie p.main. Keine Parameter.
Jede Zeile kommt aus den gespeicherten Daten der Fahrzeugeiten selbst: ein Fahrzeug in die Pledge-Kategorie zu taggen und seine Infobox zu füllen genügt, damit es erscheint — kein Edit an diesem Modul. Die Abfrage läuft nicht bei jedem Aufruf: die Tabelle entsteht aus dem Stand beim letzten Speichern oder erzwungenen Re-Parse der Seite.
Für Modul-Editoren
API
buildSpec(): die BucketQuery-Spezifikation:kind = 'Vehicle', ein Entweder-Oder-Kategoriefilter, Deckellimit = 1000.COLUMNS: das deklarative Spaltenspec, eine Zeile pro Gridspalte;kindwählt den Renderer (card,stackedValue,badge,linkList,date, sonstnumber/text) — nur im Bucket-Zweig relevant.SMW_LABELS: die deutschen Spaltenköpfe des SMW-Renders, verschlüsselt nach demasder Spezifikation; ein fehlender Schlüssel fällt auf den nackten Printout, nie auf das englischeas.manufacturerEyebrow(result),flightReadyLabel(value): Karten-Eyebrow und Versionslabel-Kürzung für den Bucket-Zweig.p.main(frame): Einstieg. Auf SMW:DataGrid/Smw.rendermit den übersetzten Spalten; auf Bucket: der AG-Grid-Pfad.
Stolperfallen
- Auf SMW druckt die Tabelle die gespeicherten Felder ohne Karte, Bild, Badges und kombinierte Preise; das Verhalten der Zieldatentabelle und die Abfragelimits sind dort zu verifizieren.
- Ein leeres Ergebnis und ein Store-Fehlschlag sind beide hier enthalten und melden „keine Pledge-Fahrzeuge gespeichert“.
require('strict')
-- PledgeVehicleGrid: renders the List of pledge vehicles as an AG Grid via the
-- AGGrid extension. Sources every pledge vehicle from Bucket (Module:BucketQuery),
-- reshapes the results into AG Grid rowData, and returns the grid: virtualised
-- rows, rich cells (linked names, thumbnails, loaner link-lists), REST-served data.
--
-- Rows come from Module:BucketQuery as typed values (numbers, bare page titles,
-- arrays for the loaner list), which the AGGridColumns kinds take as they are.
--
-- An empty result and a Store failure (rate limit, bad manifest) are both
-- contained here and reported as "no pledge vehicles stored": Bucket's
-- per-user API limiter also answers empty when throttled, so on a live
-- article that message can mean a transient rate limit rather than missing
-- data.
local aggrid
local Util
local bucketQuery = require('Module:BucketQuery')
local p = {}
-- Source width in px for the manufacturer brand glyph in the card eyebrow.
local GLYPH_WIDTH = 40
-- Manufacturer display name -> { code, short }, from the maintained
-- Module:Manufacturers/data.json (keyed CODE -> { name, short }). `code` resolves
-- the brand glyph (File:Sc-icon-brand-<code>.svg); `short` is the compact label
-- shown in the card eyebrow. Built once at module load.
local MANUFACTURER = {}
do
local ok, data = pcall(mw.loadJsonData, 'Module:Manufacturers/data.json')
if ok and type(data) == 'table' then
for code, entry in pairs(data) do
if type(entry) == 'table' and entry.name then
MANUFACTURER[entry.name] = { code = tostring(code):lower(), short = entry.short }
end
end
end
end
-- Numeric display formats. The extension applies these client-side via Intl on
-- the real number, so the underlying value (and thus sort / filter / set-filter
-- / CSV export) stays numeric -- only the rendered text gains grouping and a
-- unit. `style` is always 'number'; `useGrouping` defaults to true, so thousands
-- separators come for free. Decimals are left unset to preserve each value's
-- natural precision.
local FMT_AUEC = { style = 'number', suffix = ' aUEC' } -- in-game currency
local FMT_USCU = { style = 'number', suffix = ' µSCU' } -- personal inventory / storage capacity
local FMT_METERS = { style = 'number', suffix = ' m' }
local FMT_KG = { style = 'number', suffix = ' kg' }
local FMT_SCU = { style = 'number', suffix = ' SCU' }
local FMT_SPEED = { style = 'number', suffix = ' m/s' }
local FMT_RATE = { style = 'number', suffix = ' °/s' }
-- Production state -> BadgeLua variant. Flight ready is done (success); active /
-- long-term production is in progress (warning); concept is not yet flyable
-- (error). SQ42-only and any unmapped state get the neutral base badge.
-- The SMW grid path Germanizes vocab values before cells build, so the
-- stored-German spellings join the English keys.
local PRODUCTION_VARIANT = {
['Flight ready'] = 'success',
['Flugbereit'] = 'success',
['Active production'] = 'warning',
['Aktive Produktion'] = 'warning',
['Long term production'] = 'warning',
['Langzeit Produktion'] = 'warning',
['In concept'] = 'error',
['Im Konzept'] = 'error',
}
-- Eyebrow resolver for the vehicle card: the manufacturer's short name + brand
-- glyph, read from the row's Manufacturer page value. Consumer-specific
-- (the card kind itself stays generic). Returns nil when there's no manufacturer.
local function manufacturerEyebrow(result)
local mfrTarget, mfrDisplay = Util.pageTarget(result['Manufacturer'])
if not mfrTarget then
return nil
end
local mfrName = mfrDisplay or mfrTarget
local info = MANUFACTURER[mfrName]
local mfrLink = aggrid.link(mfrTarget, mfrName)
local eyebrow = {
text = (info and info.short) or mfrName,
full = mfrName,
href = mfrLink and mfrLink.href,
}
if info and info.code then
eyebrow.icon = aggrid.thumb('File:Sc-icon-brand-' .. info.code .. '.svg', GLYPH_WIDTH)
end
return eyebrow
end
-- "Added in version" is a page reference (the canonical Update: patch). This is a
-- vehicle-only grid, so the column shows just the version label: strip the
-- "Update:Star Citizen " / "Star Citizen " prefix the page value carries
-- ("Update:Star Citizen Alpha 3.24.3" -> "Alpha 3.24.3"). nil when absent.
local function flightReadyLabel(value)
Util = Util or require('Module:AGGridColumns/Util')
local target = Util.pageTarget(value)
if not target or target == '' then
return nil
end
return (target:gsub('^Update:', ''):gsub('^Star Citizen ', ''))
end
local COLUMNS = {
{
field = 'vehicle',
header = 'Vehicle',
kind = 'card',
titleLabel = 'Name',
imageLabel = 'Image',
displayLabel = 'DisplayName',
eyebrow = manufacturerEyebrow,
eyebrowHeader = 'Manufacturer',
filter = 'aggridSet',
width = 300,
},
{ field = 'type', header = 'Type', kind = 'text', label = 'Type', filter = 'aggridSet', width = 130 },
{ field = 'career', header = 'Career', kind = 'text', label = 'Career', filter = 'aggridSet', width = 110 },
-- Role is a repeated Bucket field: a valueList renders each role and lets the
-- set filter offer them separately, the same shape RentalVehicleGrid uses.
{ field = 'role', header = 'Role', kind = 'valueList', label = 'Role', filter = 'aggridSet', width = 180 },
{ field = 'size', header = 'Size', kind = 'number', label = 'Size', filter = 'aggridSet', width = 80 },
{
field = 'storeSize',
header = 'Store size',
kind = 'text',
label = 'Store size',
filter = 'aggridSet',
width = 100,
},
{
field = 'production',
header = 'Production state',
kind = 'badge',
label = 'Production state',
variants = PRODUCTION_VARIANT,
filter = 'aggridSet',
width = 200,
},
{
field = 'availability',
header = 'Pledge availability',
kind = 'text',
label = 'Pledge availability',
filter = 'aggridSet',
width = 140,
},
{
field = 'pledge',
header = 'Pledge',
kind = 'stackedValue',
curLabel = 'Pledge',
origLabel = 'Orig pledge',
origHeader = 'Original pledge',
width = 90,
},
{
field = 'warbond',
header = 'Warbond',
kind = 'stackedValue',
curLabel = 'Warbond',
origLabel = 'Orig warbond',
origHeader = 'Original warbond',
width = 90,
},
{ field = 'loaner', header = 'Loaner', kind = 'linkList', label = 'Loaner', width = 160 },
{
field = 'avgPrice',
header = 'Avg purchase',
kind = 'number',
label = 'Avg purchase',
format = FMT_AUEC,
width = 105,
},
{
field = 'avgRental',
header = 'Avg daily rental',
kind = 'number',
label = 'Avg daily rental',
format = FMT_AUEC,
width = 105,
},
{ field = 'length', header = 'Length', kind = 'number', label = 'Length', format = FMT_METERS, width = 80 },
{ field = 'width', header = 'Width', kind = 'number', label = 'Width', format = FMT_METERS, width = 80 },
{ field = 'height', header = 'Height', kind = 'number', label = 'Height', format = FMT_METERS, width = 80 },
{ field = 'mass', header = 'Mass', kind = 'number', label = 'Mass', format = FMT_KG, width = 90 },
{ field = 'minCrew', header = 'Min crew', kind = 'number', label = 'Min crew', width = 80 },
{ field = 'maxCrew', header = 'Max crew', kind = 'number', label = 'Max crew', width = 80 },
{ field = 'inventory', header = 'Inventory', kind = 'number', label = 'Inventory', format = FMT_USCU, width = 110 },
{ field = 'cargo', header = 'Cargo', kind = 'number', label = 'Cargo', format = FMT_SCU, width = 80 },
{ field = 'scm', header = 'SCM speed', kind = 'number', label = 'SCM speed', format = FMT_SPEED, width = 85 },
{ field = 'maxSpeed', header = 'Max speed', kind = 'number', label = 'Max speed', format = FMT_SPEED, width = 90 },
{ field = 'roll', header = 'Roll', kind = 'number', label = 'Roll', format = FMT_RATE, width = 75 },
{ field = 'pitch', header = 'Pitch', kind = 'number', label = 'Pitch', format = FMT_RATE, width = 75 },
{ field = 'yaw', header = 'Yaw', kind = 'number', label = 'Yaw', format = FMT_RATE, width = 75 },
{ field = 'conceptDate', header = 'Concept date', kind = 'date', label = 'Concept date' },
{
field = 'flightReady',
header = 'Flight ready',
kind = 'text',
label = 'Flight ready',
filter = 'aggridSet',
width = 110,
},
}
-- One Store column per grid label; the label is the result key the column
-- kinds read, so the COLUMNS table above is unchanged. DisplayName backs the
-- card's displayLabel: Store's page_name builtin is the bare title and does
-- not carry a page's {{DISPLAYTITLE}}.
local SPEC_COLUMNS = {
{ builtin = 'page_name', as = 'Name' },
{ property = 'Name', as = 'DisplayName' },
{ property = 'Image', as = 'Image' },
{ property = 'Manufacturer', as = 'Manufacturer' },
{ property = 'Subject type', as = 'Type' },
{ property = 'Career', as = 'Career' },
{ property = 'Role', as = 'Role' },
{ property = 'Size', as = 'Size' },
{ property = 'Ship matrix size', as = 'Store size' },
{ property = 'Production state', as = 'Production state' },
{ property = 'Pledge availability', as = 'Pledge availability' },
{ property = 'Pledge price', as = 'Pledge' },
{ property = 'Original pledge price', as = 'Orig pledge' },
{ property = 'Warbond pledge price', as = 'Warbond' },
{ property = 'Original warbond pledge price', as = 'Orig warbond' },
{ property = 'Loaner vehicle', as = 'Loaner' },
{ property = 'Average purchase price', as = 'Avg purchase' },
{ property = 'Average rental price', as = 'Avg daily rental' },
{ property = 'Entity length', as = 'Length' },
{ property = 'Entity width', as = 'Width' },
{ property = 'Entity height', as = 'Height' },
{ property = 'Mass', as = 'Mass' },
{ property = 'Minimum crew', as = 'Min crew' },
{ property = 'Maximum crew', as = 'Max crew' },
{ property = 'Storage capacity', as = 'Inventory' },
{ property = 'Cargo capacity', as = 'Cargo' },
{ property = 'Scm speed', as = 'SCM speed' },
{ property = 'Max speed', as = 'Max speed' },
{ property = 'Roll rate', as = 'Roll' },
{ property = 'Pitch rate', as = 'Pitch' },
{ property = 'Yaw rate', as = 'Yaw' },
{ property = 'Concept announcement date', as = 'Concept date' },
{ property = 'Added in version', as = 'Flight ready' },
}
-- German display headers for the SMW grid, keyed by the grid column's English
-- header (the spec column's `as`). Terms follow the crosswalk's German
-- property names, so the grid captions and the stored properties read the
-- same vocabulary. A missing key falls back to the English header, which the
-- header pinning test rejects.
local SMW_HEADER = {
Vehicle = 'Fahrzeug',
Type = 'Strukturtyp',
Career = 'Karriere',
Role = 'Fokus',
Size = 'Größe',
['Store size'] = 'Ship Matrix Größe',
['Production state'] = 'Produktionsstatus',
['Pledge availability'] = 'Pledge Verfügbarkeit',
Pledge = 'Schiffspreis',
Warbond = 'Warbond Pledgepreis',
Loaner = 'Leihfahrzeug',
['Avg purchase'] = 'Durchschnittlicher Kaufpreis',
['Avg daily rental'] = 'Durchschnittlicher Mietpreis',
Length = 'Länge',
Width = 'Breite',
Height = 'Höhe',
Mass = 'Gewicht',
['Min crew'] = 'Minimalbesatzung',
['Max crew'] = 'Maximalbesatzung',
Inventory = 'Inventar',
Cargo = 'Frachtkapazität',
['SCM speed'] = 'Kampfgeschwindigkeit',
['Max speed'] = 'Maximalgeschwindigkeit',
Roll = 'Rollen',
Pitch = 'Neigen',
Yaw = 'Gieren',
['Concept date'] = 'Ankündigungsdatum',
['Flight ready'] = 'Flugbereit seit',
}
--- Build the query spec. `typeFilter`, when given, is one extra Store filter
--- constraining Strukturtyp (the German wiki's hubs split the same pledge grid
--- by subject type: Raumschiffe unscoped, Fahrzeuge on Bodenfahrzeug +
--- Gravlev-Fahrzeug).
--- @param typeFilter table|nil a parseFilters filter entry
--- @return table
local function buildSpec(typeFilter)
local filters = { { any = { 'Category:Pledge Raumschiff', 'Category:Pledge Bodenfahrzeug' } } }
if typeFilter then
filters[#filters + 1] = typeFilter
end
return {
kind = 'Vehicle',
filters = filters,
columns = SPEC_COLUMNS,
limit = 1000,
}
end
--- Render the grid over prepared results. One options table serves both
--- backends: they differ only in where the rows came from and which header
--- language they carry.
--- @param results table[]
--- @param columns table[] AGGridColumns column specs (COLUMNS, or its Germanized copy)
--- @return string
local function gridHtml(results, columns)
local AGGridColumns = require('Module:AGGridColumns')
Util = Util or require('Module:AGGridColumns/Util')
aggrid = aggrid or require('mw.ext.aggrid')
-- Pre-clean the "Added in version" Page value to a bare version label for the
-- "Flight ready" column (the text kind otherwise renders the full page title).
for _, result in ipairs(results) do
result['Flight ready'] = flightReadyLabel(result['Flight ready'])
end
local gridOptions = {
columnDefs = AGGridColumns.buildColumnDefs(columns),
rowData = AGGridColumns.buildRowData(results, columns),
-- Themed global search box wired to AG Grid's quick filter (client-side over
-- the loaded rows).
quickSearch = true,
-- Toolbar button that reopens the grid in a full-window modal, for the wide
-- column set.
expand = true,
csvExport = true,
defaultCsvExportParams = { allColumns = true },
-- No pagination: all vehicles in one virtualised, internally-scrolling
-- grid. Only the visible rows are ever in the DOM.
pagination = false,
-- Row height tuned to the card cell (thumbnail + two text lines).
rowHeight = 64,
-- Auto-size plain columns to their content. The custom-rendered columns
-- (card, stacked prices, badges) opt out via suppressAutoSize and use their `w`.
autoSizeStrategy = { type = 'fitCellContents' },
defaultColDef = {
sortable = true,
resizable = true,
},
}
local styles = mw.getCurrentFrame():extensionTag({
name = 'templatestyles',
args = { src = 'Module:PledgeVehicleGrid/styles.css' },
})
return styles .. '<div class="t-pledge-grid">' .. aggrid.render(gridOptions) .. '</div>'
end
--- The SMW path: Entity/Store's reader answers with the spec's `as` keys and
--- English machine tokens on vocab columns, so the rows take the same
--- Germanizing display pass {{Data table}} applies, and the headers read
--- SMW_HEADER instead of the Bucket wiki's English.
local function smwGrid(typeFilter)
local DataGrid = require('Module:DataGrid')
local results, queryErr = DataGrid.runQuery(buildSpec(typeFilter))
if queryErr then
return '<strong class="error">Module:PledgeVehicleGrid: ' .. tostring(queryErr) .. '</strong>'
end
if #results == 0 then
return '<strong class="error">Modul:PledgeVehicleGrid: keine Pledge-Fahrzeuge gespeichert.</strong>'
end
-- translateDisplay keys on column.label, the result key: the spec's `as`.
local vocabColumns = {}
for _, col in ipairs(SPEC_COLUMNS) do
if col.property then
vocabColumns[#vocabColumns + 1] = { property = col.property, label = col.as }
end
end
DataGrid.translateDisplay(results, vocabColumns, 'Vehicle')
local columns = {}
for _, col in ipairs(COLUMNS) do
local german = {}
for key, value in pairs(col) do
german[key] = value
end
german.header = SMW_HEADER[col.header] or col.header
if col.eyebrowHeader then
german.eyebrowHeader = 'Hersteller'
end
if col.origHeader then
german.origHeader = col.field == 'pledge' and 'Ursprünglicher Schiffspreis'
or 'Ursprünglicher Warbond Pledgepreis'
end
columns[#columns + 1] = german
end
return gridHtml(results, columns)
end
--- Entry point. Renders the pledge-vehicle grid.
--- @param frame mw.frame
--- @return string
function p.main(frame)
local backend = require('Module:Entity/StructuredData').backend()
-- `typ` narrows the grid to the named Strukturtyp values, ;-separated
-- ({{PledgeVehicleGrid|typ=Bodenfahrzeug; Gravlev-Fahrzeug}}). The pledge
-- category scope stays fixed.
local typeFilter = nil
-- A real #invoke frame's getParent needs the colon call; the test doubles
-- expose it as a plain closure field, which ignores the extra self.
local args = frame and type(frame.getParent) == 'function' and frame:getParent().args or {}
local raw = mw.text.trim(tostring(args.typ or ''))
if raw ~= '' then
local filters, err = require('Module:DataGrid').parseFilters('Strukturtyp = ' .. raw)
if err or not filters or #filters ~= 1 then
return '<strong class="error">Modul:PledgeVehicleGrid: ungültiger typ-Parameter: '
.. mw.html.escape(raw)
.. '</strong>'
end
typeFilter = filters[1]
end
if backend == 'smw' then
return smwGrid(typeFilter)
elseif backend ~= 'bucket' then
error('Unknown structured-data backend: ' .. tostring(backend))
end
local ok, results = pcall(bucketQuery.query, buildSpec(typeFilter))
if not ok or #results == 0 then
return '<strong class="error">Module:PledgeVehicleGrid: no pledge vehicles stored.</strong>'
end
return gridHtml(results, COLUMNS)
end
-- Test-only exports. Not part of the public API.
p._internal = { buildSpec = buildSpec, flightReadyLabel = flightReadyLabel, columns = COLUMNS, smwHeader = SMW_HEADER }
return p


