CaffGeek/MBACNationals

View on GitHub
Web.Admin/AdminApp/Controllers/controller.practice.js

Summary

Maintainability
A
2 hrs
Test Coverage
(function () {
    "use strict";

    var practiceController = function ($scope, $http, $q, $location, dataService) {
        var url = $location.absUrl();
        var lastSlash = url.lastIndexOf('/');
        var province = url.slice(lastSlash + 1);
        var year = url.slice(lastSlash - 4, lastSlash);

        $scope.model = {
            province: province,
            allowedTimes : [],
            teams: [],
            practiceLocations: []
        };

        //TODO: Move to some config per year...
        if (year == 2014) {
            $scope.model.allowedTimes = [9, 10, 11, 12, 13, 14, 15];
            $scope.model.practiceLocations = ['Rossmere', 'Academy', 'Coronation'];
        }
        else if (year == 2015) {
            $scope.model.allowedTimes = [11, 12, 13, 14, 15, 16];
            $scope.model.practiceLocations = ['Sherwood'];
        }
        else if (year == 2016) {
            $scope.model.allowedTimes = [11, 12, 13, 14, 15, 16];
            $scope.model.practiceLocations = ['Willowbrook', 'Scottsdale', 'Clover'];
        }
        else if (year == 2019) {
            $scope.model.allowedTimes = [13, 14, 15];
            $scope.model.practiceLocations = ['Anik', 'Paris', 'Kingpin'];
        }
        else if (year == 2022) {
            $scope.model.allowedTimes = [11, 12, 13, 14];
            $scope.model.practiceLocations = ['Bonnie Doon'];
        }

        if (year && province) {
            dataService.LoadPracticePlan(year, province).
                success(function (contingentPracticePlan) {
                    $scope.model.id = contingentPracticePlan.Id;
                    $scope.model.province = contingentPracticePlan.Province;
                    $scope.model.teams = contingentPracticePlan.Teams;
                });
        } 

        $scope.savePracticePlan = function () {
            dataService.SavePracticePlan($scope.model);
        };
    };

    app.controller("PracticeController", ["$scope", "$http", "$q", "$location", "dataService", practiceController]);
}());