<commit_before>(function(angular){

    var app = angular.module('new-course');

    app.controller('CourseEditController',
        ['$scope', '$window', '$uibModal', '$http', '$q', 'Course',  'CourseAuthor', 'Lesson', '$filter', 'youtubePlayerApi', 'VideoData', 'FormUpload', 'uibDateParser',
        function($scope, $window, $uibModal, $http , $q, Course,  CourseProfessor, Lesson, $filter, youtubePlayerApi, VideoData, FormUpload, uibDateParser) {

            $scope.errors = {};
            var httpErrors = {
                '400': 'Os campos não foram preenchidos corretamente.',
                '403': 'Você não tem permissão para ver conteúdo nesta página.',
                '404': 'Este curso não existe!'
            };

            $scope.course_id = parseInt($window.course_id, 10);

            $scope.courseProfessors = [];
            $scope.lessons = [];

            Course.get({id: $scope.course_id}, function(course){
                if(course.intro_video) {
                    youtubePlayerApi.videoId = course.intro_video.youtube_id;
                }
                document.title = 'Curso: {0}'.format(course.name);
                $scope.addThumb = !course.thumbnail_url;
                $scope.addHomeThumb = !course.home_thumbnail_url;
                course.start_date = uibDateParser.parse(course.start_date, "yyyy-MM-dd");
                $scope.course = course;
            });

            $scope.lessons = Lesson.query({
              'course__id': $scope.course_id
            });

            $scope.courseProfessors = CourseProfessor.query({
              course: $scope.course_id
            });

            var player;
            $scope.playerReady = false;
            youtubePlayerApi.loadPlayer().then(function(p){
                player = p;
                $scope.playerReady = true;
            });

            $scope.$watch('course.intro_video.youtube_id', function(vid, oldVid){
                if(!vid || vid === oldVid) return;
                if(player) player.cueVideoById(vid);
                VideoData.load(vid).then(function(data){
                    if (data.items.length > 0)
                        $scope.course.intro_video.name = data.items[0].snippet.title;
                });
            });


            $scope.setCurrentUnitVideo = function() {
                //
                // support pasting both long and short urls from youtube
                // eg. http://youtu.be/8uj7YSqby7s
                //
                var complete_url = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
                var result = complete_url.exec($scope.youtube_id);
                if (result && result[2].length == 11) {
                    $scope.course.intro_video.youtube_id = result[2];
                }
            };

            function showFieldErrors(response) {
                $scope.errors = response.data;
                var messages = [];
                for(var att in response.data) {
                    var message = response.data[att];
                    if(Course.fields && Course.fields[att]) {
                        message = Course.fields[att].label + ': ' + message;
                    }
                    messages.push(message);
                }
                $scope.alert.error('Encontramos alguns erros!', messages, true);
            }

            $scope.saveThumb = function() {
                if(! $scope.thumbfile) {
                    return;
                }

                if ($scope.course.id) {
                    var fu = new FormUpload();
                    fu.addField('thumbnail', $scope.thumbfile);
                    // return a new promise that file will be uploaded
                    return fu.sendTo('/api/coursethumbs/' + $scope.course.id)
                        .then(function(){<commit_msg>Prevent error during course save if there were no video_intro before<commit_after>(function(angular){

    var app = angular.module('new-course');

    app.controller('CourseEditController',
        ['$scope', '$window', '$uibModal', '$http', '$q', 'Course',  'CourseAuthor', 'Lesson', '$filter', 'youtubePlayerApi', 'VideoData', 'FormUpload', 'uibDateParser',
        function($scope, $window, $uibModal, $http , $q, Course,  CourseProfessor, Lesson, $filter, youtubePlayerApi, VideoData, FormUpload, uibDateParser) {

            $scope.errors = {};
            var httpErrors = {
                '400': 'Os campos não foram preenchidos corretamente.',
                '403': 'Você não tem permissão para ver conteúdo nesta página.',
                '404': 'Este curso não existe!'
            };

            $scope.course_id = parseInt($window.course_id, 10);

            $scope.courseProfessors = [];
            $scope.lessons = [];

            Course.get({id: $scope.course_id}, function(course){
                if(course.intro_video) {
                    youtubePlayerApi.videoId = course.intro_video.youtube_id;
                }
                document.title = 'Curso: {0}'.format(course.name);
                $scope.addThumb = !course.thumbnail_url;
                $scope.addHomeThumb = !course.home_thumbnail_url;
                course.start_date = uibDateParser.parse(course.start_date, "yyyy-MM-dd");
                $scope.course = course;
            });

            $scope.lessons = Lesson.query({
              'course__id': $scope.course_id
            });

            $scope.courseProfessors = CourseProfessor.query({
              course: $scope.course_id
            });

            var player;
            $scope.playerReady = false;
            youtubePlayerApi.loadPlayer().then(function(p){
                player = p;
                $scope.playerReady = true;
            });

            $scope.$watch('course.intro_video.youtube_id', function(vid, oldVid){
                if(!vid || vid === oldVid) return;
                if(player) player.cueVideoById(vid);
                VideoData.load(vid).then(function(data){
                    if (data.items.length > 0)
                        $scope.course.intro_video.name = data.items[0].snippet.title;
                });
            });


            $scope.setCurrentUnitVideo = function() {
                //
                // support pasting both long and short urls from youtube
                // eg. http://youtu.be/8uj7YSqby7s
                //
                var complete_url = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
                var result = complete_url.exec($scope.youtube_id);
                if (result && result[2].length == 11) {
                    // If this is the first time a intro_video is set, prepare the variable
                    if($scope.course.intro_video === 'undefined')
                        $scope.course.intro_video = {};
                    $scope.course.intro_video.youtube_id = result[2];
                }
            };

            function showFieldErrors(response) {
                $scope.errors = response.data;
                var messages = [];
                for(var att in response.data) {
                    var message = response.data[att];
                    if(Course.fields && Course.fields[att]) {
                        message = Course.fields[att].label + ': ' + message;
                    }
                    messages.push(message);
                }
                $scope.alert.error('Encontramos alguns erros!', messages, true);
            }

            $scope.saveThumb = function() {
                if(! $scope.thumbfile) {
                    return;
                }

                if ($scope.course.id) {
                    var fu = new FormUpload();
                    fu.addField('thumbnail', $scope.thumbfile);
                    // return a new promise that file will be uploaded
                    return fu.sendTo('/api/coursethumbs/' + $scope.course.id)
                        .then(function(){
{'fraction_non_alphanumeric': 0.13139052882803667, 'fraction_numerical': 0.005275719130762467, 'mean_word_length': 1.4904598060681888, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1454881', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2071, 'n_words': 397}