<commit_before>app.factory('DomainsFactory', ['$resource', function($resource) {
    return $resource('/domain/:id', { id: '@id' }, {
        update: {
            method: 'PUT'
        }
    });
}]);

app.service('Domains', ['$rootScope', '$log', '$q', 'DomainsFactory',
    function($rootScope, $log, $q, DomainsFactory) {
        var service = {};

        service.all = [];
        service.deleted_domains = [];

        service.query = function(ret_func) {
            if (service.all.length == 0) {
                $log.debug("Fetching list of domains.");
                service.all = DomainsFactory.query(ret_func);

                return service.all;
            }
            else {
                ret_func();
                return service.all;
            }
        };

        service.save = function(data, success, error) {
            DomainsFactory.save(data, function(value, responseHeader) {
                service.all.push(value);

                success(value, responseHeader);
            }, function(httpResponse) {
                error(httpResonse);
            });
        }

        service.delete = function(domain) {
            (function() {
                var domain_id = domain.id;

                angular.forEach(service.all, function(value, $index) {
                    if (domain_id == value.id) {
                        service.all.splice($index, 1);
                    }
                });

                service.deleted_domains.push(angular.copy(domain));

                domain.$delete(function(value, reponseHeader) {
                    angular.forEach(service.deleted_domains, function(value, $index) {
                        if (domain_id == value.id) {
                            service.deleted_domains.splice($index, 1);
                        }
                    });
                }, function(httpResponse) {
                    $log.error('Unable to delete domain entry. %o', httpResonse);
                });
            })();
        }

        $log.debug("Initialised Domains");

        service.query(function() {});

        return service;
    }
]);<commit_msg>Add state information to Domain service<commit_after>app.factory('DomainsFactory', ['$resource', function($resource) {
    return $resource('/domain/:id', { id: '@id' }, {
        update: {
            method: 'PUT'
        }
    });
}]);

app.service('Domains', ['$rootScope', '$log', '$q', 'DomainsFactory',
    function($rootScope, $log, $q, DomainsFactory) {
        var service = {};

        service.state = {};
        service.state.loaded = false;
        service.all = [];
        service.deleted_domains = [];

        service.query = function(ret_func) {
            if (service.all.length == 0) {
                $log.debug("Fetching list of domains.");
                service.all = DomainsFactory.query(ret_func);

                return service.all;
            }
            else {
                ret_func();
                return service.all;
            }
        };

        service.save = function(data, success, error) {
            DomainsFactory.save(data, function(value, responseHeader) {
                service.all.push(value);

                success(value, responseHeader);
            }, function(httpResponse) {
                error(httpResonse);
            });
        }

        service.delete = function(domain) {
            (function() {
                var domain_id = domain.id;

                angular.forEach(service.all, function(value, $index) {
                    if (domain_id == value.id) {
                        service.all.splice($index, 1);
                    }
                });

                service.deleted_domains.push(angular.copy(domain));

                domain.$delete(function(value, reponseHeader) {
                    angular.forEach(service.deleted_domains, function(value, $index) {
                        if (domain_id == value.id) {
                            service.deleted_domains.splice($index, 1);
                        }
                    });
                }, function(httpResponse) {
                    $log.error('Unable to delete domain entry. %o', httpResonse);
                });
            })();
        }

        $log.debug("Initialised Domains");

        service.query(function() {
            service.state.loaded = true;
        });

        return service;
    }
]);
{'fraction_non_alphanumeric': 0.1326530612244898, 'fraction_numerical': 0.0013605442176870747, 'mean_word_length': 1.4196379594075699, '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': '5512725', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1100, 'n_words': 190}