<commit_before>angular.module('AnimalsDetailedAdminController', ['AnimalsAdminModule', 'AnimalsAdminValues'])
    .controller('AnimalsDetailedAdminController', ['$scope', '$routeParams', '$window', 'AnimalsAdminService',
        'AnimalsAdminValues', '$filter',
        function($scope, $routeParams, $window, AnimalsAdminService, AnimalsAdminValues, $filter) {

            AnimalsAdminService.rolesAllowed("moderator");

            //initialize loading spinner
            var targetContent = document.getElementById('loading-block');
            new Spinner(opts).spin(targetContent);
            //This variable decides when spinner loading for contentis closed.
            $scope.contentLoading = 0;

            $scope.currentLanguage = $window.localStorage.getItem('NG_TRANSLATE_LANG_KEY');

            var animalId = $routeParams.animalId;       //animal id
            $scope.animal = AnimalsAdminValues.animal;  //animal
            $scope.animalImage = undefined;
            $scope.errors = [];

            /**
             * @param animalId id of animal used for lookup.
             * @return animal instance.
             */
            var getAnimal = function() {
                $scope.contentLoading++;

                AnimalsAdminService.getAnimal(animalId)
                    .then(function (respounce) {
                        $scope.animalImage = "resources/img/no_img.png";
                        if (AnimalsAdminValues.animal.image != undefined) {
                            if (AnimalsAdminValues.animal.image.length > 0) {
                                $scope.animalImage = AnimalsAdminValues.animal.image;
                            }
                        }

                        if ($scope.animal.user == undefined) {
                            $scope.error = $filter('translate')("ERROR_NO_RECORDS");
                        }
                    }, function (respounce) {
                        $scope.errors.push({msg: $filter('translate')("ERROR_ANIMAL_NOT_FOUND")});
                    })
                    .finally(function () {
                        $scope.contentLoading--;
                    });
            }

            getAnimal();

            /**
             * delete animal.
             */
            $scope.deleteAnimal = function() {
                if (!confirm($filter('translate')("ANIMAL_DETAILED_CONFIRM_DELETE"))) {
                    return;
                }

                $filter('date')($scope.animal.dateOfRegister, 'yyyy-MM-dd')
                AnimalsAdminService.deleteAnimal($scope.animal.id)
                    .then(function(data) {
                        $window.location.href = "#/ua/user/home/animals";
                    },
                    function(data) {
                        $window.alert($filter('translate')("ANIMAL_DETAILED_DELETE_FAILED"));
                    });
            }

            /**
             * Convert an image
             * to a base64 url
             */
            function convertImgToBase64URL(){
                var img = document.getElementById("animalImg");
                var canvas = document.createElement('canvas');
                canvas.width = img.clientWidth;
                canvas.height = img.clientHeight;
                canvas.getContext('2d').drawImage(img, 1, 1);
                console.log(canvas.toDataURL());
                return canvas.toDataURL();
            }

            $scope.toPdf = function() {
                var docDefinition = { content: [
                    { text: 'Пропала ' + $scope.animal.type.type, fontSize: 21, alignment: 'center' },
                    { text: ' ' },
                    { image: convertImgToBase64URL(), alignment: 'center', fit: [500, 500] },
                    { text: ' ' },
                    { text: 'Прохання звертатись за телефоном: ' + $scope.animal.user.phone, fontSize: 21, alignment: 'center' }
                ] };

                pdfMake.createPdf(docDefinition).open();
            }

        }]);<commit_msg>some fix for AnimalDetailedAdminController.js<commit_after>angular.module('AnimalsDetailedAdminController', ['AnimalsAdminModule', 'AnimalsAdminValues'])
    .controller('AnimalsDetailedAdminController', ['$scope', '$routeParams', '$window', 'AnimalsAdminService',
        'AnimalsAdminValues', '$filter',
        function($scope, $routeParams, $window, AnimalsAdminService, AnimalsAdminValues, $filter) {

            AnimalsAdminService.rolesAllowed("moderator");

            //initialize loading spinner
            var targetContent = document.getElementById('loading-block');
            new Spinner(opts).spin(targetContent);
            //This variable decides when spinner loading for contentis closed.
            $scope.contentLoading = 0;

            $scope.currentLanguage = $window.localStorage.getItem('NG_TRANSLATE_LANG_KEY');

            var animalId = $routeParams.animalId;       //animal id
            $scope.animal = AnimalsAdminValues.animal;  //animal
            $scope.animalImage = undefined;
            $scope.errors = [];

            /**
             * @param animalId id of animal used for lookup.
             * @return animal instance.
             */
            var getAnimal = function() {
                $scope.contentLoading++;

                AnimalsAdminService.getAnimal(animalId)
                    .then(function (respounce) {
                        $scope.animalImage = "resources/img/no_img.png";
                        if (AnimalsAdminValues.animal.image != undefined) {
                            if (AnimalsAdminValues.animal.image.length > 0) {
                                $scope.animalImage = AnimalsAdminValues.animal.image;
                            }
                        }

                        if ($scope.animal.user == undefined) {
                            $scope.error = $filter('translate')("ERROR_NO_RECORDS");
                        }
                    }, function (respounce) {
                        $scope.errors.push({msg: $filter('translate')("ERROR_ANIMAL_NOT_FOUND")});
                    })
                    .finally(function () {
                        $scope.contentLoading--;
                    });
            }

            getAnimal();

            /**
             * delete animal.
             */
            $scope.deleteAnimal = function() {
                if (!confirm($filter('translate')("ANIMAL_DETAILED_CONFIRM_DELETE"))) {
                    return;
                }

                $filter('date')($scope.animal.dateOfRegister, 'yyyy-MM-dd')
                AnimalsAdminService.deleteAnimal($scope.animal.id)
                    .then(function(data) {
                        $window.location.href = "#/ua/user/home/animals";
                    },
                    function(data) {
                        $window.alert($filter('translate')("ANIMAL_DETAILED_DELETE_FAILED"));
                    });
            }

            /**
             * Convert an image
             * to a base64 url
             */
            function convertImgToBase64URL(){
                var img = document.getElementById("animalImg");
                var canvas = document.createElement('canvas');

                if (img.clientWidth <= 400) {
                    canvas.width = img.clientWidth;
                    canvas.height = img.clientHeight;
                    canvas.getContext('2d').drawImage(img, 0, 0);
                } else {
                    var c = img.clientWidth / 400;
                    canvas.width = img.clientWidth / c;
                    canvas.height = img.clientHeight / c;
                    canvas.getContext('2d').drawImage(img, 0, 0, img.clientWidth / c, img.clientHeight / c);
                }

                return canvas.toDataURL();
            }

            $scope.toPdf = function() {
                var docDefinition = { content: [
                    { text: 'Розшукується', fontSize: 35, alignment: 'center', bold: true },
                    { text: 'Пропала ' + $scope.animal.type.type + ' породи ' + $scope.animal.breed.breedUa, fontSize: 18, alignment: 'center' },
                    { text: 'Прохання повернути', fontSize: 20, alignment: 'center' },
                    { text: 'конт. тел.: ' + $scope.animal.user.phone, fontSize: 25, alignment: 'center', bold: true },
                    { text: ' ' },
                    { image: convertImgToBase64URL(), alignment: 'center'},
                    { text: ' ' },
                    { text: 'Не залишайтесь байдужими, допоможіть знайти', fontSize: 20, alignment: 'center' },
                    { text: 'ДРУГА !!!', fontSize: 25, alignment: 'center', bold: true }
                ] };

                pdfMake.createPdf(docDefinition).open();
            }

        }]);
{'fraction_non_alphanumeric': 0.11835995016423151, 'fraction_numerical': 0.00600294484086533, 'mean_word_length': 1.4432761483121195, 'pattern_counts': {'":': 0, '<': 4, '<?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': '6274282', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2132, 'n_words': 377}