<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Henry POC</title>

    <!-- BOOTSTRAP -->
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- END BOOTSTRAP -->

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this scaffold -->
    <link href="{{request.static_url('pocwww:static/theme.css')}}" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
    <script src="https://d3js.org/d3.v3.js"></script>
    <script src="{{request.static_url('pocwww:static/moment.min.js')}}"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
    <script type="text/javascript" src="{{request.static_url('pocwww:static/graphs.js')}}"></script>
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/"><span id="shake-status"></span> | Henry POC</a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li {% if (navgroup == 'dashboard') %}class="visible-xs-inline active" {% else %} class="visible-xs-inline" {% endif %}><a href="/">Dashboard</a></li>
                    <li {% if (navgroup == 'cards') %}class="visible-xs-inline active" {% else %} class="visible-xs-inline" {% endif %}><a href="/cards">Cards</a></li>
                    <li {% if (navgroup == 'values') %}class="visible-xs-inline active" {% else %} class="visible-xs-inline" {% endif %}><a href="/values">Values</a></li>
                    <li {% if (navgroup == 'gaugeoff') %}class="visible-xs-inline active" {% else %} class="visible-xs-inline" {% endif %}><a href="/gaugeoff">Gauge-Off</a></li>
                    <li {% if (navgroup == 'fluidshots') %}class="visible-xs-inline active" {% else %} class="visible-xs-inline" {% endif %}><a href="/fluidshots">Fluid Shots</a></li>
                    <li {% if (navgroup == 'welltests') %}class="visible-xs-inline active" {% else %} class="visible-xs-inline" {% endif %}><a href="/welltests">Well Tests</a></li>
                    {% if request.authenticated_userid %}
                        <li {% if (navgroup == 'setpoints') %}class="active"{% endif %}><a href="/setpoints">Setpoints</a></li>
                        <li {% if (navgroup == 'config') %}class="active"{% endif %}><a href="/config">Well Setup</a></li>
                        <li><a href="/register">{{request.authenticated_userid}}</a></li>
                        <li><form class="navbar-form"><div class="form-group"><a href="{{request.route_url('auth',action='out')}}" class="btn btn-warning">Sign Out</a></div></form></li>
                    {% else %}
                        <form action="{{request.route_url('auth',action='in')}}" method="post" class="form-inline navbar-form">
                            <div class="form-group">
                                <input type="text" name="username" class="form-control" placeholder="Username">
                            </div>
                            <div class="form-group">
                                <input type="password" name="password" class="form-control" placeholder="Password">
                            </div>
                            <div class="form-group">
                                <input type="submit" value="Sign in" class="btn btn-default">
                            </div>
                        </form>
                    {% endif %}</li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-3 col-md-2 sidebar">
                <div style="text-align:center">
                    <h3 class="allcaps"><a href="/runstatus">Run Status</a></h3>
                    <h4><span id="runstatus"></span></h4>
                    <p>at</p>
                    <h5><span id="runstatustimestamp"></span></h5>
                    {% if request.authenticated_userid %}
                        <button onclick="start()" class="btn btn-success">Start</button>
                        <button onclick="stop()" class="btn btn-danger">Stop</button>
                    {% endif %}
                </div>
                <hr />
                <ul class="nav nav-sidebar">
                    <li {% if (navgroup == 'dashboard') %}class="active"{% endif %}><a href="/">Dashboard</a></li>
                    <li {% if (navgroup == 'cards') %}class="active"{% endif %}><a href="/cards">Cards</a></li>
                    <li {% if (navgroup == 'values') %}class="active"{% endif %}><a href="/values">Values</a></li>
                    <li {% if (navgroup == 'gaugeoff') %}class="active"{% endif %}><a href="/gaugeoff">Gauge-Off</a></li>
                </ul>
                <ul class="nav nav-sidebar">
                    <li {% if (navgroup == 'fluidshots') %}class="active"{% endif %}><a href="/fluidshots">Fluid Shots</a></li>
                    <li {% if (navgroup == 'welltests') %}class="active"{% endif %}><a href="/welltests">Well Tests</a></li>
                </ul>

                {% block card_dates %}
                {% endblock card_dates %}

                {% block cards %}
                {% endblock cards %}

            </div>
            <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
                {% block content %}
                <p>No content</p>
                {% endblock content %}
            </div>
        </div>
    </div>


</body>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->

<script>

function setRunStatus(data){
    $("#runstatus").text(data.runstatus.status);
    $("#db-runstatus").text(data.runstatus.status);
    var ts_date = new Date(Date.parse(data.runstatus.timestamp.replace(" ", "T")));
    $("#runstatustimestamp").text(ts_date.toString());
    $("#db-runstatustimestamp").text(ts_date.toString());
}
function getRunStatus(){
    $.ajax({
        dataType: 'json',
        url: "/json/runstatusnow",
        success: setRunStatus
    });
};
getRunStatus();

function start(){
    $.ajax({
        dataType: 'json',
        url: "/json/cmd/start",
        success: getRunStatus
    });
}

function stop(){
    $.ajax({
        dataType: 'json',
        url: "/json/cmd/stop",
        success: getRunStatus
    });
}

function shakeOK(){
    $('#shake-status').html('<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>')
}

function shakeFail(){
    $('#shake-status').html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>')
}

function shake(){
    $.ajax({
        dataType: 'json',
        url: "/json/cmd/shake",
        success: shakeOK,
        error: shakeFail
    });
}
shake();

setInterval(function() {
  getRunStatus();
  shake();
}, 10000);

</script>

</html>
