<%
    # Note that this file is not a valid *.html file!
    # It is intended to be a bottlepy - style template
    # used for the scripting part of TheOnionBox!

    # from tob_template_tools import *

    import psutil
    cpu_count = psutil.cpu_count()

    host = get('host')

%>

{{!header_row('Host', 'General Information', 'host')}}
{{!standard_row('Name', host.name)}}
{{!standard_row('OS', "{} {} (Version: {})".format(host.system, host.release, host.version))}}
{{!standard_row('System', "{} {}".format(host.processor, host.machine))}}

% if host.uptime:
    {{!standard_row('Latest Reboot', host.uptime)}}
% end

{{!standard_row('# of CPU Cores', cpu_count)}}

<div class="row">
    <div class="{{box_datum_grid}}">CPU Usage</div>
    <div class="{{box_value_grid}}">
        <div class="row">
            <div class="col-6">
                <canvas class="processor_chart box_canvas" id="processor_load_0" width="100" height="50"
                        style="vertical-align: middle; {{'cursor: pointer;' if cpu_count > 1 else ''}}"
                        data-toggle="tooltip" data-placement="bottom"
                        title="{{'Click for CPU Core Details!' if cpu_count > 1 else 'CPU Usage'}}">
                </canvas>
            </div>
        </div>
    </div>
    <div class="{{box_right_grid}}"></div>
</div>
<div class="row">
    <div class="{{box_datum_grid}}"></div>
    <div class="{{box_value_grid}}">
        <div id="general_cpu_current" class="box_value_margin">
            Currently:
        </div>
    </div>
    <div class="{{box_right_grid}}"></div>
</div>

{{!standard_row('Memory', "{} MB".format(host.memoryMB))}}

<div class = "row">
    <div class="{{box_datum_grid}}">Memory Usage</div>
    <div class="{{box_value_grid}}">
        <div class="row">
            <div class="col-6">
                <canvas class="processor_chart box_canvas" id="mem_load" width="100" height="50"
                    style="vertical-align: middle;"
                    data-toggle="tooltip" data-placement="bottom"
                    title="Memory Usage (%)">
                </canvas>
            </div>
            <div class="col-6"></div>
        </div>
    </div>
    <div class="{{box_right_grid}}"></div>
</div>
<div class="row">
    <div class="{{box_datum_grid}}"></div>
    <div class="{{box_value_grid}}">
        <div id="general_mem_current" class="box_value_margin">
            Currently:
        </div>
    </div>
    <div class="{{box_right_grid}}"></div>
</div>

% if host.temperature:
    <div class = "row">
        <div class="{{box_datum_grid}}">Temperature</div>
        <div class="{{box_value_grid}}">
            <div class="row">
                <div class="col-6">
                        <canvas class="processor_chart box_canvas" id="temp" width="100" height="50"
                            style="vertical-align: middle;">
                        </canvas>
                </div>
                <div class="col-6"></div>
            </div>
        </div>
        <div class="{{box_right_grid}}"></div>
    </div>
    <div class="row">
        <div class="{{box_datum_grid}}"></div>
        <div class="{{box_value_grid}}">
            <div id="general_temp_current" class="box_value_margin">
                Currently:
            </div>
        </div>
        <div class="{{box_right_grid}}"></div>
    </div>

% end

% if cpu_count > 1:
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <div class="modal-title box_section" id="myModalLabel">
            CPU Core Usage
        </div>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body container">
            % for count in range(cpu_count):
          <div class="row">
              <div class="col-4 box_datum_modal truncate">
                  CPU Core #{{count}}
              </div>
              <div class="col-7 box_value_margin">
                <canvas class="processor_chart box_canvas" id="processor_load_{{count + 1}}" height="50"
                        style="vertical-align: middle; height: 50px;"
                        data-toggle="tooltip" data-placement="bottom"
                        title="CPU#{{count}}: CPU Usage (%)">
                </canvas>
              </div>
              <div class="col-1"></div>
          </div>
            % end
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
% end

<hr>