(function ()
    {
    var module = angular.module('test', []);

    module.controller('TestController', ['$http', '$scope', function ($http, $scope)
        {
        var test = this;
        test.http = $http;
        test.repository = null;
        test.profile = null;
        test.running = false;

        this.isReady = function()
            {
            return test.repository !== null && test.profile !== null;
            };

        this.isRunning = function()
            {
            return test.running;
            };

        this.start = function()
            {
            test.http.post('/controller/loadtest/start?repository=' + test.repository + "&profile=" +test.profile).success(function()
                {
                test.running = true;
                });
            };

        this.stop = function()
            {
            test.http.post('/controller/loadtest/stop').success(function()
                {
                test.running = false;
                });
            };

        $scope.$on('repositoryLoaded', function (event, repository)
            {
            if (repository === "")
                test.repository = null;
            else
                test.repository = repository;
            });

        $scope.$on('profileSelected', function (event, profile)
            {
            if (profile === "")
                test.profile = null;
            else
                test.profile = profile;
            });
        }]);

    })();

	