<commit_before>(function () {
    'use strict';

    angular
        .module('orange')
        .factory('BasePagingService', BasePagingService)
        .factory('PatientPagingService', PatientPagingService);

    BasePagingService.$inject = ['$rootScope', '$q', 'OrangeApi', 'settings'];
    PatientPagingService.$inject = ['$rootScope', 'BasePagingService', 'PatientService'];

    /**
     * Base Paging service works through OrangeApi
     */
    function BasePagingService($rootScope, $q, OrangeApi, settings) {
        var Service = function () {

            this.apiEndpoint = '';
            this.items = null;
            this.item = null;
            this.count = 0;
            this.offset = 0;
            this.limit = settings.defaultLimit;
            this.sortBy = 'id';
            this.sortOrder = 'asc';

            $rootScope.$on('auth:user:logout', this.clear.bind(this));
        };

        Service.prototype.getItems = getItems;
        Service.prototype.hasMore = hasMore;
        Service.prototype.moreItems = moreItems;
        Service.prototype.setItem = setItem;
        Service.prototype.getItem = getItem;
        Service.prototype.removeItem = removeItem;
        Service.prototype.saveItem = saveItem;
        Service.prototype.clear = clear;

        Service.prototype.getNewItemPromise = getNewItemPromise;
        Service.prototype.newItemSuccess = newItemSuccess;
        Service.prototype.getFetchPromise = getFetchPromise;
        Service.prototype.fetchItemsSuccess = fetchItemsSuccess;

        return Service;

        function initItems() {
            var self = this;
            this.offset = 0;
            return fetchItems.apply(this).then(function (items) {
                self.items = items;
                self.offset = self.limit;
                return self.items;
            });
        }

        function clear() {
            this.items = null;
            this.item = null;
            this.count = 0;
            this.offset = 0;
        }

        function getItems(force) {
            force = force || false;
            if (this.items == null || force) {
                return initItems.apply(this);
            } else {
                var deferred = $q.defer();
                deferred.resolve(this.items);
                return deferred.promise;
            }
        }

        function fetchItems(options) {
            options = options || {};
            var opts = {
                    limit: options['limit'] || this.limit,
                    offset: options['offset'] || this.offset,
                    sort_by: options['sortBy'] || this.sortBy,
                    sort_order: options['sortOrder'] || this.sortOrder
                };

            return this.getFetchPromise(opts);
        }

        function getFetchPromise(options) {
            return OrangeApi[this.apiEndpoint].getList(options).then(
                this.fetchItemsSuccess.bind(this)
            );
        }<commit_msg>[artefact][ORANGE-130] Method get all items<commit_after>(function () {
    'use strict';

    angular
        .module('orange')
        .factory('BasePagingService', BasePagingService)
        .factory('PatientPagingService', PatientPagingService);

    BasePagingService.$inject = ['$rootScope', '$q', 'OrangeApi', 'settings'];
    PatientPagingService.$inject = ['$rootScope', 'BasePagingService', 'PatientService'];

    /**
     * Base Paging service works through OrangeApi
     */
    function BasePagingService($rootScope, $q, OrangeApi, settings) {
        var Service = function () {

            this.apiEndpoint = '';
            this.items = null;
            this.item = null;
            this.count = 0;
            this.offset = 0;
            this.limit = settings.defaultLimit;
            this.sortBy = 'id';
            this.sortOrder = 'asc';

            $rootScope.$on('auth:user:logout', this.clear.bind(this));
        };

        Service.prototype.getItems = getItems;
        Service.prototype.getAllItems = getAllItems;
        Service.prototype.hasMore = hasMore;
        Service.prototype.moreItems = moreItems;
        Service.prototype.setItem = setItem;
        Service.prototype.getItem = getItem;
        Service.prototype.removeItem = removeItem;
        Service.prototype.saveItem = saveItem;
        Service.prototype.clear = clear;

        Service.prototype.getNewItemPromise = getNewItemPromise;
        Service.prototype.newItemSuccess = newItemSuccess;
        Service.prototype.getFetchPromise = getFetchPromise;
        Service.prototype.fetchItemsSuccess = fetchItemsSuccess;

        return Service;

        function initItems(all) {
            all = all || false;
            var self = this,
                options = {
                    limit: all ? 0 : this.limit
                };
            this.offset = 0;
            return fetchItems.call(this, options).then(function (items) {
                self.items = items;
                self.offset = all ? items.meta['count'] : self.limit;
                return self.items;
            });
        }

        function clear() {
            this.items = null;
            this.item = null;
            this.count = 0;
            this.offset = 0;
        }

        function getItems(force) {
            force = force || false;
            if (this.items == null || force) {
                return initItems.apply(this);
            } else {
                var deferred = $q.defer();
                deferred.resolve(this.items);
                return deferred.promise;
            }
        }

        function getAllItems(force) {
            if (force || this.count === 0 || this.count > this.offset) {
                return initItems.call(this, true);
            } else {
                return this.getItems();
            }
        }

        function fetchItems(options) {
            options = options || {};
            var opts = {
                    limit: options['limit'] !== undefined ? options['limit'] : this.limit,
                    offset: options['offset'] !== undefined ? options['offset'] : this.offset,
                    sort_by: options['sortBy'] || this.sortBy,
                    sort_order: options['sortOrder'] || this.sortOrder
                };

            return this.getFetchPromise(opts);
        }

        function getFetchPromise(options) {
            return OrangeApi[this.apiEndpoint].getList(options).then(
                this.fetchItemsSuccess.bind(this)
            );
        }
{'fraction_non_alphanumeric': 0.11215096655415771, 'fraction_numerical': 0.0023013194231359313, 'mean_word_length': 1.6993788819875777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1996033', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1621, 'n_words': 323}