/*
 *	aegis - project change supervisor
 *	Copyright (C) 1994, 1995, 1997, 2001, 2002, 2006-2008 Peter Miller
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program. If not, see
 *	<http://www.gnu.org/licenses/>.
 */

auto p, ps, name, staff;
p = project[project_name()];
title("The Project Staff Report", sprintf("Project \"%s\"", p.name));
columns
(
    { name = "Login\n--------"; width = 8; padding = 2; },
    { name = "Full Name\n-----------"; width = 20; },
    { name = "Developer\n----------"; width = 10; },
    { name = "Reviewer\n----------"; width = 10; },
    { name = "Integrator\n----------"; width = 10; },
    { name = "Administrator\n-------------"; width = 13; }
);
ps = p.state.branch;
for (name in ps.developer)
    staff[name].developer = true;
for (name in ps.reviewer)
    staff[name].reviewer = true;
for (name in ps.integrator)
    staff[name].integrator = true;
for (name in ps.administrator)
    staff[name].administrator = true;

auto cn, cs, h;
for (cn in keys(ps.change))
{
    cs = ps.change[cn];
    for (h in cs.history)
    {
       	if (h.what == new_change)
	    staff[h.who].administrator_count++;
       	else if (h.what == develop_begin)
       	{
	    staff[h.who].developer_count++;
	    if (h.forced != "")
	     	staff[h.forced].administrator_count++;
       	}
       	else if (h.what == review_pass || h.what == review_fail)
	    staff[h.who].reviewer_count++;
       	else if (h.what == integrate_begin)
	    staff[h.who].integrator_count++;
    }
}

for (name in sort(keys(staff)))
{
    auto s, cmnt;
    s = staff[name];
    if (s.developer && !s.developer_count)
       	s.developer_count = 0;
    if (s.reviewer && !s.reviewer_count)
       	s.reviewer_count = 0;
    if (s.integrator && !s.integrator_count)
       	s.integrator_count = 0;
    if (s.administrator && !s.administrator_count)
       	s.administrator_count = 0;
    try { cmnt = passwd[name].pw_comment; } catch (cmnt) { cmnt = ""; }
    print
    (
       	name,
       	cmnt,
       	sprintf
	(
	    "%7s",
	    (
	     	(
		    !s.developer && !s.developer_count
	     	?
		    ""
	     	:
		    (s.developer_count + 0)
	     	)
	    ##
	     	(!s.developer && s.developer_count ? "-" : " ")
	    )
       	),
       	sprintf
       	(
	    "%7s",
	    (
	     	(
		    !s.reviewer && !s.reviewer_count
	     	?
		    ""
	     	:
		    (s.reviewer_count + 0)
	     	)
	    ##
	     	(!s.reviewer && s.reviewer_count ? "-" : " ")
	    )
       	),
       	sprintf
       	(
	    "%7s",
	    (
	     	(
		    !s.integrator && !s.integrator_count
	     	?
		    ""
	     	:
		    (s.integrator_count + 0)
	     	)
	    ##
	     	(!s.integrator && s.integrator_count ? "-" : " ")
	    )
       	),
       	sprintf
       	(
	    "%7s",
	    (
	     	(
		    !s.administrator && !s.administrator_count
	     	?
		    ""
	     	:
		    (s.administrator_count + 0)
	     	)
	    ##
	     	(!s.administrator && s.administrator_count ? "-" : " ")
	    )
       	)
    );
}
