<commit_before>/**
 * Created by vytautassugintas on 06/04/16.
 */
'use strict';

angular
    .module('myApp.profile', [
        'ngRoute',
        'ngCookies'
    ])

    .filter('getByProperty', function() {
        return function(propertyName, propertyValue, collection) {
            var i=0, len=collection.length;
            for (i; i<len; i++) {
                if (collection[i][propertyName] == propertyValue) {
                    collection[i].show = true;
                    return collection[i];
                }
            }
            return null;
        }
    })

    .controller('profileController', function ($http, $scope, $window, $cookies, $timeout, $httpParamSerializer, $filter, ProfileService, Challenges) {
        var inputChangedPromise;
        var receiverValidated = false;
        var amountValidated = false;
        var showMoreLimit = 5;
        var errorMessage = "";
        var requestDateFormat = 'yyyy-MM-dd HH:mm:ss,sss';

        $scope.userAvailableKudos = 0;
        $scope.userReceivedKudos = 0;
        $scope.incomingKudosShowLimit = 5;
        $scope.outgoingKudosShowLimit = 5;
        $scope.maxSendKudosLength = $scope.userAvailableKudos;
        $scope.incomingKudosCollection = [];
        $scope.outgoingKudosCollection = [];
        $scope.givenChallengesCollection = [];
        $scope.usersCollection = [];
        $scope.buttonDisabled = true;

        $scope.receiverErrorClass = "";
        $scope.receiverErrorMessage = "";
        $scope.amountErrorClass = "";
        $scope.amountErrorMessage = "";

        $scope.logout = logout;
        $scope.sendKudos = sendKudos;
        $scope.giveChallenge = giveChallenge;
        $scope.cancelChallenge = cancelChallenge;
        $scope.inputChanged = inputChanged;
        $scope.kudosValidation = kudosValidation;
        $scope.isValid = isValid;
        $scope.clearSendKudosFormValues = clearSendKudosFormValues;
        $scope.showMoreIncomingKudos = showMoreIncomingKudos;
        $scope.showMoreOutgoingKudos = showMoreOutgoingKudos;
        $scope.showLessIncomingKudos = showLessIncomingKudos;
        $scope.showLessOutgoingKudos = showLessOutgoingKudos;
        $scope.showMoreIncomingKudosButton = showMoreIncomingKudosButton;
        $scope.showMoreOutgoingKudosButton = showMoreOutgoingKudosButton;
        $scope.showMoreInfo = showMoreInfo;
        $scope.showLessInfo = showLessInfo;
        $scope.clearChallengeFormValues = clearChallengeFormValues;
        $scope.challengeFormCheck = challengeFormCheck;

        checkUser();
        registerTooltip();

        /**
         * Send kudos modal receiver input
         * field auto complete
         */
        $scope.autocompleteHide = true;

        $scope.selectAutoText = function (text) {
            $scope.sendKudosTo = text;
            $scope.searchTermSelected = true;
            $scope.autocompleteHide = true;
            sendKudosValidation();
        };

        $scope.$watch('sendKudosTo', function (newVal, oldVal) {
            if ($scope.searchTermSelected == false) {
                if (newVal != undefined) {
                    if (newVal.length > 1) {
                        $scope.autocompleteHide = false;
                    } else {
                        $scope.autocompleteHide = true;
                    }
                }
            } else {
                $scope.searchTermSelected = false;
            }
        });

        ProfileService.userHome().then(function (val) {
            $scope.userEmail = val.email;
            $scope.userName = val.firstName;
            $scope.userSurname = val.lastName;
            $scope.userPhone = val.phone;
            $scope.userPosition = val.position;
            $scope.userLocation = val.location;
            $scope.userTeam = val.team;
            $scope.userStartedToWork = val.startedToWorkDate;
            $scope.userBirthday = val.birthday;
        });

        ProfileService.remainingKudos().then(function (val) {
            $scope.userAvailableKudos = val;
        });

        ProfileService.receivedKudos().then(function (val) {
            $scope.userReceivedKudos = val;
        });

        ProfileService.incomingKudos().then(function (val) {
            $scope.incomingKudosCollection = val;
            showMoreIncomingKudosButton(val);
            receivedKudosTable();
        });

        ProfileService.outgoingKudos().then(function (val) {
            $scope.outgoingKudosCollection = val;
            showMoreOutgoingKudosButton(val);
            sentKudosTable();
        });

        ProfileService.listUsers().then(function (val) {
            $scope.usersCollection = val.userList;
        });

        ProfileService.givenChallenges().then(function (val) {
            $scope.givenChallengesCollection = val;
        });

        function sendKudos() {
            var sendTo = $httpParamSerializer({
                receiverEmail: $scope.sendKudosTo,
                amount: $scope.sendKudosAmount,
                message: $scope.sendKudosMessage});

            ProfileService.send(sendTo).then(function (val) {
                $scope.showSendKudosModal = false;
                $scope.showSuccess = true;
                $scope.userAvailableKudos = $scope.userAvailableKudos - val.data.amount;
                $('#sendKudosModal').modal('hide');
                toastr.success('You successfully sent ' + acornPlural(val.data.amount) + ' to ' + val.data.receiver);
                addTransactionToCollection(val.data);
                clearSendKudosFormValues();
            }).catch(function () {
                sendKudosReceiverErrorMessage("Receiver does not exist");
            });
        }

        function addTransactionToCollection(val) {
            var itemToAdd = {
                receiver: val.receiver,
                message: val.message,
                amount: val.amount,
                timestamp: trimDate(val.timestamp)};

            $scope.outgoingKudosCollection.push(itemToAdd);
            sentKudosTable();
            showMoreOutgoingKudosButton($scope.outgoingKudosCollection);
        }

        function sendKudosValidation() {
            clearErrorMessages();
            if ($scope.sendKudosTo == null) {
                sendKudosReceiverErrorMessage("Please enter receiver");
            } else if (!validateEmail($scope.sendKudosTo)) {
                sendKudosReceiverErrorMessage("Please enter valid receiver email");
            } else if ($scope.sendKudosTo === $scope.userEmail) {
                sendKudosReceiverErrorMessage("Can't send kudos to yourself");
            } else if ($scope.sendKudosAmount > $scope.userAvailableKudos) {
                sendKudosAmountErrorMessage("You don't have enough Acorns");
            } else if ($scope.sendKudosAmount == null) {
                sendKudosAmountErrorMessage("Please enter amount");
            } else if ($scope.sendKudosAmount <= 0) {
                sendKudosAmountErrorMessage("Please enter more than zero");
            } else {
                clearErrorMessages();
            }
        }

        function inputChanged() {
            if (inputChangedPromise) $timeout.cancel(inputChangedPromise);
            inputChangedPromise = $timeout(sendKudosValidation(), 100);
        }

        function sendKudosReceiverErrorMessage(message) {
            $scope.receiverErrorClass = "error-message";
            $scope.fieldReceiverErrorClass = "invalid";
            $scope.receiverErrorMessage = message;
            receiverValidated = false;
            disableSendKudosButton();
        }

        function sendKudosAmountErrorMessage(message) {
            $scope.amountErrorClass = "error-message";
            $scope.fieldAmountErrorClass = "invalid";
            $scope.amountErrorMessage = message;
            amountValidated = false;
            disableSendKudosButton();
        }

        function clearErrorMessages() {
            $scope.receiverErrorMessage = "";
            $scope.receiverErrorClass = "";
            $scope.fieldReceiverErrorClass = "";
            $scope.amountErrorMessage = "";
            $scope.amountErrorClass = "";
            $scope.fieldAmountErrorClass = "";
            enableSendKudosButton();
        }

        function clearSendKudosFormValues() {
            $scope.receiverErrorMessage = "";
            $scope.amountErrorMessage = "";
            $scope.receiverErrorClass = "";
            $scope.amountErrorClass = "";
            $scope.fieldAmountErrorClass = "";
            $scope.fieldReceiverErrorClass = "";
            $scope.sendKudosTo = "";
            $scope.sendKudosAmount = "";
            $scope.sendKudosMessage = "";
            disableSendKudosButton();
        }

        function showMoreIncomingKudosButton(val) {
            if (val.length > 5) {
                $scope.moreIncoming = true;
            }
        }

        function showMoreOutgoingKudosButton(val) {
            if (val.length > 5) {
                $scope.moreOutgoing = true;
            }
        }

        function showMoreIncomingKudos() {
            if ($scope.incomingKudosShowLimit <= $scope.incomingKudosCollection.length) {
                $scope.incomingKudosShowLimit += showMoreLimit;
            }
        }

        function showMoreOutgoingKudos() {
            if ($scope.outgoingKudosShowLimit <= $scope.outgoingKudosCollection.length) {
                $scope.outgoingKudosShowLimit += showMoreLimit;
            }
        }

        function showLessOutgoingKudos() {
            $scope.outgoingKudosShowLimit = showMoreLimit;
        }

        function showLessIncomingKudos() {
            $scope.incomingKudosShowLimit = showMoreLimit;
        }

        function sentKudosTable() {
            if ($scope.outgoingKudosCollection.length > 0)
                $scope.sentKudosTable = true;
        }

        function receivedKudosTable() {
            if ($scope.incomingKudosCollection.length > 0)
                $scope.receivedKudosTable = true;
        }

        function showMoreInfo(challengeId) {
            return $filter('getByProperty')("id", challengeId, $scope.givenChallengesCollection);
        }

        function showLessInfo(challengeId) {
            return $filter('getByProperty')("id", challengeId, $scope.givenChallengesCollection).show = false;
        }

        function updateProfile() {
            var updateInfo = $.param({
                birthday: this.birthday,
                department: this.department,
                location: this.location,
                phone: "",              // <-- TODO FIX PHONE
                position: this.position,
                startToWork: this.startToWork,
                team: this.team
            });
            ProfileService.update(updateInfo).then(function (val) {
                $('#userDetailsModal').modal('hide');
                checkUser();
            })
        }

        function sendKudos() {
            var sendTo = $httpParamSerializer({
                receiverEmail: $scope.sendKudosTo,
                amount: $scope.sendKudosAmount,
                message: $scope.sendKudosMessage
            });

            ProfileService.send(sendTo).then(function (val) {
                $scope.showSendKudosModal = false;
                $scope.showSuccess = true;
                $scope.userAvailableKudos = $scope.userAvailableKudos - val.data.amount;
                $('#sendKudosModal').modal('hide');
                toastr.success('You successfully sent ' + acornPlural(val.data.amount) + ' to ' + val.data.receiver);
                pushOutgoingTransferIntoCollection(val.data);
                clearSendKudosFormValues();
            }).catch(function () {
                errorMessage == "" ? showSendKudosErrorMessage("Receiver does not exist") : showSendKudosErrorMessage(errorMessage)
            });
        }

        function giveChallenge() {
            var expirationDate = $filter('date')($scope.giveChallengeExpirationDate, requestDateFormat);

            var giveTo = $httpParamSerializer({
                participant: $scope.giveChallengeTo,
                referee: $scope.giveChallengeReferee,
                name: $scope.giveChallengeName,
                description: $scope.giveChallengeDescription,
                finishDate: expirationDate,
                amount: $scope.giveChallengeAmountOfKudos
            });

            var challengeCall = challengeFormCheck();

            if (challengeCall)
            Challenges.create(giveTo).then(function (val) {
                clearChallengeFormValues();
                $('#giveChallengeModal').modal('hide');
                toastr.success('You successfully challenged '  + val.data.participant + " with " + acornPlural(val.data.amount) + '.' +
                    ' Referee: ' + val.data.referee);
                $scope.userAvailableKudos -= val.data.amount;
            }).catch(function () {
                showChallengeFormErrorMessage("Challenge receiver or referee does not exist");
            })
        }

            function cancelChallenge(id) {
                var challengeId = $httpParamSerializer({
                    id: id
                });
                Challenges.cancel(challengeId).then(function (val) {
                    toastr.success("Challenge canceled");
                    var challenge = $filter('getByProperty')("id", challengeId, $scope.givenChallengesCollection);
                    $scope.givenChallengesCollection.splice($scope.givenChallengesCollection.indexOf(challenge), 1);
                });
            }

                function challengeFormCheck(){
                    if ($scope.giveChallengeName == null){
                        showChallengeFormErrorMessage("Please enter Challenge name");
                        return false;
                    } else if ($scope.giveChallengeAmountOfKudos == null) {
                        showChallengeFormErrorMessage("Please enter valid challenge Acorns");
                        return false;
                    } else if ($scope.giveChallengeAmountOfKudos > $scope.userAvailableKudos) {
                        showChallengeFormErrorMessage("You don't have enough of Acorns");
                        return false;
                    } else if ($scope.giveChallengeTo == null) {
                        showChallengeFormErrorMessage("Please enter challenge receiver");
                        return false;
                    } else if ($scope.giveChallengeTo == $scope.userEmail){
                        showChallengeFormErrorMessage("You can't challenge yourself");
                        return false;
                    } else if ($scope.giveChallengeReferee == null){
                        showChallengeFormErrorMessage("Please enter challenge referee");
                        return false;
                    } else if ($scope.giveChallengeReferee == $scope.userEmail){
                        showChallengeFormErrorMessage("You can't be challenge referee");<commit_msg>Corrected given challenges list updating<commit_after>/**
 * Created by vytautassugintas on 06/04/16.
 */
'use strict';

angular
    .module('myApp.profile', [
        'ngRoute',
        'ngCookies'
    ])

    .filter('getByProperty', function() {
        return function(propertyName, propertyValue, collection) {
            var i=0, len=collection.length;
            for (i; i<len; i++) {
                if (collection[i][propertyName] == propertyValue) {
                    collection[i].show = true;
                    return collection[i];
                }
            }
            return null;
        }
    })

    .controller('profileController', function ($http, $scope, $window, $cookies, $timeout, $httpParamSerializer, $filter, ProfileService, Challenges) {
        var inputChangedPromise;
        var receiverValidated = false;
        var amountValidated = false;
        var showMoreLimit = 5;
        var errorMessage = "";
        var requestDateFormat = 'yyyy-MM-dd HH:mm:ss,sss';

        $scope.userAvailableKudos = 0;
        $scope.userReceivedKudos = 0;
        $scope.incomingKudosShowLimit = 5;
        $scope.outgoingKudosShowLimit = 5;
        $scope.maxSendKudosLength = $scope.userAvailableKudos;
        $scope.incomingKudosCollection = [];
        $scope.outgoingKudosCollection = [];
        $scope.givenChallengesCollection = [];
        $scope.usersCollection = [];
        $scope.buttonDisabled = true;

        $scope.receiverErrorClass = "";
        $scope.receiverErrorMessage = "";
        $scope.amountErrorClass = "";
        $scope.amountErrorMessage = "";

        $scope.logout = logout;
        $scope.sendKudos = sendKudos;
        $scope.giveChallenge = giveChallenge;
        $scope.cancelChallenge = cancelChallenge;
        $scope.inputChanged = inputChanged;
        $scope.kudosValidation = kudosValidation;
        $scope.isValid = isValid;
        $scope.clearSendKudosFormValues = clearSendKudosFormValues;
        $scope.showMoreIncomingKudos = showMoreIncomingKudos;
        $scope.showMoreOutgoingKudos = showMoreOutgoingKudos;
        $scope.showLessIncomingKudos = showLessIncomingKudos;
        $scope.showLessOutgoingKudos = showLessOutgoingKudos;
        $scope.showMoreIncomingKudosButton = showMoreIncomingKudosButton;
        $scope.showMoreOutgoingKudosButton = showMoreOutgoingKudosButton;
        $scope.showMoreInfo = showMoreInfo;
        $scope.showLessInfo = showLessInfo;
        $scope.clearChallengeFormValues = clearChallengeFormValues;
        $scope.challengeFormCheck = challengeFormCheck;

        checkUser();
        registerTooltip();

        /**
         * Send kudos modal receiver input
         * field auto complete
         */
        $scope.autocompleteHide = true;

        $scope.selectAutoText = function (text) {
            $scope.sendKudosTo = text;
            $scope.searchTermSelected = true;
            $scope.autocompleteHide = true;
            sendKudosValidation();
        };

        $scope.$watch('sendKudosTo', function (newVal, oldVal) {
            if ($scope.searchTermSelected == false) {
                if (newVal != undefined) {
                    if (newVal.length > 1) {
                        $scope.autocompleteHide = false;
                    } else {
                        $scope.autocompleteHide = true;
                    }
                }
            } else {
                $scope.searchTermSelected = false;
            }
        });

        ProfileService.userHome().then(function (val) {
            $scope.userEmail = val.email;
            $scope.userName = val.firstName;
            $scope.userSurname = val.lastName;
            $scope.userPhone = val.phone;
            $scope.userPosition = val.position;
            $scope.userLocation = val.location;
            $scope.userTeam = val.team;
            $scope.userStartedToWork = val.startedToWorkDate;
            $scope.userBirthday = val.birthday;
        });

        ProfileService.remainingKudos().then(function (val) {
            $scope.userAvailableKudos = val;
        });

        ProfileService.receivedKudos().then(function (val) {
            $scope.userReceivedKudos = val;
        });

        ProfileService.incomingKudos().then(function (val) {
            $scope.incomingKudosCollection = val;
            showMoreIncomingKudosButton(val);
            receivedKudosTable();
        });

        ProfileService.outgoingKudos().then(function (val) {
            $scope.outgoingKudosCollection = val;
            showMoreOutgoingKudosButton(val);
            sentKudosTable();
        });

        ProfileService.listUsers().then(function (val) {
            $scope.usersCollection = val.userList;
        });

        ProfileService.givenChallenges().then(function (val) {
            $scope.givenChallengesCollection = val;
        });

        function sendKudos() {
            var sendTo = $httpParamSerializer({
                receiverEmail: $scope.sendKudosTo,
                amount: $scope.sendKudosAmount,
                message: $scope.sendKudosMessage});

            ProfileService.send(sendTo).then(function (val) {
                $scope.showSendKudosModal = false;
                $scope.showSuccess = true;
                $scope.userAvailableKudos = $scope.userAvailableKudos - val.data.amount;
                $('#sendKudosModal').modal('hide');
                toastr.success('You successfully sent ' + acornPlural(val.data.amount) + ' to ' + val.data.receiver);
                addTransactionToCollection(val.data);
                clearSendKudosFormValues();
            }).catch(function () {
                sendKudosReceiverErrorMessage("Receiver does not exist");
            });
        }

        function addTransactionToCollection(val) {
            var itemToAdd = {
                receiver: val.receiver,
                message: val.message,
                amount: val.amount,
                timestamp: trimDate(val.timestamp)};

            $scope.outgoingKudosCollection.push(itemToAdd);
            sentKudosTable();
            showMoreOutgoingKudosButton($scope.outgoingKudosCollection);
        }

        function sendKudosValidation() {
            clearErrorMessages();
            if ($scope.sendKudosTo == null) {
                sendKudosReceiverErrorMessage("Please enter receiver");
            } else if (!validateEmail($scope.sendKudosTo)) {
                sendKudosReceiverErrorMessage("Please enter valid receiver email");
            } else if ($scope.sendKudosTo === $scope.userEmail) {
                sendKudosReceiverErrorMessage("Can't send kudos to yourself");
            } else if ($scope.sendKudosAmount > $scope.userAvailableKudos) {
                sendKudosAmountErrorMessage("You don't have enough Acorns");
            } else if ($scope.sendKudosAmount == null) {
                sendKudosAmountErrorMessage("Please enter amount");
            } else if ($scope.sendKudosAmount <= 0) {
                sendKudosAmountErrorMessage("Please enter more than zero");
            } else {
                clearErrorMessages();
            }
        }

        function inputChanged() {
            if (inputChangedPromise) $timeout.cancel(inputChangedPromise);
            inputChangedPromise = $timeout(sendKudosValidation(), 100);
        }

        function sendKudosReceiverErrorMessage(message) {
            $scope.receiverErrorClass = "error-message";
            $scope.fieldReceiverErrorClass = "invalid";
            $scope.receiverErrorMessage = message;
            receiverValidated = false;
            disableSendKudosButton();
        }

        function sendKudosAmountErrorMessage(message) {
            $scope.amountErrorClass = "error-message";
            $scope.fieldAmountErrorClass = "invalid";
            $scope.amountErrorMessage = message;
            amountValidated = false;
            disableSendKudosButton();
        }

        function clearErrorMessages() {
            $scope.receiverErrorMessage = "";
            $scope.receiverErrorClass = "";
            $scope.fieldReceiverErrorClass = "";
            $scope.amountErrorMessage = "";
            $scope.amountErrorClass = "";
            $scope.fieldAmountErrorClass = "";
            enableSendKudosButton();
        }

        function clearSendKudosFormValues() {
            $scope.receiverErrorMessage = "";
            $scope.amountErrorMessage = "";
            $scope.receiverErrorClass = "";
            $scope.amountErrorClass = "";
            $scope.fieldAmountErrorClass = "";
            $scope.fieldReceiverErrorClass = "";
            $scope.sendKudosTo = "";
            $scope.sendKudosAmount = "";
            $scope.sendKudosMessage = "";
            disableSendKudosButton();
        }

        function showMoreIncomingKudosButton(val) {
            if (val.length > 5) {
                $scope.moreIncoming = true;
            }
        }

        function showMoreOutgoingKudosButton(val) {
            if (val.length > 5) {
                $scope.moreOutgoing = true;
            }
        }

        function showMoreIncomingKudos() {
            if ($scope.incomingKudosShowLimit <= $scope.incomingKudosCollection.length) {
                $scope.incomingKudosShowLimit += showMoreLimit;
            }
        }

        function showMoreOutgoingKudos() {
            if ($scope.outgoingKudosShowLimit <= $scope.outgoingKudosCollection.length) {
                $scope.outgoingKudosShowLimit += showMoreLimit;
            }
        }

        function showLessOutgoingKudos() {
            $scope.outgoingKudosShowLimit = showMoreLimit;
        }

        function showLessIncomingKudos() {
            $scope.incomingKudosShowLimit = showMoreLimit;
        }

        function sentKudosTable() {
            if ($scope.outgoingKudosCollection.length > 0)
                $scope.sentKudosTable = true;
        }

        function receivedKudosTable() {
            if ($scope.incomingKudosCollection.length > 0)
                $scope.receivedKudosTable = true;
        }

        function showMoreInfo(challengeId) {
            return $filter('getByProperty')("id", challengeId, $scope.givenChallengesCollection);
        }

        function showLessInfo(challengeId) {
            return $filter('getByProperty')("id", challengeId, $scope.givenChallengesCollection).show = false;
        }

        function updateProfile() {
            var updateInfo = $.param({
                birthday: this.birthday,
                department: this.department,
                location: this.location,
                phone: "",              // <-- TODO FIX PHONE
                position: this.position,
                startToWork: this.startToWork,
                team: this.team
            });
            ProfileService.update(updateInfo).then(function (val) {
                $('#userDetailsModal').modal('hide');
                checkUser();
            })
        }

        function sendKudos() {
            var sendTo = $httpParamSerializer({
                receiverEmail: $scope.sendKudosTo,
                amount: $scope.sendKudosAmount,
                message: $scope.sendKudosMessage
            });

            ProfileService.send(sendTo).then(function (val) {
                $scope.showSendKudosModal = false;
                $scope.showSuccess = true;
                $scope.userAvailableKudos = $scope.userAvailableKudos - val.data.amount;
                $('#sendKudosModal').modal('hide');
                toastr.success('You successfully sent ' + acornPlural(val.data.amount) + ' to ' + val.data.receiver);
                pushOutgoingTransferIntoCollection(val.data);
                clearSendKudosFormValues();
            }).catch(function () {
                errorMessage == "" ? showSendKudosErrorMessage("Receiver does not exist") : showSendKudosErrorMessage(errorMessage)
            });
        }

        function giveChallenge() {
            var expirationDate = $filter('date')($scope.giveChallengeExpirationDate, requestDateFormat);

            var giveTo = $httpParamSerializer({
                participant: $scope.giveChallengeTo,
                referee: $scope.giveChallengeReferee,
                name: $scope.giveChallengeName,
                description: $scope.giveChallengeDescription,
                finishDate: expirationDate,
                amount: $scope.giveChallengeAmountOfKudos
            });

            var challengeCall = challengeFormCheck();

            if (challengeCall)
            Challenges.create(giveTo).then(function (val) {
                clearChallengeFormValues();
                $('#giveChallengeModal').modal('hide');
                toastr.success('You successfully challenged '  + val.data.participant + " with " + acornPlural(val.data.amount) + '.' +
                    ' Referee: ' + val.data.referee);
                $scope.userAvailableKudos -= val.data.amount;
            }).catch(function () {
                showChallengeFormErrorMessage("Challenge receiver or referee does not exist");
            })
        }

            function cancelChallenge(id) {
                var challengeId = $httpParamSerializer({
                    id: id
                });
                Challenges.cancel(challengeId).then(function (val) {
                    toastr.success("Challenge canceled");
                    var challenge = $filter('getByProperty')("id", id, $scope.givenChallengesCollection);
                    $scope.givenChallengesCollection.splice($scope.givenChallengesCollection.indexOf(challenge), 1);
                });
            }

                function challengeFormCheck(){
                    if ($scope.giveChallengeName == null){
                        showChallengeFormErrorMessage("Please enter Challenge name");
                        return false;
                    } else if ($scope.giveChallengeAmountOfKudos == null) {
                        showChallengeFormErrorMessage("Please enter valid challenge Acorns");
                        return false;
                    } else if ($scope.giveChallengeAmountOfKudos > $scope.userAvailableKudos) {
                        showChallengeFormErrorMessage("You don't have enough of Acorns");
                        return false;
                    } else if ($scope.giveChallengeTo == null) {
                        showChallengeFormErrorMessage("Please enter challenge receiver");
                        return false;
                    } else if ($scope.giveChallengeTo == $scope.userEmail){
                        showChallengeFormErrorMessage("You can't challenge yourself");
                        return false;
                    } else if ($scope.giveChallengeReferee == null){
                        showChallengeFormErrorMessage("Please enter challenge referee");
                        return false;
                    } else if ($scope.giveChallengeReferee == $scope.userEmail){
                        showChallengeFormErrorMessage("You can't be challenge referee");
{'fraction_non_alphanumeric': 0.1011750647281418, 'fraction_numerical': 0.00146053243045874, 'mean_word_length': 1.8532057960034094, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '2349517', 'n_tokens_mistral': 8128, 'n_tokens_neox': 7634, 'n_words': 1253}