-
Notifications
You must be signed in to change notification settings - Fork 103
feat: Add Overview page for empty pages - person version #7091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a4f128d
add Wrapper
hjpalpha a4339b3
eof
hjpalpha 6a0baea
prep custom infoboxes (alias faction for race)
hjpalpha b17a93a
implement empty page for persosn
hjpalpha 522f1c2
Update lua/wikis/commons/Widget/EmptyPagePreview/Person.lua
hjpalpha 74e1ece
Update lua/wikis/commons/Widget/EmptyPagePreview/Person.lua
hjpalpha 63b9c54
Update lua/wikis/commons/Widget/EmptyPagePreview.lua
hjpalpha 04da5c4
use `Opponent.playerFromLpdbStruct` and `Opponent.staffFromLpdbStruct`
hjpalpha cef3674
unused import
hjpalpha d7b6594
Update lua/wikis/commons/Widget/EmptyPagePreview/Person.lua
hjpalpha 0d1327d
Update lua/wikis/commons/Widget/EmptyPagePreview/Person.lua
hjpalpha 8c32fa1
Update lua/wikis/commons/Widget/EmptyPagePreview/Person.lua
hjpalpha 4af5211
from review
hjpalpha 713badd
as per poll not needed anymore
hjpalpha b146767
unused import
hjpalpha c233fdc
Merge branch 'main' into empty-page-person-stuff
hjpalpha 81ab856
as per preview
hjpalpha 2db6e46
kick tostring
hjpalpha 7453810
Merge branch 'main' into empty-page-person-stuff
hjpalpha 2134d76
kick empty line
hjpalpha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --- | ||
| -- @Liquipedia | ||
| -- page=Module:Widget/EmptyPagePreview | ||
| -- | ||
| -- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
| -- | ||
|
|
||
| local Lua = require('Module:Lua') | ||
|
|
||
| local Class = Lua.import('Module:Class') | ||
| local Namespace = Lua.import('Module:Namespace') | ||
| local TeamTemplate = Lua.import('Module:TeamTemplate') | ||
|
|
||
| local EmptyTeamPagePreview = Lua.import('Module:Widget/EmptyPagePreview/Team') | ||
| local EmptyPersonPagePreview = Lua.import('Module:Widget/EmptyPagePreview/Person') | ||
| local Widget = Lua.import('Module:Widget') | ||
|
|
||
| ---@class EmptyPagePreview: Widget | ||
| ---@operator call(table): EmptyPagePreview | ||
| local EmptyPagePreview = Class.new(Widget) | ||
|
|
||
| ---@return Widget? | ||
| function EmptyPagePreview:render() | ||
| if not Namespace.isMain() then | ||
| return | ||
| end | ||
|
|
||
| if TeamTemplate.exists(self.props.pageName or mw.title.getCurrentTitle().prefixedText) then | ||
| return EmptyTeamPagePreview(self.props) | ||
| end | ||
|
|
||
| return EmptyPersonPagePreview(self.props) | ||
| end | ||
|
|
||
| return EmptyPagePreview | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,250 @@ | ||
| --- | ||
| -- @Liquipedia | ||
| -- page=Module:Widget/EmptyPagePreview/Person | ||
| -- | ||
| -- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
| -- | ||
|
|
||
| local Lua = require('Module:Lua') | ||
|
|
||
| local Array = Lua.import('Module:Array') | ||
| local BroadcasterTable = Lua.import('Module:BroadcastTalentTable') | ||
| local Class = Lua.import('Module:Class') | ||
| local DateExt = Lua.import('Module:Date/Ext') | ||
| local Info = Lua.import('Module:Info', {loadData = true}) | ||
| local Infobox = Lua.import('Module:Infobox/Person/Player/Custom') | ||
| local Logic = Lua.import('Module:Logic') | ||
| local MatchTable = Lua.import('Module:MatchTable/Custom') | ||
| local Namespace = Lua.import('Module:Namespace') | ||
| local Opponent = Lua.import('Module:Opponent/Custom') | ||
| local Page = Lua.import('Module:Page') | ||
| local ResultsTable = Lua.import('Module:ResultsTable/Custom') | ||
| local Table = Lua.import('Module:Table') | ||
| local Tabs = Lua.import('Module:Tabs') | ||
| local Variables = Lua.import('Module:Variables') | ||
|
|
||
| local PlayerAutoTeamNavBox = Lua.import('Module:Widget/NavBox/AutoTeam/Player') | ||
| local HtmlWidgets = Lua.import('Module:Widget/Html/All') | ||
| local Widget = Lua.import('Module:Widget') | ||
| local WidgetUtil = Lua.import('Module:Widget/Util') | ||
|
|
||
| local Condition = Lua.import('Module:Condition') | ||
| local ConditionTree = Condition.Tree | ||
| local ConditionNode = Condition.Node | ||
| local Comparator = Condition.Comparator | ||
| local BooleanOperator = Condition.BooleanOperator | ||
| local ColumnName = Condition.ColumnName | ||
|
|
||
| local DEFAULT_MAX_PLAYERS_PER_PLACEMENT = Info.config.defaultMaxPlayersPerPlacement or 10 | ||
|
|
||
| ---@class EmptyPersonPagePreview: Widget | ||
| ---@operator call(table): EmptyPersonPagePreview | ||
| local EmptyPersonPagePreview = Class.new(Widget) | ||
| EmptyPersonPagePreview.defaultProps = {pageName = mw.title.getCurrentTitle().prefixedText} | ||
|
|
||
| ---@return Widget? | ||
| function EmptyPersonPagePreview:render() | ||
| if not Namespace.isMain() then | ||
| return | ||
| end | ||
|
|
||
| --disable storage ... just to be sure ... | ||
| Variables.varDefine('disable_LPDB_storage', 'true') | ||
|
|
||
| self.person = Page.applyUnderScoresIfEnforced(self.props.pageName) | ||
|
|
||
| return HtmlWidgets.Div{ | ||
| children = WidgetUtil.collect( | ||
| self:_infobox(), | ||
| HtmlWidgets.H2{children = {'Overview'}}, | ||
| self:_results(), | ||
| self:_matches(), | ||
| HtmlWidgets.Br{}, | ||
| PlayerAutoTeamNavBox{} | ||
| ), | ||
| } | ||
| end | ||
|
|
||
| ---@private | ||
| ---@return Widget | ||
| function EmptyPersonPagePreview:_infobox() | ||
| local infoboxArgsFromSquadInfo = self:_backfillInformationFromSquadInfo() | ||
|
|
||
| local infoboxArgs = Table.merge( | ||
| { | ||
| default = 'Infobox player NoImage.png', | ||
| defaultDark = 'Infobox player NoImage darkmode.png', | ||
| }, | ||
| infoboxArgsFromSquadInfo, | ||
| self:_backfillInformationFromPlacements() | ||
| ) | ||
| table.insert(infoboxArgs.idsArray, infoboxArgsFromSquadInfo.id) | ||
|
Eetwalt marked this conversation as resolved.
|
||
| infoboxArgs.idsArray = Array.unique(infoboxArgs.idsArray) | ||
| infoboxArgs.idsArray = Array.filter(infoboxArgs.idsArray, function(id) | ||
| return id ~= infoboxArgs.id | ||
| end) | ||
| infoboxArgs.ids = table.concat(infoboxArgs.idsArray, ', ') | ||
| infoboxArgs.id = infoboxArgs.id or self.props.pageName | ||
|
|
||
| return Infobox.run(infoboxArgs) | ||
| end | ||
|
|
||
| ---@private | ||
| ---@return Widget[] | ||
| function EmptyPersonPagePreview:_matches() | ||
|
hjpalpha marked this conversation as resolved.
|
||
| return { | ||
| HtmlWidgets.H3{children = 'Most Recent Matches'}, | ||
| MatchTable.results{ | ||
| tableMode = 'solo', | ||
| player = self.person, | ||
| showType = true, | ||
| limit = 10, | ||
| } | ||
| } | ||
| end | ||
|
|
||
| ---@private | ||
| ---@return (Widget|Html)[] | ||
| function EmptyPersonPagePreview:_results() | ||
| ---@type table<string, string|boolean|Widget> | ||
| local tabArgs = { | ||
| suppressHeader = true, | ||
| name1 = 'Achievements', | ||
| content1 = ResultsTable.results{ | ||
| player = self.person, | ||
| showType = true, | ||
| gameIcons = true, | ||
| awards = false, | ||
| achievements = true, | ||
| querytype = 'solo', | ||
| } | ||
| } | ||
| local index = 2 | ||
|
|
||
| local awardsAchievements = ResultsTable.awards{ | ||
| player = self.person, | ||
| showType = true, | ||
| gameIcons = true, | ||
| awards = true, | ||
| achievements = true, | ||
| querytype = 'solo', | ||
| } | ||
| if Logic.isNotEmpty(awardsAchievements) then | ||
| tabArgs['name' .. index] = 'Awards Achievements' | ||
| tabArgs['content' .. index] = awardsAchievements | ||
| index = index + 1 | ||
| end | ||
|
|
||
| local talentAchievements = BroadcasterTable.run{ | ||
| broadcaster = self.person, | ||
| achievements = true, | ||
| useTickerNames = true, | ||
| } | ||
| if Logic.isNotEmpty(talentAchievements) then | ||
| tabArgs['name' .. index] = 'Talent Achievements' | ||
| tabArgs['content' .. index] = talentAchievements | ||
| end | ||
|
|
||
| return { | ||
| HtmlWidgets.H3{children = 'Achievements'}, | ||
| Tabs.dynamic(tabArgs) | ||
| } | ||
|
hjpalpha marked this conversation as resolved.
|
||
| end | ||
|
|
||
| --- checks the last 100 placements for the wanted data | ||
| ---@private | ||
| ---@return table | ||
| function EmptyPersonPagePreview:_backfillInformationFromPlacements() | ||
| local personConditions = ConditionTree(BooleanOperator.any) | ||
| -- players | ||
| :add(Array.map(Array.range(1, DEFAULT_MAX_PLAYERS_PER_PLACEMENT), function(index) | ||
| return ConditionNode(ColumnName('p' .. index, 'opponentplayers'), Comparator.eq, self.person) | ||
| end)) | ||
| -- coaches (etc) | ||
| :add(Array.map(Array.range(1, 5), function(index) | ||
| return ConditionNode(ColumnName('c' .. index, 'opponentplayers'), Comparator.eq, self.person) | ||
| end)) | ||
|
|
||
| local conditions = ConditionTree(BooleanOperator.all):add{ | ||
| ConditionNode(ColumnName('date'), Comparator.neq, DateExt.defaultDateTime), | ||
| ConditionNode(ColumnName('opponentplayers'), Comparator.neq, ''), | ||
| ConditionNode(ColumnName('opponentplayers'), Comparator.neq, '[]'), | ||
| ConditionNode(ColumnName('liquipediatier'), Comparator.neq, -1), | ||
|
mbergen marked this conversation as resolved.
|
||
| personConditions | ||
| } | ||
|
|
||
| local placements = mw.ext.LiquipediaDB.lpdb('placement', { | ||
| conditions = tostring(conditions), | ||
| query = 'opponenttype, opponentname, opponenttemplate, opponentplayers', | ||
| order = 'date desc', | ||
| limit = 100, | ||
| }) | ||
|
|
||
| local infoboxArgs = {idsArray = {}} | ||
|
|
||
| if #placements == 0 then | ||
| return infoboxArgs | ||
| end | ||
|
|
||
| ---@param personData table<string, string> | ||
| ---@return standardPlayer? | ||
| local getPerson = function(personData) | ||
| local index = 1 | ||
| while personData['p' .. index] or personData['c' .. index] do | ||
| if personData['p' .. index] == self.person then | ||
| return Opponent.playerFromLpdbStruct(personData, index) | ||
| end | ||
| if personData['c' .. index] == self.person then | ||
| return Opponent.staffFromLpdbStruct(personData, index) | ||
| end | ||
| index = index + 1 | ||
| end | ||
| end | ||
|
|
||
| Array.forEach(Array.reverse(placements), function(placement) | ||
| local person = getPerson(placement.opponentplayers) | ||
| if not person then | ||
| return | ||
| end | ||
|
|
||
| local id = Logic.nilIfEmpty(person.displayName) | ||
| table.insert(infoboxArgs.idsArray, id) | ||
| Table.mergeInto(infoboxArgs, { | ||
| id = id, | ||
| country = person.flag, | ||
| faction = person.faction, | ||
| }) | ||
| end) | ||
|
|
||
| return infoboxArgs | ||
| end | ||
|
|
||
| ---@private | ||
| ---@return table | ||
| function EmptyPersonPagePreview:_backfillInformationFromSquadInfo() | ||
| local squadEntry = mw.ext.LiquipediaDB.lpdb('squadplayer', { | ||
| conditions = tostring(ConditionNode(ColumnName('link'), Comparator.eq, self.person)), | ||
| query = 'name, id, nationality, leavedate, inactivedate, pagename, extradata', | ||
| order = 'joindate desc', | ||
| limit = 1, | ||
| })[1] | ||
|
|
||
| if not squadEntry then | ||
| return {} | ||
|
mbergen marked this conversation as resolved.
|
||
| end | ||
|
|
||
| local infoboxArgs = { | ||
| id = Logic.nilIfEmpty(squadEntry.id), | ||
| country = Logic.nilIfEmpty(squadEntry.nationality), | ||
| faction = Logic.nilIfEmpty((squadEntry.extradata or {}).faction), | ||
| name = Logic.nilIfEmpty(squadEntry.name), | ||
| } | ||
|
|
||
| if DateExt.isDefaultTimestamp(squadEntry.leavedate) and DateExt.isDefaultTimestamp(squadEntry.inactivedate) then | ||
| infoboxArgs.team = squadEntry.pagename | ||
| end | ||
|
hjpalpha marked this conversation as resolved.
|
||
|
|
||
| return infoboxArgs | ||
| end | ||
|
|
||
| return EmptyPersonPagePreview | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.