<commit_before>'use strict';

angular.module('mean.system').controller(
    'FeedController', ['$scope', 'Goals', 'Feed', 'Global', function ($scope, Goals, Feed, Global) {
        $scope.global = Global;
        $scope.globalFeed = [];
        $scope.loggedIn = false;

        // Make sure that a users is logged in
        if ($scope.global.user.name === undefined) {
            $scope.userName = 'Rick H';
        } else {
            $scope.loggedIn = true;
        }

        Goals.query(function (data) {
            $scope.goals = getListOfGoals(data);
            Feed.query(function (data) {
                $scope.globalFeed = getListOfPosts(data);
                $scope.service = data;
            });
        });

        $scope.showImage = false;
        $scope.uploadComplete = function (files) {
            $scope.imageLocation = files[0].src;
            $scope.showImage = true;
        };

        $scope.fileUpload = function () {
            setTimeout(function () {
                angular.element('#file_browse').trigger('click');
            }, 0);
        };


        $scope.showInput = function (type) {
            hideAllInputs();
            switch (type) {
                case 'location':
                    $scope.showLocationInput = true;
                    $scope.locationComplete = false;
                    break;
                case 'youtube':
                    $scope.showYoutubeInput = true;
                    break;
                case 'goals':
                    $scope.showGoalsInput = true;
                    break;
                default:
                    break;
            }
        };

        $scope.onBlur = function (type) {
            hideAllInputs();
            switch (type) {
                case 'location':
                    if ($scope.locationName.length > 0) {
                        $scope.locationComplete = true;
                    }
                    break;
                case 'youtube':
                    var start = $scope.youTubeURL.indexOf('v=');
                    if (start > 1) {
                        start = start + 2;
                        var code = $scope.youTubeURL.slice(start, $scope.youTubeURL.length);
                        $scope.validYouTubeURL = 'https://www.youtube.com/embed/' + code;
                        $scope.showVideo = true;
                    }
                    break;
                default:
                    break;
            }
        };

        $scope.selectedGoal = function (item) {
            hideAllInputs();
            $scope.goalID = item.id;
            $scope.showGoal = true;
            $scope.goal = item;
        };
        $scope.remove = function (post) {
            var removeItem;
            for (var item in $scope.service) {
                if ($scope.service[item]._id === post.id) {
                    removeItem = item;
                }
            }
            $scope.service[removeItem].$remove(function (response) {
                if (response !== undefined) {
                    for (var item in $scope.globalFeed) {
                        if ($scope.globalFeed[item].id === post.id) {
                            $scope.globalFeed.splice(item, 1);
                            break;
                        }
                    }
                }
            });


        };

        $scope.post = function () {

            $scope.upload = true;
            $scope.sending = true;

            var feedService = new Feed({
                status: $scope.status,
                goalId: $scope.goalID,
                image: $scope.imageLocation,
                youtube: $scope.validYouTubeURL,
                location: $scope.locationName
            });



            feedService.$save(function (response) {

                if (response !== undefined) {

                    $scope.status = undefined;
                    $scope.goalID = undefined;
                    $scope.imageLocation = undefined;
                    $scope.validYouTubeURL = undefined;
                    $scope.locationName = undefined;
                    $scope.youTubeURL = undefined;
                    $scope.imageLocation = undefined;
                    hideAllInputs();

                    var newPost = {
                        created: response.created,
                        status: response.status,
                        location: response.location,
                        youtube: response.youtube,
                        goalId: response.goalId,
                        image: response.image,
                        id: response._id
                    };
                    $scope.service.push(response);
                    var templateType = 0;
                    if (newPost.status !== undefined) {
                        templateType += 1;
                    }
                    if (newPost.image !== undefined) {
                        templateType += 1;
                    }
                    if (newPost.youtube !== undefined) {
                        templateType += 1;
                    }

                    switch (templateType) {
                        case 1:
                            newPost.template1 = true;
                            break;
                        case 2:
                            if (newPost.youtube !== undefined) {
                                newPost.template1 = true;<commit_msg>small bug for file upload<commit_after>'use strict';

angular.module('mean.system').controller(
    'FeedController', ['$scope', 'Goals', 'Feed', 'Global', function ($scope, Goals, Feed, Global) {
        $scope.global = Global;
        $scope.globalFeed = [];
        $scope.loggedIn = false;

        // Make sure that a users is logged in
        if ($scope.global.user.name === undefined) {
            $scope.userName = 'Rick H';
        } else {
            $scope.loggedIn = true;
        }

        Goals.query(function (data) {
            $scope.goals = getListOfGoals(data);
            Feed.query(function (data) {
                $scope.globalFeed = getListOfPosts(data);
                $scope.service = data;
            });
        });

        $scope.showImage = false;
        $scope.uploadComplete = function (files) {
            $scope.imageLocation = files[0].src;
            $scope.showImage = true;
        };

        $scope.fileUpload = function () {
            setTimeout(function () {
                angular.element('#file_browse').trigger('click');
            }, 0);
        };


        $scope.showInput = function (type) {
            hideAllInputs();
            switch (type) {
                case 'location':
                    $scope.showLocationInput = true;
                    $scope.locationComplete = false;
                    break;
                case 'youtube':
                    $scope.showYoutubeInput = true;
                    break;
                case 'goals':
                    $scope.showGoalsInput = true;
                    break;
                default:
                    break;
            }
        };

        $scope.onBlur = function (type) {
            hideAllInputs();
            switch (type) {
                case 'location':
                    if ($scope.locationName.length > 0) {
                        $scope.locationComplete = true;
                    }
                    break;
                case 'youtube':
                    var start = $scope.youTubeURL.indexOf('v=');
                    if (start > 1) {
                        start = start + 2;
                        var code = $scope.youTubeURL.slice(start, $scope.youTubeURL.length);
                        $scope.validYouTubeURL = 'https://www.youtube.com/embed/' + code;
                        $scope.showVideo = true;
                    }
                    break;
                default:
                    break;
            }
        };

        $scope.selectedGoal = function (item) {
            hideAllInputs();
            $scope.goalID = item.id;
            $scope.showGoal = true;
            $scope.goal = item;
        };
        $scope.remove = function (post) {
            var removeItem;
            for (var item in $scope.service) {
                if ($scope.service[item]._id === post.id) {
                    removeItem = item;
                }
            }
            $scope.service[removeItem].$remove(function (response) {
                if (response !== undefined) {
                    for (var item in $scope.globalFeed) {
                        if ($scope.globalFeed[item].id === post.id) {
                            $scope.globalFeed.splice(item, 1);
                            break;
                        }
                    }
                }
            });


        };

        $scope.post = function () {

            $scope.upload = true;
            $scope.sending = true;

            var feedService = new Feed({
                status: $scope.status,
                goalId: $scope.goalID,
                image: $scope.imageLocation,
                youtube: $scope.validYouTubeURL,
                location: $scope.locationName
            });



            feedService.$save(function (response) {

                if (response !== undefined) {

                    $scope.status = undefined;
                    $scope.goalID = undefined;
                    $scope.imageLocation = undefined;
                    $scope.validYouTubeURL = undefined;
                    $scope.locationName = undefined;
                    $scope.youTubeURL = undefined;
                    $scope.showImage = false;

                    hideAllInputs();

                    var newPost = {
                        created: response.created,
                        status: response.status,
                        location: response.location,
                        youtube: response.youtube,
                        goalId: response.goalId,
                        image: response.image,
                        id: response._id
                    };
                    $scope.service.push(response);
                    var templateType = 0;
                    if (newPost.status !== undefined) {
                        templateType += 1;
                    }
                    if (newPost.image !== undefined) {
                        templateType += 1;
                    }
                    if (newPost.youtube !== undefined) {
                        templateType += 1;
                    }

                    switch (templateType) {
                        case 1:
                            newPost.template1 = true;
                            break;
                        case 2:
                            if (newPost.youtube !== undefined) {
                                newPost.template1 = true;
{'fraction_non_alphanumeric': 0.1022528735632184, 'fraction_numerical': 0.002574712643678161, 'mean_word_length': 0.9846715328467154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6635249', 'n_tokens_mistral': 2684, 'n_tokens_neox': 2441, 'n_words': 505}