diff --git a/lua/wikis/commons/Squad/Row.lua b/lua/wikis/commons/Squad/Row.lua index ac7798f9758..df248b2e556 100644 --- a/lua/wikis/commons/Squad/Row.lua +++ b/lua/wikis/commons/Squad/Row.lua @@ -12,29 +12,37 @@ local Icon = Lua.import('Module:Icon') local Opponent = Lua.import('Module:Opponent/Custom') local OpponentDisplay = Lua.import('Module:OpponentDisplay/Custom') local String = Lua.import('Module:StringUtils') +local TeamTemplate = Lua.import('Module:TeamTemplate') local Template = Lua.import('Module:Template') -local Widget = Lua.import('Module:Widget/All') +local Table2Widgets = Lua.import('Module:Widget/Table2/All') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local Row, Cell = Table2Widgets.Row, Table2Widgets.Cell local RoleIcons = { captain = Icon.makeIcon{iconName = 'captain', hover = 'Captain'}, sub = Icon.makeIcon{iconName = 'substitute', hover = 'Substitute'}, } +local function shouldShowColumn(visibility, columnId) + return visibility == nil or visibility[columnId] == nil or visibility[columnId] == true +end + ---@class SquadRow: BaseClass ----@operator call(ModelRow): SquadRow +---@operator call(ModelRow, table?): SquadRow ---@field children Widget[] ---@field model ModelRow +---@field columnVisibility table? local SquadRow = Class.new( - function(self, squadPerson) + function(self, squadPerson, columnVisibility) self.children = {} self.model = assert(squadPerson, 'No Squad Person supplied to the Row') + self.columnVisibility = columnVisibility end ) ---@return self function SquadRow:id() - local content = {} local opponent = Opponent.resolve( Opponent.readOpponentArgs{ self.model.id, @@ -45,43 +53,48 @@ function SquadRow:id() }, nil, {syncPlayer = true} ) - table.insert(content, mw.html.create('b'):node(OpponentDisplay.InlineOpponent{opponent = opponent})) + local idContent = { + HtmlWidgets.B{children = {OpponentDisplay.InlineOpponent{opponent = opponent}}}, + } local roleIcon = RoleIcons[(self.model.role or ''):lower()] if roleIcon then - table.insert(content, ' ' .. roleIcon) + table.insert(idContent, ' ' .. roleIcon) end - local cell = Widget.Td{ - classes = {'ID'}, - children = content, - } - - local date = self.model.leavedate or self.model.inactivedate - local hasTeam = self.model.extradata.loanedto and mw.ext.TeamTemplate.teamexists(self.model.extradata.loanedto) - local hasTeamRole = hasTeam and self.model.extradata.loanedtorole - local teamNode = Widget.Td{ - css = hasTeamRole and {'text-align', 'center'} or nil, - children = { - hasTeam and mw.ext.TeamTemplate.teamicon(self.model.extradata.loanedto, date) or nil, - hasTeamRole and mw.html.create('small'):tag('i'):wikitext(self.model.extradata.loanedtorole) or nil, - } - } + table.insert(self.children, Cell{ + children = idContent, + }) - table.insert(self.children, cell) - table.insert(self.children, teamNode) + if shouldShowColumn(self.columnVisibility, 'teamIcon') then + local date = self.model.leavedate or self.model.inactivedate + local hasTeam = self.model.extradata.loanedto and TeamTemplate.exists(self.model.extradata.loanedto) + local hasTeamRole = hasTeam and self.model.extradata.loanedtorole + table.insert(self.children, Cell{ + children = { + hasTeam and OpponentDisplay.InlineTeamContainer{ + template = self.model.extradata.loanedto, + date = date, + style = 'icon', + } or nil, + hasTeamRole and HtmlWidgets.Small{ + children = {HtmlWidgets.I{children = {self.model.extradata.loanedtorole}}} + } or nil, + } + }) + end return self end ---@return self function SquadRow:name() - table.insert(self.children, Widget.Td{ - classes = {'Name'}, - children = String.isNotEmpty(self.model.name) and { - mw.html.create('div'):addClass('MobileStuff'):wikitext('(', self.model.name, ')'), - mw.html.create('div'):addClass('LargeStuff'):wikitext(self.model.name), - } or nil + if not shouldShowColumn(self.columnVisibility, 'name') then + return self + end + + table.insert(self.children, Cell{ + children = String.isNotEmpty(self.model.name) and {self.model.name} or nil, }) return self @@ -89,41 +102,41 @@ end ---@return self function SquadRow:role() + if not shouldShowColumn(self.columnVisibility, 'role') then + return self + end + local display = String.isNotEmpty(self.model.role) and not RoleIcons[self.model.role:lower()] - table.insert(self.children, Widget.Td{ - classes = {'Position'}, - children = display and { - mw.html.create('div'):addClass('MobileStuff'):wikitext('Role: '), - mw.html.create('i'):wikitext('(' .. self.model.role .. ')'), - } or nil, + table.insert(self.children, Cell{ + children = display and {self.model.role} or nil, }) return self end ----Display Position and Role in a single cell ---@return self function SquadRow:position() + if not shouldShowColumn(self.columnVisibility, 'role') then + return self + end + local displayRole = String.isNotEmpty(self.model.role) and not RoleIcons[self.model.role:lower()] local content = {} if String.isNotEmpty(self.model.position) or String.isNotEmpty(self.model.role) then - table.insert(content, mw.html.create('div'):addClass('MobileStuff'):wikitext('Position: ')) - if String.isNotEmpty(self.model.position) then table.insert(content, self.model.position) if displayRole then - table.insert(content, ' (' .. self.model.role .. ')') + table.insert(content, ' (' .. self.model.role .. ')') end elseif displayRole then table.insert(content, self.model.role) end end - table.insert(self.children, Widget.Td{ - classes = {'Position'}, + table.insert(self.children, Cell{ children = content, }) @@ -131,16 +144,16 @@ function SquadRow:position() end ---@param field string ----@param cellTitle string? ---@return self -function SquadRow:date(field, cellTitle) - table.insert(self.children, Widget.Td{ - classes = {'Date'}, +function SquadRow:date(field) + if not shouldShowColumn(self.columnVisibility, field) then + return self + end + + table.insert(self.children, Cell{ children = self.model[field] and { - mw.html.create('div'):addClass('MobileStuffDate'):wikitext(cellTitle), - mw.html.create('div'):addClass('Date') - :tag('i'):wikitext(self.model.extradata[field .. 'display'] or self.model[field]) - } or nil + HtmlWidgets.I{children = {self.model.extradata[field .. 'display'] or self.model[field]}}, + } or nil, }) return self @@ -148,6 +161,10 @@ end ---@return self function SquadRow:newteam() + if not shouldShowColumn(self.columnVisibility, 'newteam') then + return self + end + local function createContent() local content = {} local newTeam, newTeamRole, newTeamSpecial = self.model.newteam, self.model.newteamrole, self.model.newteamspecial @@ -158,31 +175,26 @@ function SquadRow:newteam() return content end - table.insert(content, mw.html.create('div'):addClass('MobileStuff') - :tag('i'):addClass('fa fa-long-arrow-right'):attr('aria-hidden', 'true'):done():wikitext(' ')) - if hasNewTeamSpecial then table.insert(content, Template.safeExpand(mw.getCurrentFrame(), newTeamSpecial)) return content end if not hasNewTeam then - table.insert(content, mw.html.create('div'):addClass('NewTeamRole'):wikitext(newTeamRole)) + table.insert(content, newTeamRole) return content end local date = self.model.extradata.newteamdate or self.model.leavedate - table.insert(content, mw.ext.TeamTemplate.team(newTeam, date)) + table.insert(content, OpponentDisplay.InlineTeamContainer{template = newTeam, date = date}) if hasNewTeamRole then - table.insert(content, ' ') - table.insert(content, mw.html.create('i'):tag('small'):wikitext('(' .. newTeamRole .. ')')) + table.insert(content, ' (' .. newTeamRole .. ')') end return content end - table.insert(self.children, Widget.Td{ - classes = {'NewTeam'}, + table.insert(self.children, Cell{ children = createContent(), }) @@ -191,19 +203,7 @@ end ---@return Widget function SquadRow:create() - -- Set row background for certain roles - local backgrounds = {'Player'} - local role = string.lower(self.model.role or '') - - if role == 'sub' then - table.insert(backgrounds, 'sub') - elseif role:find('coach') then - table.insert(backgrounds, role) - table.insert(backgrounds, 'roster-coach') - end - - return Widget.Tr{ - classes = backgrounds, + return Row{ children = self.children, } end diff --git a/lua/wikis/commons/Squad/Utils.lua b/lua/wikis/commons/Squad/Utils.lua index 5dbf246563c..0848cb2ddbe 100644 --- a/lua/wikis/commons/Squad/Utils.lua +++ b/lua/wikis/commons/Squad/Utils.lua @@ -16,6 +16,7 @@ local Logic = Lua.import('Module:Logic') local ReferenceCleaner = Lua.import('Module:ReferenceCleaner') local String = Lua.import('Module:StringUtils') local Table = Lua.import('Module:Table') +local TeamTemplate = Lua.import('Module:TeamTemplate') local Lpdb = Lua.import('Module:Lpdb') local Faction = Lua.import('Module:Faction') @@ -125,10 +126,10 @@ end ---@return ModelRow function SquadUtils.readSquadPersonArgs(args) local function getTeamInfo(page, property) - if not page or not mw.ext.TeamTemplate.teamexists(page) then + if not page or not TeamTemplate.exists(page) then return end - return mw.ext.TeamTemplate.raw(page)[property] + return TeamTemplate.getRawOrNil(page)[property] end local name = String.nilIfEmpty(args.name) @@ -190,9 +191,46 @@ function SquadUtils.storeSquadPerson(squadPerson) squadPerson:save() end +---@param players table[] +---@param squadStatus SquadStatus +---@return table +function SquadUtils.analyzeColumnVisibility(players, squadStatus) + local isInactive = squadStatus == SquadUtils.SquadStatus.INACTIVE + or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE + local isFormer = squadStatus == SquadUtils.SquadStatus.FORMER + or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE + + return { + teamIcon = Array.any(players, function(p) + local loanedTo = p.extradata and p.extradata.loanedto or p.loanedto + return loanedTo and TeamTemplate.exists(loanedTo) + end), + name = Array.any(players, function(p) + return String.isNotEmpty(p.name) + end), + role = Array.any(players, function(p) + return String.isNotEmpty(p.role) or String.isNotEmpty(p.position) + end), + joindate = Array.any(players, function(p) + return String.isNotEmpty(p.joindate) + end), + inactivedate = isInactive and Array.any(players, function(p) + return String.isNotEmpty(p.inactivedate) + end), + leavedate = isFormer and Array.any(players, function(p) + return String.isNotEmpty(p.leavedate) + end), + newteam = isFormer and Array.any(players, function(p) + return String.isNotEmpty(p.newteam) + or String.isNotEmpty(p.newteamrole) + or String.isNotEmpty(p.newteamspecial) + end), + } +end + ---@param frame table ---@param squadWidget SquadWidget ----@param rowCreator fun(player: table, squadStatus: SquadStatus, squadType: SquadType):Widget +---@param rowCreator fun(player: table, squadStatus: SquadStatus, squadType: SquadType, columnVisibility: table):Widget ---@return Widget function SquadUtils.defaultRunManual(frame, squadWidget, rowCreator) local args = Arguments.getArgs(frame) @@ -207,49 +245,54 @@ function SquadUtils.defaultRunManual(frame, squadWidget, rowCreator) props.status = SquadUtils.SquadStatus.FORMER_INACTIVE end + local columnVisibility = SquadUtils.analyzeColumnVisibility(players, props.status) props.children = Array.map(players, function(player) - return rowCreator(player, props.status, props.type) + return rowCreator(player, props.status, props.type, columnVisibility) end) + local output = squadWidget(props) + output = SquadContexts.ColumnVisibility{value = columnVisibility, children = {output}} if Info.config.squads.hasPosition then - return SquadContexts.RoleTitle{value = SquadUtils.positionTitle(), children = {squadWidget(props)}} + output = SquadContexts.RoleTitle{value = SquadUtils.positionTitle(), children = {output}} end - return squadWidget(props) + return output end ---@param players table[] ---@param squadStatus SquadStatus ---@param squadType SquadType ---@param squadWidget SquadWidget ----@param rowCreator fun(person: table, squadStatus: SquadStatus, squadType: SquadType):Widget +---@param rowCreator fun(person: table, squadStatus: SquadStatus, squadType: SquadType, columnVisibility: table):Widget ---@param customTitle string? ---@param personMapper? fun(person: table): table ---@return Widget function SquadUtils.defaultRunAuto(players, squadStatus, squadType, squadWidget, rowCreator, customTitle, personMapper) + local mappedPlayers = Array.map(players, personMapper or SquadUtils.convertAutoParameters) + local columnVisibility = SquadUtils.analyzeColumnVisibility(mappedPlayers, squadStatus) local props = { status = squadStatus, title = customTitle, type = squadType, } - - local mappedPlayers = Array.map(players, personMapper or SquadUtils.convertAutoParameters) props.children = Array.map(mappedPlayers, function(player) - return rowCreator(player, props.status, props.type) + return rowCreator(player, props.status, props.type, columnVisibility) end) + local output = squadWidget(props) + output = SquadContexts.ColumnVisibility{value = columnVisibility, children = {output}} if Info.config.squads.hasPosition then - return SquadContexts.RoleTitle{value = SquadUtils.positionTitle(), children = {squadWidget(props)}} + output = SquadContexts.RoleTitle{value = SquadUtils.positionTitle(), children = {output}} end - return squadWidget(props) + return output end ---@param squadRowClass SquadRow ----@return fun(person: table, squadStatus: SquadStatus, squadType: SquadType):Widget +---@return fun(person: table, squadStatus: SquadStatus, squadType: SquadType, columnVisibility: table?):Widget function SquadUtils.defaultRow(squadRowClass) - return function(person, squadStatus, squadType) + return function(person, squadStatus, squadType, columnVisibility) local squadPerson = SquadUtils.readSquadPersonArgs(Table.merge(person, {status = squadStatus, type = squadType})) SquadUtils.storeSquadPerson(squadPerson) - local row = squadRowClass(squadPerson) + local row = squadRowClass(squadPerson, columnVisibility) row:id():name() if Info.config.squads.hasPosition then @@ -257,14 +300,14 @@ function SquadUtils.defaultRow(squadRowClass) else row:role() end - row:date('joindate', 'Join Date: ') + row:date('joindate') if squadStatus == SquadUtils.SquadStatus.INACTIVE or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('inactivedate', 'Inactive Date: ') + row:date('inactivedate') end if squadStatus == SquadUtils.SquadStatus.FORMER or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('leavedate', 'Leave Date: ') + row:date('leavedate') row:newteam() end diff --git a/lua/wikis/commons/Widget/Contexts/Squad.lua b/lua/wikis/commons/Widget/Contexts/Squad.lua index d58dd19d150..50827a26a53 100644 --- a/lua/wikis/commons/Widget/Contexts/Squad.lua +++ b/lua/wikis/commons/Widget/Contexts/Squad.lua @@ -15,4 +15,5 @@ return { RoleTitle = Class.new(Context), InactiveSection = Class.new(Context), FormerSection = Class.new(Context), + ColumnVisibility = Class.new(Context), } diff --git a/lua/wikis/commons/Widget/Squad/Core.lua b/lua/wikis/commons/Widget/Squad/Core.lua index 1cf6a7a840d..cb31b9313a9 100644 --- a/lua/wikis/commons/Widget/Squad/Core.lua +++ b/lua/wikis/commons/Widget/Squad/Core.lua @@ -12,13 +12,11 @@ local Logic = Lua.import('Module:Logic') local String = Lua.import('Module:StringUtils') local SquadUtils = Lua.import('Module:Squad/Utils') -local Widgets = Lua.import('Module:Widget/All') +local TableWidgets = Lua.import('Module:Widget/Table2/All') local Widget = Lua.import('Module:Widget') local WidgetUtil = Lua.import('Module:Widget/Util') local SquadContexts = Lua.import('Module:Widget/Contexts/Squad') -local DataTable, Tr, Th = Widgets.DataTable, Widgets.Tr, Widgets.Th - ---@class SquadWidget: Widget ---@operator call(table): SquadWidget local Squad = Class.new(Widget) @@ -39,24 +37,28 @@ local SquadTypeToDisplay = { [SquadUtils.SquadType.STAFF] = 'Organization', } ----@return WidgetDataTable +---@return Table2 function Squad:render() local title = self:_title(self.props.status, self.props.title, self.props.type) local header = self:_header(self.props.status) - local allChildren = WidgetUtil.collect(title, header, unpack(self.props.children)) - - return DataTable{ - classes = {'wikitable-striped', 'roster-card'}, - wrapperClasses = {'roster-card-wrapper'}, - children = allChildren, + return TableWidgets.Table{ + title = title, + children = { + TableWidgets.TableHeader{ + children = {header}, + }, + TableWidgets.TableBody{ + children = self.props.children, + }, + }, } end ---@param squadStatus SquadStatus ---@param title string? ---@param squadType SquadType ----@return Widget? +---@return string? function Squad:_title(squadStatus, title, squadType) local defaultTitle -- TODO: Work away this special case @@ -64,7 +66,6 @@ function Squad:_title(squadStatus, title, squadType) (squadStatus == SquadUtils.SquadStatus.FORMER or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE) then defaultTitle = 'Former Squad' - -- No default title for Active tables elseif squadStatus ~= SquadUtils.SquadStatus.ACTIVE then defaultTitle = SquadStatusToDisplay[squadStatus] .. ' ' .. SquadTypeToDisplay[squadType] end @@ -75,35 +76,41 @@ function Squad:_title(squadStatus, title, squadType) return end - return Tr{ - children = {Th{children = {titleText}, attributes={colspan = 10}}} - } + return titleText end ---@param status SquadStatus ---@return Widget function Squad:_header(status) + local visibility = self:useContext(SquadContexts.ColumnVisibility) + + local function show(col) + return visibility == nil or visibility[col] == nil or visibility[col] == true + end + local isInactive = status == SquadUtils.SquadStatus.INACTIVE or status == SquadUtils.SquadStatus.FORMER_INACTIVE local isFormer = status == SquadUtils.SquadStatus.FORMER or status == SquadUtils.SquadStatus.FORMER_INACTIVE - local name = self:useContext(SquadContexts.NameSection, {Th{children = {'Name'}}}) - local inactive = isInactive and self:useContext(SquadContexts.InactiveSection, { - Th{children = {'Inactive Date'}} - }) or nil - local former = isFormer and self:useContext(SquadContexts.FormerSection, { - Th{children = {'Leave Date'}}, - Th{children = {'New Team'}}, + local name = show('name') and self:useContext( + SquadContexts.NameSection, + {TableWidgets.CellHeader{children = {'Name'}}} + ) or nil + local inactive = isInactive and show('inactivedate') and self:useContext(SquadContexts.InactiveSection, { + TableWidgets.CellHeader{children = {'Inactive Date'}} }) or nil - local role = {Th{children = {self:useContext(SquadContexts.RoleTitle)}}} + local former = isFormer and WidgetUtil.collect( + show('leavedate') and TableWidgets.CellHeader{children = {'Leave Date'}} or nil, + show('newteam') and TableWidgets.CellHeader{children = {'New Team'}} or nil + ) or nil + local role = show('role') and {TableWidgets.CellHeader{children = {self:useContext(SquadContexts.RoleTitle)}}} or nil - return Tr{ - classes = {'HeaderRow'}, + return TableWidgets.Row{ children = WidgetUtil.collect( - Th{children = {'ID'}}, - Th{}, -- "Team Icon" (most commmonly used for loans) + TableWidgets.CellHeader{children = {'ID'}}, + show('teamIcon') and TableWidgets.CellHeader{} or nil, name, role, - Th{children = {'Join Date'}}, + show('joindate') and TableWidgets.CellHeader{children = {'Join Date'}} or nil, inactive, former ) diff --git a/lua/wikis/commons/Widget/Table2/Cell.lua b/lua/wikis/commons/Widget/Table2/Cell.lua index e51fd1e1bbf..0eada517845 100644 --- a/lua/wikis/commons/Widget/Table2/Cell.lua +++ b/lua/wikis/commons/Widget/Table2/Cell.lua @@ -34,6 +34,10 @@ local ColumnUtil = Lua.import('Module:Widget/Table2/ColumnUtil') ---@field props Table2CellProps local Table2Cell = Class.new(Widget) +Table2Cell.defaultProps = { + nowrap = true, +} + ---@return Widget function Table2Cell:render() local props = self.props @@ -43,7 +47,12 @@ function Table2Cell:render() -- Skip context lookups and property merging if there are no column definitions if not columns then return HtmlWidgets.Td{ - attributes = props.attributes, + attributes = ColumnUtil.buildCellAttributes( + props.align, + props.nowrap, + props.shrink, + props.attributes + ), children = props.children, } end diff --git a/lua/wikis/commons/Widget/Table2/CellHeader.lua b/lua/wikis/commons/Widget/Table2/CellHeader.lua index cd6cce70707..9ec4127d69b 100644 --- a/lua/wikis/commons/Widget/Table2/CellHeader.lua +++ b/lua/wikis/commons/Widget/Table2/CellHeader.lua @@ -50,6 +50,13 @@ function Table2CellHeader:render() attributes.class = 'unsortable' end + attributes = ColumnUtil.buildCellAttributes( + props.align, + props.nowrap, + props.shrink, + attributes + ) + return HtmlWidgets.Th{ attributes = attributes, children = props.children, diff --git a/lua/wikis/dota2/Squad/Custom.lua b/lua/wikis/dota2/Squad/Custom.lua index c802226844b..6f45b636b38 100644 --- a/lua/wikis/dota2/Squad/Custom.lua +++ b/lua/wikis/dota2/Squad/Custom.lua @@ -75,24 +75,24 @@ function CustomSquad.runAuto(playerList, squadStatus, squadType, customTitle) ) end -function CustomSquad._playerRow(person, squadStatus, squadType) +function CustomSquad._playerRow(person, squadStatus, squadType, columnVisibility) local squadPerson = SquadUtils.readSquadPersonArgs(Table.merge(person, {status = squadStatus, type = squadType})) squadPerson.extradata.activeteam = person.activeteam squadPerson.extradata.activeteamrole = person.activeteamrole SquadUtils.storeSquadPerson(squadPerson) - local row = ExtendedSquadRow(squadPerson) + local row = ExtendedSquadRow(squadPerson, columnVisibility) row:id() row:name() row:position() - row:date('joindate', 'Join Date: ') + row:date('joindate') if squadStatus == SquadUtils.SquadStatus.INACTIVE or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('inactivedate', 'Inactive Date: ') + row:date('inactivedate') row:activeteam() end if squadStatus == SquadUtils.SquadStatus.FORMER or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('leavedate', 'Leave Date: ') + row:date('leavedate') row:newteam() end diff --git a/lua/wikis/overwatch/Squad/Custom.lua b/lua/wikis/overwatch/Squad/Custom.lua index 626f94263ff..5ce0f35ef3d 100644 --- a/lua/wikis/overwatch/Squad/Custom.lua +++ b/lua/wikis/overwatch/Squad/Custom.lua @@ -50,12 +50,14 @@ function CustomSquad.run(frame) local players = SquadUtils.parsePlayers(args) local showNumber = Array.any(players, Operator.property('number')) + local columnVisibility = SquadUtils.analyzeColumnVisibility(players, props.status) props.children = Array.map(players, function(player) - return CustomSquad._playerRow(player, props.status, props.type, showNumber) + return CustomSquad._playerRow(player, props.status, props.type, showNumber, columnVisibility) end) local root = SquadContexts.RoleTitle{value = SquadUtils.positionTitle(), children = {Squad(props)}} + root = SquadContexts.ColumnVisibility{value = columnVisibility, children = {root}} if not showNumber then return root end @@ -82,26 +84,27 @@ end ---@param squadStatus SquadStatus ---@param squadType SquadType ---@param showNumber boolean +---@param columnVisibility table? ---@return Widget -function CustomSquad._playerRow(person, squadStatus, squadType, showNumber) +function CustomSquad._playerRow(person, squadStatus, squadType, showNumber, columnVisibility) local squadPerson = SquadUtils.readSquadPersonArgs(Table.merge(person, {status = squadStatus, type = squadType})) squadPerson.extradata.number = person.number SquadUtils.storeSquadPerson(squadPerson) - local row = ExtendedSquadRow(squadPerson) + local row = ExtendedSquadRow(squadPerson, columnVisibility) row:id() if showNumber then row:number() end - row:name():position():date('joindate', 'Join Date: ') + row:name():position():date('joindate') if squadStatus == SquadUtils.SquadStatus.INACTIVE or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('inactivedate', 'Inactive Date: ') + row:date('inactivedate') end if squadStatus == SquadUtils.SquadStatus.FORMER or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('leavedate', 'Leave Date: ') + row:date('leavedate') row:newteam() end diff --git a/lua/wikis/smash/Squad/Custom.lua b/lua/wikis/smash/Squad/Custom.lua index 45d203db345..38fea14f357 100644 --- a/lua/wikis/smash/Squad/Custom.lua +++ b/lua/wikis/smash/Squad/Custom.lua @@ -54,6 +54,7 @@ function CustomSquad.run(frame) local tableGame = args.game local players = SquadUtils.parsePlayers(args) + local columnVisibility = SquadUtils.analyzeColumnVisibility(players, props.status) props.children = Array.map(players, function(person) local game = person.game and mw.text.split(person.game:lower(), ',')[1] or tableGame @@ -66,17 +67,17 @@ function CustomSquad.run(frame) squadPerson.extradata.mains = mains SquadUtils.storeSquadPerson(squadPerson) - local row = ExtendedSquadRow(squadPerson) ---@type SmashSquadRow + local row = ExtendedSquadRow(squadPerson, columnVisibility) ---@type SmashSquadRow row:id():name() - row:mains():date('joindate', 'Join Date: ') + row:mains():date('joindate') if props.status == SquadUtils.SquadStatus.INACTIVE or props.status == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('inactivedate', 'Inactive Date: ') + row:date('inactivedate') end if props.status == SquadUtils.SquadStatus.FORMER or props.status == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('leavedate', 'Leave Date: ') + row:date('leavedate') row:newteam() end @@ -87,9 +88,12 @@ function CustomSquad.run(frame) end) - return SquadContexts.RoleTitle{ - value = 'Main', - children = {Squad(props)} + return SquadContexts.ColumnVisibility{ + value = columnVisibility, + children = {SquadContexts.RoleTitle{ + value = 'Main', + children = {Squad(props)} + }} } end diff --git a/lua/wikis/starcraft/Squad/Custom.lua b/lua/wikis/starcraft/Squad/Custom.lua index 7fa681fad38..a3cae4521fd 100644 --- a/lua/wikis/starcraft/Squad/Custom.lua +++ b/lua/wikis/starcraft/Squad/Custom.lua @@ -44,7 +44,7 @@ function CustomSquad.run(frame) local tlpd = Logic.readBool(args.tlpd) local SquadClass = tlpd and SquadTldb or Squad - return SquadUtils.defaultRunManual(frame, SquadClass, function(person, squadStatus, squadType) + return SquadUtils.defaultRunManual(frame, SquadClass, function(person, squadStatus, squadType, columnVisibility) local inputId = person.id --[[@as number]] person.race = CustomSquad._queryTLPD(inputId, 'race') or person.race person.id = CustomSquad._queryTLPD(inputId, 'name') or person.id @@ -58,7 +58,7 @@ function CustomSquad.run(frame) squadPerson.extradata.eloPeak = CustomSquad._queryTLPD(inputId, 'peak_elo') SquadUtils.storeSquadPerson(squadPerson) - local row = ExtendedSquadRow(squadPerson) + local row = ExtendedSquadRow(squadPerson, columnVisibility) row:id():name() @@ -66,13 +66,13 @@ function CustomSquad.run(frame) row:elo() else row:role() - row:date('joindate', 'Join Date: ') + row:date('joindate') if squadStatus == SquadUtils.SquadStatus.FORMER then - row:date('leavedate', 'Leave Date: ') + row:date('leavedate') row:newteam() elseif squadStatus == SquadUtils.SquadStatus.INACTIVE then - row:date('inactivedate', 'Inactive Date: ') + row:date('inactivedate') end end diff --git a/lua/wikis/starcraft2/Squad/Custom.lua b/lua/wikis/starcraft2/Squad/Custom.lua index 948faf66b6b..3ed6974222d 100644 --- a/lua/wikis/starcraft2/Squad/Custom.lua +++ b/lua/wikis/starcraft2/Squad/Custom.lua @@ -51,8 +51,9 @@ end ---@param person table ---@param squadStatus SquadStatus ---@param squadType SquadType +---@param columnVisibility table? ---@return Widget -function CustomSquad._playerRow(person, squadStatus, squadType) +function CustomSquad._playerRow(person, squadStatus, squadType, columnVisibility) local squadPerson = SquadUtils.readSquadPersonArgs(Table.merge(person, {status = squadStatus, type = squadType})) local squadArgs = Arguments.getArgs(mw.getCurrentFrame()) @@ -66,15 +67,15 @@ function CustomSquad._playerRow(person, squadStatus, squadType) SquadUtils.storeSquadPerson(squadPerson) - local row = SquadRow(squadPerson) + local row = SquadRow(squadPerson, columnVisibility) - row:id():name():role():date('joindate', 'Join Date: ') + row:id():name():role():date('joindate') if squadStatus == SquadUtils.SquadStatus.INACTIVE or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('inactivedate', 'Inactive Date: ') + row:date('inactivedate') end if squadStatus == SquadUtils.SquadStatus.FORMER or squadStatus == SquadUtils.SquadStatus.FORMER_INACTIVE then - row:date('leavedate', 'Leave Date: ') + row:date('leavedate') row:newteam() end diff --git a/lua/wikis/stormgate/Squad/Custom.lua b/lua/wikis/stormgate/Squad/Custom.lua index 8ac6d877788..7c9bba77094 100644 --- a/lua/wikis/stormgate/Squad/Custom.lua +++ b/lua/wikis/stormgate/Squad/Custom.lua @@ -50,8 +50,9 @@ end ---@param person table ---@param squadStatus SquadStatus ---@param squadType SquadType +---@param columnVisibility table? ---@return Widget -function CustomSquad._playerRow(person, squadStatus, squadType) +function CustomSquad._playerRow(person, squadStatus, squadType, columnVisibility) local squadPerson = SquadUtils.readSquadPersonArgs(Table.merge(person, {status = squadStatus, type = squadType})) if Logic.isEmpty(squadPerson.newteam) then if Logic.readBool(person.retired) then @@ -62,17 +63,17 @@ function CustomSquad._playerRow(person, squadStatus, squadType) end SquadUtils.storeSquadPerson(squadPerson) - local row = SquadRow(squadPerson) + local row = SquadRow(squadPerson, columnVisibility) row:id() row:name() row:role() - row:date('joindate', 'Join Date: ') + row:date('joindate') if squadStatus == SquadUtils.SquadStatus.FORMER then - row:date('leavedate', 'Leave Date: ') + row:date('leavedate') row:newteam() elseif squadStatus == SquadUtils.SquadStatus.INACTIVE then - row:date('inactivedate', 'Inactive Date: ') + row:date('inactivedate') end return row:create() diff --git a/stylesheets/Main.scss b/stylesheets/Main.scss index 9ffe2c8f366..b5f39d63f02 100644 --- a/stylesheets/Main.scss +++ b/stylesheets/Main.scss @@ -34,7 +34,6 @@ @use "commons/Faction"; @use "commons/HexagonPortraits"; @use "commons/ResponsiveTable"; -@use "commons/RosterCard"; @use "commons/TeamPortal"; @use "commons/TournamentCard"; @use "commons/NavFrame"; diff --git a/stylesheets/commons/RosterCard.scss b/stylesheets/commons/RosterCard.scss deleted file mode 100644 index 646de0774a6..00000000000 --- a/stylesheets/commons/RosterCard.scss +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* -Template(s): Roster Cards ( SquadPlayer_start; SquadPlayer ) -Author(s): Rapture -*******************************************************************************/ -.roster-card-wrapper { - margin: 0 0 10px 0; -} - -.roster-card { - display: table; - white-space: nowrap; -} - -.roster-card > tbody > tr > th { - background-color: var( --clr-surface-4, #f5f5f5 ); - font-weight: bold; - padding: 5px; -} - -.roster-card > tbody > tr.HeaderRow > th { - background-color: var( --table-subheader-background-color, var( --clr-surface-4, #f5f5f5 ) ); -} - -.roster-card > tbody > tr:not( .HeaderRow ) > th { - background-color: var( --table-header-background-color, var( --clr-surface-4, #f5f5f5 ) ); -} - -.roster-card > tbody > tr.Player { - display: table-row; - border-top: 1px solid var( --clr-border, #bbbbbb ); -} - -.roster-card > tbody > tr.Player > td { - display: table-cell; - line-height: 1.42857143; - padding: 5px; -} - -.roster-card > tbody > tr.Player > td.Team2 { - padding: 2px 0 0 0; -} - -.roster-card > tbody > tr.Player > td.Position { - text-align: center; -} - -.roster-card > tbody > tr.Player > td.PositionWoTeam2 { - text-align: center; -} - -.roster-card > tbody > tr.Player > td.NewTeam { - padding: 2px 5px 2px 5px; -} - -.roster-card > tbody > tr.Player > td > .MobileStuff { - display: none; -} - -.roster-card > tbody > tr.Player > td > div.MobileStuffDate { - display: none; -} - -.roster-card > tbody > tr.Player > td > div.Date { - font-style: italic; - text-align: center; -} - -.roster-card > tbody > tr.Player > td.NewTeam > div.NewTeamRole { - text-align: center; - font-style: italic; -} - -.roster-none, -.roster-coach { - background-color: var( --table-variant-background-color, var( --clr-surface-variant, #e5e5e5 ) ) !important; -} - -.roster-title-row2-border { - border-bottom: 1px solid var( --table-border-color, var( --clr-border, #bbbbbb ) ); -} - -@media screen and ( max-width: 750px ) { - .roster-card { - width: 100% !important; - max-width: 425px; - border: 1px solid var( --table-border-color, var( --clr-border, #bbbbbb ) ); - } - - .roster-card > tbody > tr.HeaderRow { - display: none; - } - - .roster-card > tbody > tr.Player { - display: block; - padding: 5px; - } - - .roster-card > tbody > tr.Player > td { - display: inline-block; - line-height: 1.42857143; - border: 0 !important; - padding: 0; - } - - .roster-card > tbody > tr.Player > td.ID { - float: left; - padding: 0 5px 0 0; - } - - .roster-card > tbody > tr.Player > td.Name { - font-style: italic; - font-size: small; - float: left; - margin-top: 1px; - } - - .roster-card > tbody > tr.Player > td.Team2 { - float: right; - } - - .roster-card > tbody > tr.Player > td.Position { - font-style: italic; - text-align: left; - font-size: small; - clear: left; - float: left; - } - - .roster-card > tbody > tr.Player > td.PositionWoTeam2 { - font-style: italic; - text-align: right; - font-size: small; - float: right; - } - - .roster-card > tbody > tr.Player > td.NewTeam { - display: block; - width: 100%; - text-align: center; - clear: both; - border-right: 0; - } - - .roster-card > tbody > tr.Player > td > .LargeStuff { - display: none; - } - - .roster-card > tbody > tr.Player > td > .MobileStuff { - display: inline-block; - } - - .roster-card > tbody > tr.Player > td.Date { - display: block; - width: 100%; - clear: both; - border-right: 0; - } - - .roster-card > tbody > tr.Player > td > div.MobileStuffDate { - display: inline-block; - width: 50%; - text-align: right; - font-style: italic; - float: left; - } - - .roster-card > tbody > tr.Player > td > div.Date { - display: inline-block; - width: 50%; - text-align: left; - font-style: italic; - } - - .roster-card > tbody > tr.Player > td.NewTeam > div.NewTeamRole { - display: inline-block; - text-align: left; - font-style: italic; - border-right: 0; - } -}