/* global app:true Chart:true */
(function (angular, app, Chart) { 'use strict';

    var controller = 'DashboardController';

    if (typeof app === 'undefined') throw (controller + ': app is undefined');

    Chart.defaults.global.defaultFontColor = '#9db4be';
    Chart.defaults.global.defaultFontStyle = 'bold';

    var createChart = function (container, data) {
        if (typeof data.options === 'undefined') data.options = {responsive: true, scales: {xAxes: [{ticks: {beginAtZero: true}}]}};

        return new Chart (angular.element(container)[0].getContext('2d'), data);
    };

    app.controller(controller, ['$scope', 'ajax', 'toast', 'viewFactory', function ($scope, ajax, toast, viewFactory) {

        viewFactory.title = 'Dashboard';
        viewFactory.prevUrl = null;

        $scope.refreshTimer = function(master) {

            ajax.get({ resource: '/' }).then(function (response) {
                $scope.kongStat = response.data;
                $scope.database = $scope.kongStat.configuration.database;

                createChart('#timersChart', {
                    type: 'horizontalBar',
                    data: { labels: ['Running', 'Pending'], datasets: [{
                        data: [$scope.kongStat.timers.running, $scope.kongStat.timers.pending],
                        label: 'Timers', backgroundColor:['#10C469', '#FFCE56']
                    }] }
                });

                if(!master || master !== true)
                    toast.success('Timers data has been updated');

            }, function () {
                toast.error('Could not populate data');
            });

        };


        $scope.refreshStatus = function(master) {

            ajax.get({ resource: '/status' }).then(function (response) {
                var server = response.data.server;

                createChart('#clusterStatChart', {
                    type: 'bar',
                    data: { labels: ['Handled', 'Accepted', 'Active', 'Waiting', 'Reading', 'Writing'], datasets: [{
                        data: [server.connections_handled, server.connections_accepted, server.connections_active,
                            server.connections_waiting, server.connections_reading, server.connections_writing],
                        backgroundColor: ['rgba(24, 138, 226, 0.5)', 'rgba(16, 196, 105, 0.5)', 'rgba(128, 197, 218, 0.5)',
                            'rgba(248, 142, 15, 0.5)', 'rgba(207, 32, 241, 0.5)', 'rgba(91, 105, 188, 0.5)'],
                        borderColor: ['#188AE2', '#10C469', '#80C5DA', '#F88E0F', '#CF20F1', '#5B69BC'],
                        borderWidth: 1, label: 'Connections'
                    }] }
                });

                if(!master || master !== true)
                    toast.success('Node Status data has been updated');

            }, function () {
                toast.error('Could not populate chart data');
            });

        };


        $scope.refreshStatus(true);
        $scope.refreshTimer(true);

    }]);

})(window.angular, app, Chart);
@@ -74,24 +74,25 @@
 trict';%0A
-%0A
     
-var
+const
  control
@@ -120,17 +120,16 @@
 oller';%0A
-%0A
     if (
@@ -314,19 +314,19 @@
 ';%0A%0A    
-var
+let
  createC
@@ -700,25 +700,24 @@
 wFactory) %7B%0A
-%0A
         view
@@ -823,33 +823,32 @@
 ction(master) %7B%0A
-%0A
             ajax
@@ -1627,33 +1627,32 @@
 );%0A%0A        %7D;%0A%0A
-%0A
         $scope.r
@@ -1685,17 +1685,16 @@
 ster) %7B%0A
-%0A
         
@@ -1778,11 +1778,11 @@
     
-var
+let
  ser
@@ -2925,17 +2925,16 @@
     %7D;%0A%0A
-%0A
         
@@ -2993,24 +2993,24 @@
 mer(true);%0A%0A
+
     %7D%5D);%0A%0A%7D)
@@ -3006,17 +3006,16 @@
    %7D%5D);%0A
-%0A
 %7D)(windo

use let to declare iterators