<!DOCTYPE html>
<html lang="en" ng-app="app" ng-strict-di>
<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 -->
    <title>Grab Api</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <style>
    </style>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.min.js"></script>
    <script src="http://angular-ui.github.io/ui-router/release/angular-ui-router.min.js"></script>
<script>
(function() {
    'use strict'

    angular
        .module('app', [
            'ui.router',
            'ngResource',
            'app.dashboard'
        ]);

    angular
        .module('app.dashboard', [])
        .config([
            '$stateProvider',
            '$urlRouterProvider',
            function($stateProvider, $urlRouterProvider) {
                $urlRouterProvider.otherwise('/info');
                $stateProvider
                    .state('info', {
                        url: '/info',
                        template: $('#template-info').html(),
                        controller: ['$resource', '$scope', function($resource, $scope) {
                            $resource('/api/info').get({}, function(data) {
                                $scope.data = data;
                            });
                        }],
                    })
                    .state('stop', {
                        url: '/stop',
                        controller: ['$resource', function($resource) {
                            $resource('/api/stop').get({}, function() {
                            });
                        }],
                        template: $('#template-stop').html()
                    });
        }]);
})();
/*
$.get(location.href + 'api/info', {}, function(data) {
    html = ''
    $.each(data['counters'], function(key, value){
        html += '<p>' + key + ':' + value + '</p>'
    });
    $('#body').html(html);
}, 'json');
*/
</script>
</head>
<body>
    <div style="display: none">
        <div id="template-info">
            <div class="row">
                <div class="col-md-4">
                    <h3>Counters</h3>
                    <div ng-repeat="(key, val) in data.counters">
                        <div>{{ key }}: {{ val }}</div>
                    </div>
                </div>
                <div class="col-md-4">
                    <h3>Collections</h3>
                    <div ng-repeat="(key, val) in data.collections">
                        <div>{{ key }}: {{ val }}</div>
                    </div>
                </div>
                <div class="col-md-4">
                    <h3>Info</h3>
                    <div>Network threads: {{ data.thread_number }}</div>
                    <div>Parser processes: {{ data.parser_pool_size }}</div>
                    <div>Task queue: {{ data.task_queue }}</div>
                    <div>Task dispatcher input q.: {{ data.task_dispatcher_input_queue }}</div>
                    <div>Parser service input q.: {{ data.parser_service_input_queue }}</div>
                    <div>Network service active threads: {{ data.network_service_active_threads }}</div>
                    <div>Cache reader input queue: {{ data.cache_reader_input_queue }}</div>
                    <div>Cache writer input queue: {{ data.cache_writer_input_queue }}</div>
                </div>
            </div>
        </div>

        <div id="template-stop">
            <p>Stop request sent</p>
        </div>

    </div>
    <nav class="navbar navbar-default">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse"
                    data-target="#navbar-collapse">
                    <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="#/info">Grab::Spider</a>
            </div>

            <div class="collapse navbar-collapse" id="navbar-collapse">
                <ul class="nav navbar-nav navbar-left">
                    <li ui-sref-active="active"><a ui-sref="info">Info</a></li>
                    <li ui-sref-active="active">
                        <a href="#" onclick="if (confirm('Are you sure you want to stop spider?')) {
                            location.href='#/stop'}; return false">Stop spider</a>
                        <span style="display: none"><a ui-sref="stop"></a></span>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div ui-view></div>
            </div>
        </div>
    </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</body>
</html>
