<commit_before>'use strict';

angular.module('courses').controller('AddPackToCourseController', ['$scope', '$state', '$timeout', '$modalInstance', 'course', 'Packs', 'Courses','JourneyService',
	function($scope, $state, $timeout, $modalInstance, course, Packs, Courses, JourneyService) {
        $scope.course = course;

        $scope.setFocus = function () {
            $timeout(function(){
                angular.element('.focus').trigger('focus');
            },100);
        };

        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };

        $scope.addPackToCourse = function () {

            var self = {};
            self.name = this.name;
            self.slavesToSave = course.slaves.length;
            self.slavesSaved = 0;
            self.slaves = [];

            // Create new Pack object
            var pack = new Packs({
                name: this.name,
                course: this.course._id
            });


            // Redirect after save
            pack.$save(function (response) {
                var packid = response._id;
                $scope.course.packs.push(packid);
                $scope.course.$update(function () {
                    $scope.name = '';
                    $state.go($state.$current, null, { reload: true });
                }, function (errorResponse) {
                    $scope.error = errorResponse.data.message;
                });

                console.log($scope.course.slaves);

                $scope.course.slaves.forEach(function(slaveId) {
                    Courses.query({
                        _id: slaveId
                    }, function (slaveCourses) {

                        if (slaveCourses.length === 0) {
                            // course does not exist any more
                            self.slavesSaved ++;
                            for (var i in $scope.course.slaves) {
                                if ($scope.course.slaves[i] === slaveId) {
                                    $scope.course.slaves.splice(i, 1);
                                }
                            }
                        }

                        if (slaveCourses.length === 1) {
                            var slaveCourse = slaveCourses[0];

                            var slavePack = new Packs({
                                name: self.name,
                                course: slaveCourse._id
                            });<commit_msg>removed debug info<commit_after>'use strict';

angular.module('courses').controller('AddPackToCourseController', ['$scope', '$state', '$timeout', '$modalInstance', 'course', 'Packs', 'Courses','JourneyService',
	function($scope, $state, $timeout, $modalInstance, course, Packs, Courses, JourneyService) {
        $scope.course = course;

        $scope.setFocus = function () {
            $timeout(function(){
                angular.element('.focus').trigger('focus');
            },100);
        };

        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };

        $scope.addPackToCourse = function () {

            var self = {};
            self.name = this.name;
            self.slavesToSave = course.slaves.length;
            self.slavesSaved = 0;
            self.slaves = [];

            // Create new Pack object
            var pack = new Packs({
                name: this.name,
                course: this.course._id
            });


            // Redirect after save
            pack.$save(function (response) {
                var packid = response._id;
                $scope.course.packs.push(packid);
                $scope.course.$update(function () {
                    $scope.name = '';
                    $state.go($state.$current, null, { reload: true });
                }, function (errorResponse) {
                    $scope.error = errorResponse.data.message;
                });


                $scope.course.slaves.forEach(function(slaveId) {
                    Courses.query({
                        _id: slaveId
                    }, function (slaveCourses) {

                        if (slaveCourses.length === 0) {
                            // course does not exist any more
                            self.slavesSaved ++;
                            for (var i in $scope.course.slaves) {
                                if ($scope.course.slaves[i] === slaveId) {
                                    $scope.course.slaves.splice(i, 1);
                                }
                            }
                        }

                        if (slaveCourses.length === 1) {
                            var slaveCourse = slaveCourses[0];

                            var slavePack = new Packs({
                                name: self.name,
                                course: slaveCourse._id
                            });
{'fraction_non_alphanumeric': 0.11842641663269465, 'fraction_numerical': 0.003261312678353037, 'mean_word_length': 1.1381263616557735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '261576', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1142, 'n_words': 223}