Module:Data Table/Reports

local p = {}

local DataTable = require("Module:Data Table") local TransclusionArguments = require("Module:Transclusion Arguments") local utilsCargo = require("Module:UtilsCargo") local utilsMarkup = require("Module:UtilsMarkup") local utilsTable = require("Module:UtilsTable")

function p.Main(frame) local tables = utilsCargo.query("DataTables", "_pageName, tableName", {		groupBy = "_pageName, tableName",	}) -- Sort by namespace then page name table.sort(tables, function(a, b)		local titleA = mw.title.new(a._pageName)		local titleB = mw.title.new(b._pageName)		if titleA.nsText ~= titleB.nsText then			return titleA.nsText < titleB.nsText		else			return titleA.text < titleB.text		end	end)

-- Associate data table names to the pages that reference them local copies = TransclusionArguments.fetchTransclusions({		template = "Template:Data Table Copy",		parameters = {"fromPage", "storedAs"},	}) copies = utilsTable.groupBy(copies, function(copy)		return copy.arguments.fromPage.value	end) copies = utilsTable.mapValues(copies, utilsTable._groupBy(function(copy) return copy.arguments.storedAs.value end)) copies = utilsTable.mapValues(copies, utilsTable._mapValues(utilsTable._map("_pageName"))) local columns = {"Storing Page [Description][Rowspan]", "Table Name [Description]", "Querying Pages [Description]"} local rows = {} for i, dataTable in ipairs(tables) do		local tableCopies = copies[dataTable._pageName] and copies[dataTable._pageName][dataTable.tableName] or {} tableCopies = utilsTable.map(tableCopies, utilsMarkup.link) tableCopies = utilsMarkup.bulletList(tableCopies) table.insert(rows, {			utilsMarkup.link(dataTable._pageName),			" ",			tableCopies,		}) end return DataTable.printTable(rows, {		columns = columns	}) end

return p