  [% META title = 'Resources &raquo; Dashboard View' -%]

<!-- BEGIN [% template.name %] -->
	[% addcss =	[ 'dashboard.css?v1.3' ] %]

    [% # INCLUDE dumper.tt dump = data %]
    [% # INCLUDE dumper.tt dump = data.incomplete_section_tests %]

	[% # some common data blocks:
		lab_test_data = data.incomplete_section_tests %]
    [% BLOCK series_data;
        total = 0;
        FOREACH test IN section.value;
            total = total + data.sum_this(test.value);
        END;
        id = section.key.replace(' ','-').lower;
    %]
        {
            name: '[% section.key %]',
            y: [% total %],
            drilldown: '[% id %]'
        },
    [% END %]

    [% BLOCK drilldown_series_data;
        # '+' chars for html source readability
        # omit trailing comma on data block for IE8-compatibility
    %]
        ['[% test.key %]',[% data.sum_this(test.value) %]][% ',' UNLESS loop.last +%]
    [% END %]

    <script src="/js/highcharts.js"></script>
    <script src="/js/jquery.timeago.js"></script>

    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery("abbr.timeago").timeago();
        });
    </script>

    <form action="[% c.query.self_url %]">
        <div style="margin-top: -10px; text-align: right">Last updated:
            <abbr class="timeago" title="[% USE date; date.format %]">
		    <!--[if IE]>[% date.format %]<![endif]-->
			</abbr>
            <input type='submit' value='Refresh' />
        </div>
    </form>

    <h3 style="margin-top: -5px" class="header">Request status:</h3>

	<div class="indent" id="nav-header">
	  <div>Unreported screened requests:</div>
	  <ul>
	    <li>&gt; [% c.cfg('settings').unreported_duration %] days old
		  [%
			width = data.unreported * 2;
			class = data.unreported ? 'badge badge-my-orange' : 'badge';
		  %]
		  <span class="[% class %]" style="width: [% width %]px;
			min-width: 25px; position: absolute; left: 240px">
			[% data.unreported || 0 %]</span>
		</li>
		<li>tests complete
		  [%
			width = data.tests_completed * 2;
			class = data.tests_completed ? 'badge badge-my-pink' : 'badge';
		  %]
		  <span class="[% class %]" style="width: [% width %]px;
			min-width: 25px; position: absolute; left: 240px">
			[% data.tests_completed || 0 %]</span>
		</li>
	  </ul>

	  [% width = 0; # ( data.unauthorised + data.incomplete ) * 2 # too wide %]
	  <div>Incomplete reported requests:
		<span class="badge" style="width: [% width %]px; min-width: 25px">
		  [% ( data.unauthorised || 0 ) + ( data.incomplete || 0 ) %]</span>
	  </div>
	  <ul>
	    <li>unauthorised
		  [%
			width = data.unauthorised * 2;
			class = data.unauthorised ? 'badge badge-info' : 'badge';
		  %]
		  <span class="[% class %]" style="width: [% width %]px; min-width: 25px;
			position: absolute; left: 240px">[% data.unauthorised || 0 %]</span>
		</li>
		<li>authorised &nbsp;&nbsp;&nbsp;
		  [%
			width = data.incomplete * 2;
			class = data.incomplete ? 'badge badge-my-purple' : 'badge';
		  %]
		  <span class="[% class %]" style="width: [% width %]px; min-width: 25px;
			position: absolute; left: 240px">[% data.incomplete || 0 %]</span>
		</li>
	  </ul>
	</div>

    <!-- Buttons -->
    <ul class="nav nav-pills">

	[% BLOCK urgent %]
        <i class="fa fa-taxi"></i> Urgent
        <span class="label label-[% data.urgent ? 'my-red' : 'inverse' %]">
			[% data.urgent || 0 %]</span>
	[% END; BLOCK unscreened %]
        <i class="fa fa-th-list"></i> Unscreened
        <span class="label label-[% data.unscreened ? 'my-green' : 'inverse' %]">
			[% data.unscreened || 0 %]</span>
	[% END; BLOCK unreported %]
        <i class="fa fa-plug"></i> Unreported
			&gt;[% c.cfg('settings').unreported_duration %]d
        <span class="label label-[% data.unreported ? 'my-orange' : 'inverse' %]">
			[% data.unreported || 0 %]</span>
	[% END; BLOCK tests_completed %]
	    <i class="fa fa-chain"></i> Tests complete
        <span class="label label-[% data.tests_completed ? 'my-pink' : 'inverse' %]">
			[% data.tests_completed || 0 %]</span>
	[% END; BLOCK unauthorised %]
        <i class="fa fa-tags"></i> Unauthorised
        <span class="label label-[% data.unauthorised ? 'info' : 'inverse' %]">
			[% data.unauthorised || 0 %]</span>
	[% END; BLOCK incomplete %]
	    <i class="fa fa-fax"></i> Incomplete
        <span class="label label-[% data.incomplete ? 'my-purple' : 'inverse' %]">
			[% data.incomplete || 0 %]</span>
	[% END %]

    <!-- Comment button with number of latest comments count -->
        <li class="indent">
		  [% IF data.urgent %]
            <a href="[% app_url %]/worklist/request_status?status_query=urgent">
				[% INCLUDE urgent %]
            </a>
		  [% ELSE %]<div>[% INCLUDE urgent %]</div>[% END %]
        </li>
        <li>
		  [% IF data.unscreened %]
            <a href="[% app_url %]/worklist/request_status?status_query=unscreened">
				[% INCLUDE unscreened %]
            </a>
		  [% ELSE %]<div>[% INCLUDE unscreened %]</div>[% END %]
        </li>
        <li>
		  [% IF data.unreported %]
            <a href="[% app_url %]/worklist/request_status?status_query=unreported">
				[% INCLUDE unreported %]
            </a>
		  [% ELSE %]<div>[% INCLUDE unreported %]</div>[% END %]
        </li>
        <li>
		  [% IF data.tests_completed %]
            <a href="[% app_url %]/worklist/request_status?status_query=tests_completed">
				[% INCLUDE tests_completed %]
            </a>
		  [% ELSE %]<div>[% INCLUDE tests_completed %]</div>[% END %]
        </li>
        <li>
		  [% IF data.unauthorised %]
            <a href="[% app_url %]/worklist/request_status?status_query=unauthorised">
				[% INCLUDE unauthorised %]
            </a>
		  [% ELSE %]<div>[% INCLUDE unauthorised %]</div>[% END %]
        </li>
        <li>
		  [% IF data.incomplete %]
            <a href="[% app_url %]/worklist/request_status?status_query=incomplete">
				[% INCLUDE incomplete %]
            </a>
		  [% ELSE %]<div>[% INCLUDE incomplete %]</div>[% END %]
        </li>
    </ul>

  [% IF data.local_dashboard; # only set in controller if local_dashboard.yml exists
	centre = c.cfg('settings').item('_centre') || argv; # argv from index.html ssi exec cmd
	# tt_dir = c.cfg('path_to_app_root') _ '/templates/resources/dashboard/local';
	# TRY; USE File("${tt_dir}/.${centre}"); # don't need this if testing for data.local_dashboard
	# CATCH File; skip_local_dashboard = 1; END; # skip_local_dashboard = 'true' if no file
	PROCESS "resources/dashboard/local/.${centre}"; # UNLESS skip_local_dashboard;
	END;
  %]

   <h3 class="header">Incomplete lab-tests:</h3>

    <p class="title indent">Lab sections - incomplete tests:
	  [% div_name = 'incomplete'; INCLUDE site/snippets/toggleview.tt %]
	</p>

	<!-- drilldown chart needs initial display = itemshow or get miniture chart size -->
    <div id="[% div_name %]" class="indent itemshow">
	  [% INCLUDE resources/dashboard/drilldown.tt %]
	</div>

[% IF needed # same data as 'Lab sections - incomplete tests' display after drilldown %]
    <p class="title indent">Lab sections - totals for lab-tests:
      [% div_name = 'test-totals'; INCLUDE site/snippets/toggleview.tt %]</p>
    <div id="[% div_name %]" class="indent itemhidden">
	  [% INCLUDE resources/dashboard/test_totals.tt %]</div>
[% END %]

    <p class="title indent">Lab sections - lab-test status:
      [% div_name = 'tests-status'; INCLUDE site/snippets/toggleview.tt %]
    </p>

    <div id="[% div_name %]" class="indent itemhidden">
		[% INCLUDE resources/dashboard/test_status.tt %]
	</div>

<!-- END [% template.name %] -->
