<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
        <script src="{{ mix('/js/app.js') }}"></script>

        <!-- Styles -->
        <style>
            html, body {
                background-color: #fff;
                color: #636b6f;
                font-family: 'Raleway', sans-serif;
                font-weight: 100;
                height: 100vh;
                margin: 0;
            }

            .full-height {
                height: 100vh;
            }

            .flex-center {
                align-items: center;
                display: flex;
                justify-content: center;
            }

            .position-ref {
                position: relative;
            }

            .top-right {
                position: absolute;
                right: 10px;
                top: 18px;
            }

            .content {
                text-align: center;
            }

            .title {
                font-size: 84px;
            }

            .links > a {
                color: #636b6f;
                padding: 0 25px;
                font-size: 12px;
                font-weight: 600;
                letter-spacing: .1rem;
                text-decoration: none;
                text-transform: uppercase;
            }

            .m-b-md {
                margin-bottom: 30px;
            }

            .chart {
                width: 100%;
                height: 300px;
            }
        </style>
    </head>
    <body>
        <div class="flex-center position-ref full-height">
            @if (Route::has('login'))
                <div class="top-right links">
                    @auth
                        <a href="{{ url('/home') }}">Home</a>
                    @else
                        <a href="{{ route('login') }}">Login</a>
                        <a href="{{ route('register') }}">Register</a>
                    @endauth
                </div>
            @endif

            <div class="content">
                <div class="title m-b-md">
                    Monitoring on OkU TT
                </div>

                <div class="links">
                    <a href="{{ url('/search') }}">Search</a>
                </div>

                <div class="links">
                    <a href="{{ url('/graph/network') }}">Network</a>
                    <a href="{{ url('/graph/temp') }}">Temperature</a>
                    <a href="{{ url('/graph/memory') }}">Memory</a>
                    <a href="{{ url('/graph/load') }}">Load</a>
                    <a href="{{ url('/graph/disk') }}">Disk</a>
                    <a href="{{ url('/graph/processes') }}">Processes</a>
                </div>

                <div id="app">
                        <network-graph :raw_data="chartData" />
                </div>

                  <script>
                    var settings = { "network": { name:"Network",prefix: "netstat",suffix: { "recv": "Received", "sent": "Send Bytes" }, units:"B"},
                                      "temp": {name:"Temerature",prefix: null,units:"C"},
                                      "memory": {name:"Memory",prefix:"memory", suffix: {"free":"Free Memory", "total": "Total Memory","used":"Used Memory"},units: "KB"},
                                      "load": {name:"System Load",prefix:null, units:"%"},
                                      "disk": {name:"Disk utilization",prefix:"disk",suffix: {"free":"Free Memory", "total": "Total Memory","used":"Used Memory"}, units:"MB"},
                                      "processes": {name:"Number of processes",prefix: null,units:""}};


                    axios.get('/data', {
                        params: {
                        computer_id: 1,
                        from: '2020-03-10'
                        }
                    })
                    .then(function (response) {
                        var data = response.data;
                        var index;
                        
                        for (index = 0; index < data.length; ++index) {
                            var row = data[index];
                            for (var sk in settings) {

                                for (var k in settings[sk].suffix) {
                                    key = settings[sk].prefix + '_' + k;
                                    label = row["created_at"];
                                    value = row[key];
                                    

                                    nr = { label: label, value: value};
                                    if (!settings[sk].hasOwnProperty('d4')) settings[sk].d4 = {};
                                    if (!settings[sk].d4.hasOwnProperty(k)) settings[sk].d4[k] = [];
                                    settings[sk].d4[k].push(nr);
                                }

                            }
                        }
                        
                        for (var k1 in settings) {
                            d = [];
                            for (var k2 in settings[k1].d4) {
                                name = settings[k1].suffix[k2];
                                d.push({name: name, data: settings[k1].d4[k2]});
                            }
                            settings[k1].data = d;
                        }

                        var app = new Vue({
                            el: "#app",
                            data: {
                                chartData: data
        
                            }
                        })


                     })
                    .catch(function (error) {
                        console.log(error);
                    });

                    
                  </script>

                @section('content')
                    <p></p>
                @show
            </div>
        </div>
    </body>
</html>
