diff --git a/lua/wikis/commons/TeamParticipants/Controller.lua b/lua/wikis/commons/TeamParticipants/Controller.lua index f61ca2a7f8a..ff476e3290c 100644 --- a/lua/wikis/commons/TeamParticipants/Controller.lua +++ b/lua/wikis/commons/TeamParticipants/Controller.lua @@ -44,7 +44,9 @@ function TeamParticipantsController.fromTemplate(frame) end Array.forEach(parsedData.participants, TeamParticipantsRepository.setPageVars) return TeamParticipantsDisplay{ - participants = parsedData.participants + participants = parsedData.participants, + -- only allow true to disallow input from wiki + suppressSwitch = args.suppressSwitch == true, } end diff --git a/lua/wikis/commons/Widget/Participants/Team/CardsGroup.lua b/lua/wikis/commons/Widget/Participants/Team/CardsGroup.lua index cbcde9019ca..b03101a5182 100644 --- a/lua/wikis/commons/Widget/Participants/Team/CardsGroup.lua +++ b/lua/wikis/commons/Widget/Participants/Team/CardsGroup.lua @@ -15,7 +15,8 @@ local AnalyticsWidget = Lua.import('Module:Widget/Analytics') local HtmlWidgets = Lua.import('Module:Widget/Html/All') local Div = HtmlWidgets.Div local ParticipantsTeamCard = Lua.import('Module:Widget/Participants/Team/Card') -local Switch = Lua.import('Module:Widget/Switch') +local ParticipantsTeamCardSwitch = Lua.import('Module:Widget/Participants/Team/Switch') +local WidgetUtil = Lua.import('Module:Widget/Util') ---@class ParticipantsTeamCardsGroup: Widget ---@operator call(table): ParticipantsTeamCardsGroup @@ -30,35 +31,8 @@ function ParticipantsTeamCardsGroup:render() return Div{ classes = { 'team-participant' }, - children = { - Div{ - classes = { 'team-participant__switches' }, - children = { - AnalyticsWidget{ - analyticsName = 'ParticipantsShowRostersSwitch', - analyticsProperties = { - ['track-value-as'] = 'participants show rosters', - }, - children = Switch{ - label = 'Show rosters', - switchGroup = 'team-cards-show-rosters', - defaultActive = false, - collapsibleSelector = '.team-participant-card', - }, - }, - AnalyticsWidget{ - analyticsName = 'ParticipantsCompactSwitch', - analyticsProperties = { - ['track-value-as'] = 'participants compact', - }, - children = Switch{ - label = 'Compact view', - switchGroup = 'team-cards-compact', - defaultActive = true, - }, - } - } - }, + children = WidgetUtil.collect( + (not self.props.suppressSwitch) and ParticipantsTeamCardSwitch() or nil, AnalyticsWidget{ analyticsName = 'Team participants card', children = Div{ @@ -70,7 +44,7 @@ function ParticipantsTeamCardsGroup:render() end), } } - } + ) } end diff --git a/lua/wikis/commons/Widget/Participants/Team/Switch.lua b/lua/wikis/commons/Widget/Participants/Team/Switch.lua new file mode 100644 index 00000000000..c21405f8a39 --- /dev/null +++ b/lua/wikis/commons/Widget/Participants/Team/Switch.lua @@ -0,0 +1,54 @@ +--- +-- @Liquipedia +-- page=Module:Widget/Participants/Team/Switch +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Lua = require('Module:Lua') + +local Class = Lua.import('Module:Class') + +local Widget = Lua.import('Module:Widget') +local AnalyticsWidget = Lua.import('Module:Widget/Analytics') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local Div = HtmlWidgets.Div +local Switch = Lua.import('Module:Widget/Switch') + +---@class ParticipantsTeamCardsGroupSwitch: Widget +---@operator call(): ParticipantsTeamCardsGroupSwitch +local ParticipantsTeamCardsGroupSwitch = Class.new(Widget) + +---@return Widget? +function ParticipantsTeamCardsGroupSwitch:render() + return Div{ + classes = { 'team-participant__switches' }, + children = { + AnalyticsWidget{ + analyticsName = 'ParticipantsShowRostersSwitch', + analyticsProperties = { + ['track-value-as'] = 'participants show rosters', + }, + children = Switch{ + label = 'Show rosters', + switchGroup = 'team-cards-show-rosters', + defaultActive = false, + collapsibleSelector = '.team-participant-card', + }, + }, + AnalyticsWidget{ + analyticsName = 'ParticipantsCompactSwitch', + analyticsProperties = { + ['track-value-as'] = 'participants compact', + }, + children = Switch{ + label = 'Compact view', + switchGroup = 'team-cards-compact', + defaultActive = true, + }, + } + } + } +end + +return ParticipantsTeamCardsGroupSwitch diff --git a/lua/wikis/commons/Widget/Participants/Team/Wrapper.lua b/lua/wikis/commons/Widget/Participants/Team/Wrapper.lua new file mode 100644 index 00000000000..63907fe8281 --- /dev/null +++ b/lua/wikis/commons/Widget/Participants/Team/Wrapper.lua @@ -0,0 +1,52 @@ +--- +-- @Liquipedia +-- page=Module:Widget/Participants/Team/Wrapper +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Lua = require('Module:Lua') + +local Array = Lua.import('Module:Array') +local Class = Lua.import('Module:Class') +local Controller = Lua.import('Module:TeamParticipants/Controller') +local Json = Lua.import('Module:Json') +local Table = Lua.import('Module:Table') +local Tabs = Lua.import('Module:Tabs') + +local Widget = Lua.import('Module:Widget') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local Div = HtmlWidgets.Div +local ParticipantsTeamCardSwitch = Lua.import('Module:Widget/Participants/Team/Switch') + + +---@class ParticipantsTeamCardsGroupWrapper: Widget +---@operator call(table): ParticipantsTeamCardsGroupWrapper +local ParticipantsTeamCardsGroupWrapper = Class.new(Widget) + +---@return Widget? +function ParticipantsTeamCardsGroupWrapper:render() + local names = {} + local cardsGroups = Array.mapIndexes(function(inputIndex) + local input = Json.parseIfTable(self.props[inputIndex]) + if not input then return end + table.insert(names, self.props['header' .. inputIndex]) + return Controller.fromTemplate(Table.merge(input, {suppressSwitch = true})) + end) + + local tabArgs = {} + Array.forEach(cardsGroups, function(cardsGroup, tabIndex) + tabArgs['name' .. tabIndex] = names[tabIndex] + tabArgs['content' .. tabIndex] = cardsGroup + end) + + return Div{ + classes = { 'team-participant' }, + children = { + ParticipantsTeamCardSwitch(), + Tabs.dynamic(tabArgs), + }, + } +end + +return ParticipantsTeamCardsGroupWrapper