otsApp.controller('runningController', ['$scope', '$http', 'eventSubscriptionService', 'testCommands', 'testErrors', function ($scope, $http, eventSubscriptionService, testCommands, testErrors)
{
	testErrors.clearAll();
    $scope.stopTest = testCommands.stopTest;

    // listen for changes to test status
    $scope.test_status = {};
    eventSubscriptionService.subscribe('LoadtestStatus', function(message)
    {
        $scope.$apply(function () // this ensures the changes get applied
        {
            $scope.test_status = JSON.parse(message.data);
        });
    });

    // listen for changes to metrics
    $scope.METRIC_ID = METRIC_IDS;
    $scope.metrics = {};
    $scope.metrics.summary = {};
    eventSubscriptionService.subscribe('SummaryMetrics', function(message)
        {
        $scope.metrics.summary = JSON.parse(message.data);
        $scope.errors = testErrors();
        });

    // get the test config
    $scope.testconfig = {};
    $http({method: 'GET', url: '/controller/testconfig'}).success(function (data)
        {
        $scope.testconfig = data; // response data
        });

    // setup the panel tab controls
    $scope.panel_control = {};
    $scope.panel_control.current_tab = 1;
    $scope.panel_control.selectTab = function (new_tab)
        {
        $scope.panel_control.current_tab = new_tab;
        };
    $scope.panel_control.isSelected = function (checkTab)
        {
        return $scope.panel_control.current_tab === checkTab;
        };
}]);
