<?python from decimal import Decimal ?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:py="http://genshi.edgewall.org/"
	xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="layout.html" />
  <xi:include href="macros.html" />
  <head>
    <title>Work Time Management - Reporting</title>
    <link href="${href.chrome('common/css/report.css')}" rel="stylesheet" type="text/css" />
    <link href="${href.chrome('worktime/css/jqplot/jquery.jqplot.min.css')}" rel="stylesheet" type="text/css" />
    <link href="${href.chrome('worktime/css/worktime.css')}" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="${chrome.htdocs_location}js/folding.js"></script>
    <script type="text/javascript" src="${href.chrome('worktime/js/jqplot/excanvas.min.js')}"></script>
    <script type="text/javascript" src="${href.chrome('worktime/js/jqplot/jquery.jqplot.min.js')}"></script>
    <script type="text/javascript" src="${href.chrome('worktime/js/jqplot/jqplot.pointLabels.min.js')}"></script>
    <script type="text/javascript" src="${href.chrome('worktime/js/jqplot/jqplot.barRenderer.min.js')}"></script>
    <script type="text/javascript" src="${href.chrome('worktime/js/jqplot/jqplot.categoryAxisRenderer.min.js')}"></script>
    <script type="text/javascript" src="${href.chrome('worktime/js/jqplot/jqplot.dateAxisRenderer.min.js')}"></script>
    <script type="text/javascript" src="${href.chrome('worktime/js/jqplot/jqplot.cursor.min.js')}"></script>t>
    <script type="text/javascript" src="${href.chrome('worktime/js/jqplot/jqplot.highlighter.min.js')}"></script>
    <script type="text/javascript" src="${href.chrome('worktime/js/dateformat.js')}"></script>
    <script type="text/javascript">
      jQuery(document).ready(function($) {
       $("fieldset legend.foldable").enableFolding(false);
      });
      function updateCalendar() {
        jQuery('#form').attr('action', '${href.worktime('report')}#update_button');
        jQuery('#update_button input').click();
      }
    </script>
  </head>
  <body>
    <div id="content">
      <h1>Work Time レポート</h1>
      
      <form id="form" action="${href.worktime('report')}" method="get">
        <fieldset id="filter">
          <legend class="foldable">設定</legend>
          <table class="list">
            <tbody>
              <tr>
                <td>集計単位</td>
                <td py:with="selectable_ticket_fields=[x for x in ticket_fields if x.name not in ('summary', 'description', 'reporter', 'owner', 'cc', 'status', 'priority', 'resolution', 'keywords')]">
                  <select name="selected_ticket_field">
                   <option value="id" selected="${selected_ticket_field=='id' or None}">チケット</option>
                    <option py:for="x in selectable_ticket_fields" value="${x.name}" selected="${selected_ticket_field==x.name or None}">${x.label}</option>
                  </select>
                </td>
              </tr>
              <tr>
                <td>表示単位</td>
                <td>
                  <input type="radio" checked="${selected_unit=='hours' or None}" value="hours" name="selected_unit" />時間
                  <input type="radio" checked="${selected_unit=='ratio' or None}" value="ratio" name="selected_unit" />割合
                </td>
              </tr>
            </tbody>
          </table>
        </fieldset>
        
        <div id="update_button">
         <input type="submit" value="更新" />
        </div>
        <hr/>
        
        <table id="tree" class="treeTable">
          <thead>
            <tr>
              <th colspan="${3+len(workers)}">
                <div id="calender_selector">
                  <input class="left" type="button" value="&lt;&lt;${prev.month}月"
                         onclick="form.year.value = ${prev.year}; form.month.value = ${prev.month}; form.action = '${href.worktime('report')}#update_button'; form.submit();"/>
                  <select id="year_selector" name="year" onchange="updateCalendar()">
                    <option py:for="y in range(current.year-3,current.year+4)"
                           value="$y"
                           selected="${y==current.year or None}">$y</option>
                  </select>年
                  <select id="month_selector" name="month" onchange="updateCalendar()">
                    <option py:for="m in range(1, 13)"
                           value="$m" selected="${m==current.month or None}">$m</option>
                  </select>月
                  <input class="right" type="button" value="${next.month}月&gt;&gt;"
                         onclick="form.year.value = ${next.year}; form.month.value = ${next.month}; form.action = '${href.worktime('report')}#update_button'; form.submit();"/>
                </div>
              </th>
            </tr>
            <tr>
              <th rowspan="3" style="width: 350px">
                <py:if test="selected_ticket_field=='id'">
                  チケット
                </py:if>
                ${ticket_field_map[selected_ticket_field]}
              </th>
              <th rowspan="2">合計(<py:if test="selected_unit=='hours'">時間</py:if><py:if test="selected_unit=='ratio'">割合</py:if>)</th>
              <th colspan="${len(workers)}">担当者</th>
            </tr>
            <tr>
              <th py:for="worker in workers">
                ${worker}
              </th>
            </tr>
            <tr>
              <th>
                <py:if test="selected_unit=='hours'">${all_sum}</py:if>
                <py:if test="selected_unit=='ratio'">${1.0*len(workers)}</py:if>
              </th>
              <th py:for="worker in workers">
                <py:if test="selected_unit=='hours'">${sum_by_workers[worker]}</py:if>
                <py:if test="selected_unit=='ratio'">1.0</py:if>
              </th>
            </tr>
          </thead>
          <tbody>
            <tr py:for="row in table">
              <td class="group">
                <a py:if="row.name=='id'" href="${req.href.ticket(row.value)}" class="ticket">#${row.value}:${row.summary}</a>
                <a py:if="row.name=='milestone'" href="${req.href.milestone(row.value)}" class="milestone">${row.value}</a>
                <div py:if="row.name not in ['id', 'milestone']">${row.value}</div>
              </td>
              <td>${row.sum}</td>
              <td py:for="worker in workers">
                <py:if test="type(row['__worker__' + worker]) == Decimal"> 
                  ${row['__worker__' + worker]}
                </py:if>
              </td>
            </tr>
          </tbody>
        </table>
        <div py:if="len(table)==0">該当するチケットがありません。</div>
      </form>
    </div>
  </body>
</html>
