Skip to content
Closed
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
10 changes: 9 additions & 1 deletion lua/spec/prize_pool_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ describe('prize pool', function()

assert.are_same(
{
{id = 'BASE_CURRENCY1', type = 'BASE_CURRENCY', index = 1, data = {roundPrecision = 3}},
{
id = 'BASE_CURRENCY1',
type = 'BASE_CURRENCY',
index = 1,
data = {
roundPrecision = 3,
currency = 'USD',
}
},
{
id = 'LOCAL_CURRENCY1',
type = 'LOCAL_CURRENCY',
Expand Down
Binary file modified lua/spec/snapshots/prize_pool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 28 additions & 48 deletions lua/wikis/commons/PrizePool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ local Placement = Lua.import('Module:PrizePool/Placement')

local Opponent = Lua.import('Module:Opponent/Custom')

local Widgets = Lua.import('Module:Widget/All')
local Div = Widgets.Div
local IconFa = Lua.import('Module:Widget/Image/Icon/Fontawesome')
local TableRow = Widgets.TableRow
local TableCell = Widgets.TableCell
local ChevronToggle = Lua.import('Module:Widget/GeneralCollapsible/ChevronToggle')
local Html = Lua.import('Module:Widget/Html')
local Div = Html.Div
local Label = Lua.import('Module:Widget/Basic/Label')
local PrizePoolCell = Lua.import('Module:Widget/PrizePool/Cell')

---@class PrizePool: BasePrizePool
---@operator call(...): PrizePool
---@field placements PrizePoolPlacement[]
local PrizePool = Class.new(BasePrizePool)

local NON_BREAKING_SPACE = ' '

---@param args table
function PrizePool:readPlacements(args)
local currentPlace = 0
Expand All @@ -52,16 +50,17 @@ function PrizePool:readPlacements(args)
end

---@param placement PrizePoolPlacement
---@return WidgetTableCell
---@return VNode
function PrizePool:placeOrAwardCell(placement)
local placeCell = TableCell{
children = {placement:getMedal() or '', NON_BREAKING_SPACE, placement:_displayPlace()},
css = {['font-weight'] = 'bolder'},
classes = {'prizepooltable-place'},
local placementDisplay = placement:_lpdbValue()

return PrizePoolCell{
children = Label{
labelScheme = 'prize-pool-placement',
children = placementDisplay
},
fullHeight = true,
}
placeCell.rowSpan = #placement.opponents

return placeCell
end

---@param placement PrizePoolPlacement
Expand All @@ -79,24 +78,14 @@ function PrizePool:applyCutAfter(placement)
return false
end

---@param placement PrizePoolPlacement?
---@param nextPlacement PrizePoolPlacement
---@param rows WidgetTableRow[]
function PrizePool:applyToggleExpand(placement, nextPlacement, rows)
if placement ~= nil
and placement.placeStart <= self.options.cutafter
and placement.placeEnd >= self.options.cutafter
and placement ~= self.placements[#self.placements]
and nextPlacement.placeStart ~= placement.placeStart
and nextPlacement.placeEnd ~= placement.placeEnd then

table.insert(rows, self:_toggleExpand(placement.placeEnd + 1))
---@return VNode?
function PrizePool:getCollapsibleToggle()
local placeStart = Array.find(self.placements, function (placement)
return placement.placeStart > self.options.cutafter
end)
if not placeStart then
return
end
end

---@param placeStart number
---@return WidgetTableRow
function PrizePool:_toggleExpand(placeStart)
local placeEnd = self.placements[#self.placements].placeEnd

if self.options.hideafter < math.huge then
Expand All @@ -109,25 +98,16 @@ function PrizePool:_toggleExpand(placeStart)
placeEnd = lastCut.placeEnd
end

local text = 'place ' .. placeStart .. ' to ' .. placeEnd
local expandButton = TableCell{
children = Div{children = {
text,
'&nbsp;',
IconFa{iconName = 'expand'},
}},
classes = {'general-collapsible-expand-button'},
}
local collapseButton = TableCell{
local text = 'place ' .. placeStart.placeStart .. ' to ' .. placeEnd

return Div{
classes = {'prize-pool-toggle'},
attributes = {['data-collapsible-click-region'] = 'true'},
children = Div{children = {
text,
'&nbsp;',
IconFa{iconName = 'collapse'},
}},
classes = {'general-collapsible-collapse-button'},
ChevronToggle{}
}}
}

return TableRow{classes = {'ppt-toggle-expand'}, children = {expandButton, collapseButton}}
end

-- get the lpdbObjectName depending on opponenttype
Expand Down
46 changes: 20 additions & 26 deletions lua/wikis/commons/PrizePool/Award.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ local Opponent = Lua.import('Module:Opponent/Custom')
local Widgets = Lua.import('Module:Widget/All')
local Div = Widgets.Div
local IconFa = Lua.import('Module:Widget/Image/Icon/Fontawesome')
local TableRow = Widgets.TableRow
local TableCell = Widgets.TableCell
local PrizePoolCell = Lua.import('Module:Widget/PrizePool/Cell')

--- @class AwardPrizePool: BasePrizePool
--- @operator call(...): AwardPrizePool
--- @field placements AwardPlacement[]
local AwardPrizePool = Class.new(BasePrizePool)

---@param args table
Expand Down Expand Up @@ -52,12 +52,12 @@ end
---@param placement AwardPlacement
---@return WidgetTableCell
function AwardPrizePool:placeOrAwardCell(placement)
local awardCell = TableCell{
local awardCell = PrizePoolCell{
children = {placement.award},
css = {['font-weight'] = 'bolder'},
classes = {'prizepooltable-place'},
height = #placement.opponents,
}
awardCell.rowSpan = #placement.opponents

return awardCell
end
Expand All @@ -71,37 +71,31 @@ function AwardPrizePool:applyCutAfter(placement)
return false
end

---@param placement AwardPlacement?
---@param nextPlacement AwardPlacement
---@param rows WidgetTableRow[]
function AwardPrizePool:applyToggleExpand(placement, nextPlacement, rows)
if placement ~= nil
and (placement.previousTotalNumberOfParticipants + 1) <= self.options.cutafter
and placement.currentTotalNumberOfParticipants >= self.options.cutafter
and placement ~= self.placements[#self.placements] then

table.insert(rows, self:_toggleExpand())
end
end

---@return WidgetTableRow
function AwardPrizePool:_toggleExpand()
local expandButton = TableCell{
children = Div{children = {
---@return Renderable
function AwardPrizePool:getCollapsibleToggle()
local expandButton = Div{
children = {
'Show more Awards&nbsp;',
IconFa{iconName = 'expand'},
}},
},
classes = {'general-collapsible-expand-button'},
}
local collapseButton = TableCell{
children = Div{children = {
local collapseButton = Div{
children = {
'Show less Awards&nbsp;',
IconFa{iconName = 'collapse'},
}},
},
classes = {'general-collapsible-collapse-button'},
}

return TableRow{classes = {'ppt-toggle-expand'}, children = {expandButton, collapseButton}}
return Div{
classes = {'prize-pool-toggle'},
attributes = {['data-collapsible-click-region'] = 'true'},
children = Div{
classes = {'general-collapsible-default-toggle'},
children = {expandButton, collapseButton}
}
}
end

-- Get the lpdbObjectName depending on opponenttype
Expand Down
1 change: 1 addition & 0 deletions lua/wikis/commons/PrizePool/Award/Placement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function AwardPlacement:_getLpdbData(...)
end

-- No BG for awards
---@return string?
function AwardPlacement:getBackground()
return
end
Expand Down
Loading