Module:RosterRumorData

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_esports = require('Module:EsportsUtil') local util_html = require('Module:HtmlUtil') local util_math = require('Module:MathUtil') local util_map = require('Module:MapUtil') local util_news = require("Module:NewsUtil") local util_rumor = require("Module:RumorUtil") local util_sentence = require("Module:SentenceUtil") local util_sort = require("Module:SortUtil") local util_source = require("Module:SourceUtil") local util_table = require('Module:TableUtil') local util_text = require('Module:TextUtil') local util_time = require("Module:TimeUtil") local util_title = require('Module:TitleUtil') local util_vars = require("Module:VarsUtil") local i18n = require('Module:I18nUtil') local WeeklyDataPages = require('Module:WeeklyDataPages') local lang = mw.getLanguage('en')

local m_team = require('Module:Team') local League = require('Module:League') local Role = require('Module:Role') local Region = require('Module:Region') local RegionList = require('Module:RegionList')

local COLUMNS = { 'RegionsDisplay', 'player_display', 'start_display', 'end_display', 'is_not', 'SourceLink', 'SourceSite', 'SourceAuthors', 'Status', 'statuslink_display', classes = { StatusLink = 'test-class', } }

local CUSTOM_TEXT_COLUMNS = { 'RegionsDisplay', 'CustomText', 'is_not', 'SourceLink', 'SourceSite', 'SourceAuthors', 'Status', 'statuslink_display' }

local COLSPANS = { CustomText = 3 }

local h = {}

local p = {}

function p.start(frame) util_vars.setVar(		'rumorPhase',		util_cargo.getOneResult( {				tables = 'RosterChangePortalDates', where = ('DateStart <= "%s" AND DateEnd >= "%s"'):format(					util_title.titleparts(nil, 1, 2),					util_title.titleparts(nil, 1, 2)				), fields = 'PeriodName', },			'PeriodName' )	)	return WeeklyDataPages.start('Roster Rumor Data') end

function p.date(frame) i18n.init('RosterRumorData') local args = util_args.merge util_vars.resetGlobalIndex('N_LineInDate') return WeeklyDataPages.date(args, COLUMNS, 'rumor-data') end

function p.endTable(frame) return ' ' end

function p.line(frame) local args = util_args.merge util_cargo.setStoreNamespace('Data') i18n.init('RosterRumorData') h.validateArgs(args) h.castArgs(args) local data = h.getDataFromArgs(args) util_cargo.store(data) return h.makeRowOutput(data) end

function h.validateArgs(args) if args.region then error(i18n.print('error_regionNotRegion1')) end end

function h.castArgs(args) args.pos1 = Role(args.pos1) args.pos2 = Role(args.pos2) args.region1 = Region(args.region1) args.region2 = Region(args.region2):_or(args.region1) args.regions = RegionList(util_args.numberedArgsToTable(args, 'region')) args.league1 = League(args.league1) args.league2 = League(args.league2) end

function h.getDataFromArgs(args) local ret = { _table = 'RosterRumors', Date = util_vars.getVar('Date'), Status = util_rumor.statusStore(args.status), IsOver = util_rumor.statusIsOver(args.status), RegionsDisplay = args.regions:names, Regions = args.regions, RegionStart = args.region1, RegionEnd = args.region2, Player = args.player, player_display = util_esports.playerLinked(args.player), start_display = h.validateAndGetStart(args), end_display = h.validateAndGetEnd(args), TeamStart = args.team1 and m_team.teamlinkname(args.team1), TeamEnd = args.team2 and m_team.teamlinkname(args.team2), LeagueStart = args.league1, LeagueEnd = args.league2, RoleStart = args.pos1, RoleEnd = args.pos2:_or(args.pos1), IsSubStart = util_args.castAsBool(args.sub1), IsSubEnd = util_args.castAsBool(args.sub2), IsTraineeStart = util_args.castAsBool(args.trainee1), IsTraineeEnd = util_args.castAsBool(args.trainee2), CustomText = args.customtext, SourceLink = args.url, SourceAuthors = args.author, SourceSite = args.site, StatusLink = args.statuslink, statuslink_display = args.statuslink or '-', N_LineInDate = util_vars.setGlobalIndex('N_LineInDate'), NotHappening = util_args.castAsBool(args['not']), is_not = args['not'], }	return ret end

function h.validateAndGetStart(args) if args.team1 and args.league1:exists then error(i18n.print('error_DuplicateStart')) end return h.getRoleDisplay(args, 1) .. h.getPlaceDisplay(args, 1) end

function h.validateAndGetEnd(args) if args.team2 and args.league2:exists then error(i18n.print('error_DuplicateEnd')) end return h.getRoleDisplay(args, 2) .. h.getPlaceDisplay(args, 2) end

function h.getRoleDisplay(args, when) return args['pos' .. when]:image or '' end

function h.getPlaceDisplay(args, when) if args['team' .. when] then return m_team.rightmediumlinked(args['team' .. when]) end return args['league' .. when]:name{len="long"} or '' end

function h.makeRowOutput(data) local tr = mw.html.create('tr') local div if not data.CustomText then div = h.printColumns(tr, data) else div = h.printCustomText(tr, data) end local button = h.printROButton(div, { purge = data }) button:attr('data-is-no', tostring(data.NotHappening)) button:attr('data-is-over', tostring(data.IsOver)) return tr end

function h.printColumns(tr, data) local div for i, col in ipairs(COLUMNS) do		local td = tr:tag('td') if i == #COLUMNS then div = td:tag('div'):addClass('rumor-last-cell-div') end (div or td):wikitext(data[col]) end return div end

function h.printCustomText(tr, row) local div for i, col in ipairs(CUSTOM_TEXT_COLUMNS) do		local td = tr:tag('td') :attr('colspan', COLSPANS[col]) if i == #CUSTOM_TEXT_COLUMNS then div = td:tag('div'):addClass('rumor-last-cell-div') end (div or td):wikitext(row[col]) end return div end

function h.printROButton(div, data) return util_news.printROButton(		div,		{			util_rumor.pageToRefresh(data.RegionStart),			util_rumor.pageToRefresh(data.RegionEnd)		}	) end

return p