Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lua/spec/standings_model_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,32 @@ describe('Standings model round trip', function()
GoldenTest('standings_ffa', html)
end)

it('direct-path render matches var-path render', function()
local StandingsDisplay = require('Module:Widget/Standings')

local rounds = {
{roundNumber = 1, started = true, finished = true, title = 'Day 1'},
{roundNumber = 2, started = true, finished = true, title = 'Day 2'},
}
local opponents = {
makeOpponent('Alpha', {3, 0}),
makeOpponent('Bravo', {1, 4}),
makeOpponent('Charlie', {0, 1}),
}
local standingsTable = StandingsParser.parse(
rounds, opponents, {[1] = 'up', [3] = 'down'}, 'Dir Standings', {}, 'ffa', {'full.points'})

-- Direct path: use the returned record/entries from StandingsStorage.run
local stored = StandingsStorage.run(standingsTable, {saveVars = true})
local directModel = Standings.standingsFromRecord(stored.record, stored.entries)
local htmlDirect = tostring(StandingsDisplay{standings = directModel})

-- Var path: read back from page variables (the same wiki-var write)
local htmlVar = tostring(StandingsDisplay{pageName = 'FakePage', standingsIndex = standingsTable.standingsindex})

assert.are_equal(htmlDirect, htmlVar)
end)

it('renders the swiss standings widget from the model', function()
local SwissStandings = require('Module:Widget/Standings/Swiss')

Expand Down
14 changes: 12 additions & 2 deletions lua/wikis/commons/Standings/Storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,22 @@ function StandingsStorage.run(data, options)
return StandingsStorage.entry(entry, data.standingsindex)
end)

local storageTable = StandingsStorage.table(data)

if StandingsStorage.shouldStoreLpdb() then
StandingsStorage.saveLpdb(StandingsStorage.table(data), entries)
StandingsStorage.saveLpdb(storageTable, entries)
end
if options and options.saveVars then
StandingsStorage.saveVars(StandingsStorage.table(data), entries)
StandingsStorage.saveVars(storageTable, entries)
end

-- Return the record in model-ready form (matches as a table, not a JSON string)
-- so callers on the producing page can skip the var round-trip.
local directRecord = Table.merge(storageTable, {
pagename = mw.title.getCurrentTitle().text,
matches = data.matches or {},
})
return {record = directRecord, entries = entries}
end

---@param data table
Expand Down
6 changes: 4 additions & 2 deletions lua/wikis/commons/Standings/Table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local StandingsParseLpdb = Lua.import('Module:Standings/Parse/Lpdb')
local StandingsParser = Lua.import('Module:Standings/Parser')
local StandingsStorage = Lua.import('Module:Standings/Storage')

local Standings = Lua.import('Module:Standings')
local StandingsDisplay = Lua.import('Module:Widget/Standings')

local Opponent = Lua.import('Module:Opponent/Custom')
Expand Down Expand Up @@ -69,8 +70,9 @@ function StandingsTable.fromTemplate(frame)
standingsTable.extradata.placemapping = Logic.wrapTryOrLog(StandingsParseWiki.parsePlaceMapping)(args, opponents)
end

StandingsStorage.run(standingsTable, {saveVars = true})
return StandingsDisplay{pageName = mw.title.getCurrentTitle().text, standingsIndex = standingsTable.standingsindex}
local stored = StandingsStorage.run(standingsTable, {saveVars = true})
local model = Standings.standingsFromRecord(stored.record, stored.entries)
return StandingsDisplay{standings = model}
end

---@param manualOpponents StandingTableOpponentData[]
Expand Down
9 changes: 7 additions & 2 deletions lua/wikis/commons/Widget/Standings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ local SwissStandings = Lua.import('Module:Widget/Standings/Swiss')
local Standings = Lua.import('Module:Standings')
local StringUtils = Lua.import('Module:StringUtils')

---@param props {pageName: string, standingsIndex: integer?}
---@param props {pageName: string?, standingsIndex: integer?, standings: StandingsModel?}
---@return VNode?
local function StandingsWidget(props)
local standings = Standings.getStandingsTable(props.pageName, props.standingsIndex)
local standings
if props.standings then
standings = props.standings
else
standings = Standings.getStandingsTable(props.pageName, props.standingsIndex)
end
if not standings then
return
end
Expand Down
Loading