<!DOCTYPE html>
<html>
<%!
import json
import zlib
import base64

def my_dump(data):
   return base64.b64encode(zlib.compress(json.dumps(data)))
%>
<%
table_data = []

def errors_row(row_name, row, is_wf, hiddenstuff=None):
    bg = ''
    if is_wf:
        if row_name in acted_workflows:
            bg = 'done'
        else:
            bg = 'todo'
    elif hiddenstuff:
        bg = 'step'
        row_name = '/'.join(row_name.split('/')[2:])

    table_data.append({'name': row_name,
                       'row': {'total': row['total'],
                               'errors': row['errors']},
                       'is_wf': is_wf,
                       'hid': hiddenstuff,
                       'bg': bg})

for row_name, row in sorted(errors.items()):
    errors_row(row_name, row, False)
    for row_name_1, row_1 in sorted(row.get('sub', {}).items(), key=lambda x: x[1]['timestamp']):
        errors_row(row_name_1, row_1, True, [0, row_name])
        for row_name_2, row_2 in sorted(row_1.get('sub', {}).items()):
            errors_row(row_name_2, row_2, False, [1, row_name_1])
%>
  <head>
    <title>4D Errors</title>
    <%include file="rotation_tables.html"/>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>
    <link rel="stylesheet" href="static/css/globalerror.css"/>
    <script type="text/javascript" src="static/js/pako_inflate.min.js"></script>
    <script type="text/javascript" src="static/js/expandtable.js"></script>
    <script type="text/javascript" src="static/js/piechart.js"></script>
    <script>
      var pievar = "${pievar}";
      % if pievar != 'sitename':
      var ready = {
      % for icol, col in enumerate(columns):
      ${col} : "${readiness[icol]}",
      % endfor
      };
      % endif
    </script>
  </head>

  <body>
    <table id="errortable" border="3" style="border-collapse: collapse;">
    </table>

    <span id="table-data" style="display:none;">${my_dump(table_data)}</span>

    <div id="wait-message">
      <p>
	Please wait while your browser builds the table.
      </p>

      <p>
	If this takes more than a minute after this message appears, you might have an old version of this page's javascript.
	You can refresh your browser or clear your cache to fix this. You shouldn't have to do that more than once.
      </p>
    </div>

  </body>
</html>
