<commit_before>angular.module('codebrag.licence')

    .service('licenceService', function($http, $q, $rootScope, events, $timeout, $modal) {

        var warningDays = 14,
            licenceData = {},
            ready = $q.defer(),
            checkTimer,
            checkInterval = 6 * 3600 * 1000; // 6 hours (in millis)

        function scheduleLicenceCheck() {
            ready = $q.defer();
            return loadLicenceData().then(scheduleNextCheck).then(fireEvents).then(function() {
                ready.resolve();
            });
            function scheduleNextCheck() {
                checkTimer && $timeout.cancel(checkTimer);
                checkTimer = $timeout(function() {
                    loadLicenceData().then(scheduleNextCheck).then(fireEvents)
                }, checkInterval);
            }
        }

        function loadLicenceData() {
            return $http.get('rest/licence').then(function(response) {
                licenceData = response.data;
                return licenceData;
            });
        }

        function serviceReady() {
            return ready.promise;
        }

        function getLicenceData() {
            return licenceData;
        }

        function fireEvents() {
            var daysToWarning = licenceData.daysLeft - warningDays;
            if(licenceData.valid && daysToWarning < 0) {
                $rootScope.$broadcast('codebrag:licenceAboutToExpire');
            }
            if(!licenceData.valid && !fireEvents.initialExpirationEvent) {
                $rootScope.$broadcast('codebrag:licenceExpired');
                fireEvents.initialExpirationEvent = true
            }
        }

        function initialize() {
            $rootScope.$on(events.loggedIn, scheduleLicenceCheck);
            $rootScope.$on('codebrag:openLicencePopup', licencePopup);
            $rootScope.$on('codebrag:licenceExpired',licencePopup);
        }

        function licencePopup(once) {
            if(licencePopup.displayed) return;
            var repoStatusModalConfig = {
                backdrop: false,
                keyboard: true,
                controller: 'LicenceInfoCtrl',<commit_msg>Fix - don't display licence badge when licence data not fetched from server yet<commit_after>angular.module('codebrag.licence')

    .service('licenceService', function($http, $q, $rootScope, events, $timeout, $modal) {

        var warningDays = 14,
            licenceData = {},
            ready = $q.defer(),
            checkTimer,
            checkInterval = 6 * 3600 * 1000; // 6 hours (in millis)

        function scheduleLicenceCheck() {
            return loadLicenceData().then(scheduleNextCheck).then(fireEvents).then(function() {
                console.log('resolved');
                ready.resolve();
            });
            function scheduleNextCheck() {
                checkTimer && $timeout.cancel(checkTimer);
                checkTimer = $timeout(function() {
                    loadLicenceData().then(scheduleNextCheck).then(fireEvents)
                }, checkInterval);
            }
        }

        function loadLicenceData() {
            return $http.get('rest/licence').then(function(response) {
                licenceData = response.data;
                return licenceData;
            });
        }

        function serviceReady() {
            return ready.promise;
        }

        function getLicenceData() {
            return licenceData;
        }

        function fireEvents() {
            var daysToWarning = licenceData.daysLeft - warningDays;
            if(licenceData.valid && daysToWarning < 0) {
                $rootScope.$broadcast('codebrag:licenceAboutToExpire');
            }
            if(!licenceData.valid && !fireEvents.initialExpirationEvent) {
                console.log('aaa');
                $rootScope.$broadcast('codebrag:licenceExpired');
                fireEvents.initialExpirationEvent = true
            }
        }

        function initialize() {
            $rootScope.$on(events.loggedIn, scheduleLicenceCheck);
            $rootScope.$on('codebrag:openLicencePopup', licencePopup);
            $rootScope.$on('codebrag:licenceExpired',licencePopup);
        }

        function licencePopup(once) {
            if(licencePopup.displayed) return;
            var repoStatusModalConfig = {
                backdrop: false,
                keyboard: true,
                controller: 'LicenceInfoCtrl',
{'fraction_non_alphanumeric': 0.10745466756212223, 'fraction_numerical': 0.005820461159614954, 'mean_word_length': 1.808296668761785, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2267726', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1110, 'n_words': 187}