This site is no longer actively maintained. It exists for historical purposes as an example of Phabricator integration and Lua scripting.

Difference between revisions of "Module:Reports"

From cpt
No edit summary
No edit summary
Line 28: Line 28:
end
end


function p.priorityToNumber(priority)
local priority_map = {};
priority_map['pink'] = 1
priority_map['red'] = 2
priority_map['orange'] = 3
priority_map['yellow'] = 4
priority_map['sky'] = 5
priority_map['violet'] = 6
if priority_map[priority] then
return priority_map[priority]
else
return '7'
end
end
function p.priorityToColor(priority)
local priority_map = {};
priority_map[1] = '#da49be'
priority_map[2] = '#c0392b'
priority_map[3] = '#e67e22'
priority_map[4] = '#f1c40f'
priority_map[5] = '#3498db'
priority_map[6] = '#8e44ad'
priority_map[7] = '#000'
if priority_map[priority] then
return priority_map[priority]
else
return '#000'
end
end
function p.Workboard(frame)
function p.Workboard(frame)
local s = ''
local s = ''
Line 55: Line 86:
missing = true
missing = true
end
end
priority[v1.fulltext] = v1.printouts['Priority'][1]
priority[v1.fulltext] = p.priortyToNumber( v1.printouts['Priority'][1] )
end
end
if ( empty ) then
if ( empty ) then
Line 88: Line 119:
if v1 == false then
if v1 == false then
s = s .. '{| width=100% style="margin-bottom:10px;"\n| style="border:2px solid ' ..
s = s .. '{| width=100% style="margin-bottom:10px;"\n| style="border:2px solid ' ..
priority[k1] .. ';padding:5px;text-align:center;vertical-align:middle;" |[[' ..
p.priorityToColor( priority[k1] ) .. ';padding:5px;text-align:center;vertical-align:middle;" |[[' ..
k1 .. ']]\n|}\n'
k1 .. ']]\n|}\n'
end
end

Revision as of 20:39, 12 June 2019

Documentation for this module may be created at Module:Reports/doc

local p = {}

function p.cleanse(frame)
	local s = frame.args[1]
	s = string.gsub( s, '{', '{' )
	s = string.gsub( s, '}', '}' )
	s = string.gsub( s, '%[', '[' )
	s = string.gsub( s, '%]', ']' )
	s = string.gsub( s, '|', '|' )
	return s
end

function p.cptWorkboardsTableRow(frame)
	local s = ''
	local link = frame.args[1]
	local category = frame.args[2]
	local kanban = frame.args[3]
	local backlog = frame.args[4]
	if ( #category > 0 and ( #kanban == 0 and #backlog == 0 )) or
		( #category == 0 and ( #kanban > 0 or ( #backlog > 0 and backlog ~= 'Watching / External' ))) then
		s = s .. '\n|' .. link
		s = s .. '\n|' .. category
		s = s .. '\n|' .. kanban
		s = s .. '\n|' .. backlog
		s = s .. '\n|-'
	end
	return s	
end

function p.priorityToNumber(priority)
	local priority_map = {};
	priority_map['pink'] = 1
	priority_map['red'] = 2
	priority_map['orange'] = 3
	priority_map['yellow'] = 4
	priority_map['sky'] = 5
	priority_map['violet'] = 6
	if priority_map[priority] then
		return priority_map[priority]
	else
		return '7'
	end
end		

function p.priorityToColor(priority)	
	local priority_map = {};
	priority_map[1] = '#da49be'
	priority_map[2] = '#c0392b'
	priority_map[3] = '#e67e22'
	priority_map[4] = '#f1c40f'
	priority_map[5] = '#3498db'
	priority_map[6] = '#8e44ad'
	priority_map[7] = '#000'
	if priority_map[priority] then
		return priority_map[priority]
	else
		return '#000'
	end
end
	
function p.Workboard(frame)
	local s = ''
	local epic = frame.args[1]
	local result = mw.smw.getQueryResult(
		'[[Has subobject::<q>[[Project::Core Platform Team]][[Column::' ..
		epic .. ']]</q>]][[Status::open||stalled]]' ..
		'|?CPT Kanban Column|?CPT Backlog Column|?Priority|link=none|limit=500' )
	if result ~= nil then
		local tasks = {}
		local columns = {}
		local priority = {}
		local empty = true
		local missing = false
		for k1,v1 in pairs( result.results ) do
			local kanban_column = v1.printouts['CPT Kanban Column'][1]
			local backlog_column = v1.printouts['CPT Backlog Column'][1]
			empty = false
			if kanban_column ~= nil then
				tasks[v1.fulltext] = kanban_column
				columns[kanban_column] = true
			elseif backlog_column ~= nil then
				tasks[v1.fulltext] = backlog_column
				columns[backlog_column] = true
			else
				tasks[v1.fulltext] = false
				missing = true
			end
			priority[v1.fulltext] = p.priortyToNumber( v1.printouts['Priority'][1] )
		end
		if ( empty ) then
			s = 'No results'
		else
			local sorted_columns = {}
			for k1,v1 in pairs ( columns ) do
				table.insert( sorted_columns, k1 )
			end
			table.sort( sorted_columns )
			s = s .. '{| style="border-spacing:10px;border-collapse:separate;"\n'
			for k1,v1 in pairs( sorted_columns ) do
				s = s .. '! style="border:1px solid #000;padding:5px;background-color:#bbb;text-align:center;" |' .. v1 .. '\n'
			end
			if ( missing ) then
				s = s .. '! style="border:1px solid #000;padding:5px;background-color:#bbb;text-align:center;" |MISSING COLUMN\n'
			end
			s = s .. '|-\n'
			for k1,v1 in pairs( sorted_columns ) do
				s = s .. '| style="vertical-align:top;min-width:200px;" |\n'
				for k2,v2 in pairs ( tasks ) do
					if v1 == v2 then
						s = s .. '{| width=100% style="margin-bottom:10px;"\n| style="border:2px solid ' ..
							priority[k2] .. ';padding:5px;text-align:center;vertical-align:middle;" |[[' ..
							k2 .. ']]\n|}\n'
					end
				end
			end
			if ( missing ) then
				s = s .. '| style="vertical-align:top;min-width:200px;" |\n'
				for k1,v1 in pairs ( tasks ) do
					if v1 == false then
						s = s .. '{| width=100% style="margin-bottom:10px;"\n| style="border:2px solid ' ..
						p.priorityToColor( priority[k1] ) .. ';padding:5px;text-align:center;vertical-align:middle;" |[[' ..
						k1 .. ']]\n|}\n'
					end
				end
			end
			s = s .. '|}'
		end
	end
	return s
end
return p