<commit_before>(function (window, angular) {
    'use strict';

    angular.module('App').controller('EditController', [
        '$scope',
        '$routeParams',
        '$session',
        '$sce',
        function ($scope, $routeParams, $session, $sce)
        {
            $scope.token = $routeParams.newsletterId;

            $scope.editorOptions = {
                language: 'en',
                uiColor: '#000000'
            };

            $scope.variables = [
                {name: 'objColor', value: ''},
                {name: 'objText',  value: ''}
            ];

            $scope.getIframeSrc = function (token) {
                return 'http://localhost:8000/preview/' + token;
            };

            $scope.reloadPreview = function() {
                    var url = $routeParams.newsletterId + '?' + new Date().getTime();
                    $scope.token = $sce.trustAsResourceUrl(url);
            };

            $scope.$watch('variables', function() {
                $session.save($scope.variables).then(saveSuccess, saveError);

                function saveSuccess() {
                    $scope.reloadPreview();
                }

                function saveError() {
                    console.log(error);
                }
            }, true);

            $scope.getData = function() {
                $session.get().then(getSuccess, getError);

                function getSuccess(data) {
                    console.log(data);
                    $scope.variables = data;
                }

                function getError(error) {
                    console.log(error);
                }
            };

            $scope.getData();
        }
    ]);

})(window, angular);<commit_msg>added a 300 milliseconds wait on scope.$watch to no collapse the server with many save petitions<commit_after>(function (window, angular) {
    'use strict';

    var timeOut = null;

    angular.module('App').controller('EditController', [
        '$scope',
        '$routeParams',
        '$session',
        '$sce',
        function ($scope, $routeParams, $session, $sce)
        {
            $scope.token = $routeParams.newsletterId;

            $scope.editorOptions = {
                language: 'en',
                uiColor: '#000000'
            };

            $scope.variables = [
                {name: 'objColor', value: ''},
                {name: 'objText',  value: ''}
            ];

            $scope.getIframeSrc = function (token) {
                return CONFIG.baseURL+ '/preview/' + token;
            };

            $scope.reloadPreview = function() {
                    var url = $routeParams.newsletterId + '?' + new Date().getTime();
                    $scope.token = $sce.trustAsResourceUrl(url);
            };

            $scope.$watch('variables', function() {
                if(timeOut !== null) {
                    clearTimeout(timeOut);
                }
                // Force a 500 milisec timeout to not collapse the server
                timeOut = setTimeout(function(){
                    $session.save($scope.variables).then(saveSuccess, saveError);
                }, 300);

                function saveSuccess() {
                    $scope.reloadPreview();
                }

                function saveError(error) {
                    console.log("Error retrieving data");
                    console.log(error);
                }
            }, true);

            $scope.getData = function() {
                $session.get().then(getSuccess, getError);
                function getSuccess(data) {
                    $scope.variables = data;
                }

                function getError(error) {
                    console.log('Error retrieving data:');
                    console.log(error);
                }
            };

            $scope.getData();
        }
    ]);

})(window, angular);
{'fraction_non_alphanumeric': 0.12861901101716627, 'fraction_numerical': 0.006405329233922624, 'mean_word_length': 1.2763848396501458, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5629789', 'n_tokens_mistral': 1021, 'n_tokens_neox': 920, 'n_words': 179}