<!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>Server is running</title>

    <!-- Bootstrap core CSS -->
    <link href="{{ url_for('static',filename='css/bootstrap.min.css') }}" rel="stylesheet">


    <!-- Custom styles for this template -->
    <link href="{{ url_for('static',filename='css/dashboard.css') }}" rel="stylesheet">

    <link rel="stylesheet" type="text/css" href="{{url_for('static',filename='css/dataTables.css')}}">


  </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">111</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#">Dashboard</a></li>
            <li><a href="#">Settings</a></li>
            <li><a href="#">Profile</a></li>
            <li><a href="#">{{name}}</a></li>
            <li><a href="/logout">Logout</a> </li>
          </ul>
          <form class="navbar-form navbar-right">
            <input type="text" class="form-control" placeholder="Search...">
          </form>
        </div>
      </div>
    </nav>

    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
          <ul class="nav nav-sidebar">
            <li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li>
            <li><a href="#">Reports</a></li>
            <li><a href="#">Analytics</a></li>
            <li><a href="#">Export</a></li>
          </ul>
          <ul class="nav nav-sidebar">getUncheckimageName
            <li><a href="">Nav item</a></li>
            <li><a href="">Nav item again</a></li>
            <li><a href="">One more nav</a></li>
            <li><a href="">Another nav item</a></li>
            <li><a href="">More navigation</a></li>
          </ul>
          <ul class="nav nav-sidebar">
            <li><a href="">Nav item again</a></li>
            <li><a href="">One more nav</a></li>
            <li><a href="">Another nav item</a></li>
          </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          <h1 class="page-header">状态监控</h1>

          <div class="row placeholders">
            <div class="col-xs-6 col-sm-3 placeholder">
              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
              <h4>登录状态</h4>
              <span id="loginsts" class="text-muted">Something else</span>
            </div>
            <div class="col-xs-6 col-sm-3 placeholder">
              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
              <h4>Label</h4>
              <span class="text-muted">Something else</span>
            </div>
            <div class="col-xs-6 col-sm-3 placeholder">
              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
              <h4>Label</h4>
              <span class="text-muted">Something else</span>
            </div>
            <div class="col-xs-6 col-sm-3 placeholder">
              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
              <h4>Label</h4>
              <span class="text-muted">Something else</span>
            </div>
          </div>

          <h2 class="sub-header">Section title</h2>
          <div class="table-responsive">
            <table id="table_id_example" class="display">
              <thead>
                  <tr>
                      <th>ID</th>
                      <th>时间</th>
                      <th>状态</th>

                  </tr>
              </thead>
              <tbody>

              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="{{ url_for('static',filename='js/jquery.min.js') }}"></script>
    <script>window.jQuery || document.write('<script src="static/js/jquery.min.js"><\/script>')</script>
    <script src="{{ url_for('static',filename='js/bootstrap.min.js') }}"></script>
    <!-- DataTables -->
    <script type="text/javascript" charset="utf8" src="{{url_for('static',filename='js/dataTables.js')}}"></script>
    <script type="text/javascript">
            var num;
            num = 1;
            var loginsts;
            $(document).ready(function () {
              getflightdata();
              inittable();
              postgresql();
              var table
              var loginsts
              setInterval("backupdata()",300000)
              setInterval("postgresql()",60000)
              setInterval("getflightdata()",30000)
              setInterval("updatatable()",60000)

            });
            function backupdata(){
              $.get('/bakupdata', function (data) {
                console.log(data)
              });
            }
            function postgresql(){
              $.get('/postgresql', function (data) {
                console.log(data)
              });
            }
            function getflightdata(){
              console.log(num)
              if (num % 3 == 0) {
                checkLogin()
                if (loginsts == '1') {
                  $.get('/getFlightData2/A', function (data) {
                    console.log(data)
                  });
                  console.log("A请求")
                  num += 1
                }
              }
              else{
                $.get('/getFlightData2/B', function (data) {
                  console.log(data)
                });
                console.log("B请求")
                num += 1
              }
            }

            function inittable(){
              table = $('#table_id_example').DataTable({
                ajax: {
                    url: '/table',
                    type: 'get',
                },
              });
            }
            function updatatable(){
              table.clear()
              $.get('/table', function(data){
                table.rows.add(data['data'])
                table.draw()
              })

            }
            function checkLogin(){
              $.get('/checkLogin', function(data){
                console.log(data)
                if (data['msg'] == '1'){
                  console.log('已登录')
                  $('#loginsts').text('已登录')
                  loginsts = data['msg']
                }
                else{
                  console.log('未登录')
                  $('#loginsts').text('未登录')
                  var txt1="<a href='/login'> 点击登录</a>";
                  $('#loginsts').append(txt1)
                  loginsts = data['msg']
                }
              })
            }
    </script>


  </body>
</html>
