Module:CDP Tasks: Difference between revisions

From atwg
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 21: Line 21:


function p.buildDependencyGraph()
function p.buildDependencyGraph()
local tasks = mw.smw.getQueryResult( '[[Category:Tasks]][[Archived::!true]]' ..
local tasks = mw.smw.getQueryResult( '[[Category:Tasks]][[Archived::!true]]|?Primary Team' ..
'|?Depends On Task' ..
'|?Depends On Task' ..
'|?End Year' )
'|?End Year' )
Line 35: Line 35:
local task_name = string.gsub( v.fulltext, ':', '' )
local task_name = string.gsub( v.fulltext, ':', '' )
s = s .. task_name .. ' [URL="[[' .. v.fulltext .. ']]", label='
s = s .. task_name .. ' [URL="[[' .. v.fulltext .. ']]", label='
s = s .. p.label( v.displaytitle )
local team = table.concat( v.printouts['Primary Team'], ', ' )
if ( #team > 0 ) then
team = '<BR/>(' .. team .. ')'
else
team = ''
end
s = s .. p.label( v.displaytitle .. team )
if table.concat( v.printouts['End Year'] ) == '0' then
if table.concat( v.printouts['End Year'] ) == '0' then
s = s .. ', color=darkgreen, fontcolor=darkgreen'
s = s .. ', color=darkgreen, fontcolor=darkgreen'

Latest revision as of 10:15, 13 February 2018

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

local p = {}

function p.wrap( s, length )
	s = mw.text.trim( s )
	local oldindex = 1
	local index = string.find( s, ' ' )
	while ( index ) do
		if ( index - oldindex >= length ) then
			local temp = string.sub( s, 1, index - 1 ) .. '<BR/>' .. string.sub( s, index + 1 )
			s = temp
			oldindex = index + 4
		end
		index = string.find( s, ' ', index + 1)
	end
	return s
end

function p.label( s )
	return '<<TABLE BORDER="0"><TR><TD>' .. p.wrap( s, 30 ) .. '</TD></TR></TABLE>>'
end

function p.buildDependencyGraph()
	local tasks = mw.smw.getQueryResult( '[[Category:Tasks]][[Archived::!true]]|?Primary Team' ..
		'|?Depends On Task' ..
		'|?End Year' )
    if tasks == nil then
    	return ''
    end
	local s = 'digraph tasks'
	s = s .. ' {\n'
	s = s .. 'rankdir=LR;\n'
	s = s .. 'node [shape=box, fontsize=10, fontname="Arial bold"];\n'
	s = s .. 'edge [color=gray75];\n'
	for k,v in pairs( tasks.results ) do
		local task_name = string.gsub( v.fulltext, ':', '' )
		s = s .. task_name .. ' [URL="[[' .. v.fulltext .. ']]", label='
		local team = table.concat( v.printouts['Primary Team'], ', ' )
		if ( #team > 0 ) then
			team = '<BR/>(' .. team .. ')'
		else
			team = ''
		end
		s = s .. p.label( v.displaytitle .. team )
		if table.concat( v.printouts['End Year'] ) == '0' then
			s = s .. ', color=darkgreen, fontcolor=darkgreen'
		end
		s = s .. '];\n'
	end
	for k1,v1 in pairs( tasks.results ) do
		local target_task_name = string.gsub( v1.fulltext, ':', '' )
		for k2,v2 in pairs( v1.printouts['Depends On Task'] ) do
			local source_task_name = string.gsub( v2.fulltext, ':', '' )
			s = s .. source_task_name .. '->' .. target_task_name .. '\n'
		end
	end
	s = s .. '}\n'
	return s
end

function p.showDependencyGraph(frame)
	local s = p.buildDependencyGraph()
	return frame:callParserFunction{ name = '#tag', args = { 'graphviz', format='png', s } }
end

return p