<commit_before>'use strict';

/**
 * @ngdoc directive
 * @name labelsApp.lsVocabs
 * @description
 * # lsVocabs
 */
 angular.module('labelsApp')
  .component('lsVocabs', {
    bindings: {
        mode: "@"
    },
    templateUrl: "scripts/components/vocabs/vocabs.html",
    controller: ["$scope", "ngDialog", "$location", "$timeout", "$rootScope", "AuthService", "VocabService", "ThesauriService", "CachingService", function($scope, ngDialog, $location, $timeout, $rootScope, AuthService, VocabService, ThesauriService, CachingService) {

        var ctrl = this;
        ctrl.user = null;

        ctrl.$onInit = function () {

            ctrl.loading = true;
            // get filters from cache
            if (CachingService.filters.vocabs) {
                $scope.vocabFilter = CachingService.filters.vocabs;
            }

        };

        ctrl.$onDestroy = function () {
            if (AuthService.isLoggedIn()) {  //prevents caching after logout
                // cache filter value
                CachingService.filters.vocabs = $scope.vocabFilter;

                // cache vocabs
                CachingService[ctrl.mode].vocabs = $scope.vocabularies;
            }
        };

        $rootScope.$watch("isAuthenticated", function(isAuthenticated) {
            if (ctrl.mode === "editor" && isAuthenticated) {
                ctrl.loadEditorVocabs();
            } else if (ctrl.mode === "viewer") {
                ctrl.loadPublicVocabs();
            }
        });

        ctrl.loadEditorVocabs = function() {
            if (CachingService.editor.vocabs) {
                $scope.vocabularies = CachingService.editor.vocabs;
                ctrl.loading = false;
            } else {
                VocabService.query({
                    creator: AuthService.getUser().id,
                    draft: true,
                    statistics: true
                }, function(vocabs) {
                    $scope.vocabularies = vocabs;
                    ctrl.loading = false;
                });
            }
        };

        ctrl.loadPublicVocabs = function() {
            if (CachingService.viewer.vocabs) {
                $scope.vocabularies = CachingService.viewer.vocabs;
                ctrl.loading = false;
            } else {
                VocabService.query({ statistics: true, creatorInfo: true }, function(vocabs) {
                    $scope.vocabularies = vocabs;
                    ctrl.loading = false;
                }, function error(res) {
                    console.log(res);
                });
            }
        };

        $scope.$on("addedVocab", function(event, data) {
            VocabService.save(data.vocab, function(res) {
                $scope.vocabularies.push(res);

                // update the thesauri for the new vocab and add the default ones
                var vocabThesauri = [];
                ThesauriService.query(function(thesauri) {
                    thesauri.forEach(function(thesaurus) {
                        if (thesaurus.default) {
                            vocabThesauri.push(thesaurus);
                        }
                    });

                    // update
                    ThesauriService.update({id: res.id}, vocabThesauri, function() {
                        // redirect when everything finished
                        ngDialog.closeAll();
                        $location.path("/editor/vocabularies/" + res.id + "/concepts");

                    }, function error(res) {<commit_msg>improved vocabs loading speed in viewer<commit_after>'use strict';

/**
 * @ngdoc directive
 * @name labelsApp.lsVocabs
 * @description
 * # lsVocabs
 */
 angular.module('labelsApp')
  .component('lsVocabs', {
    bindings: {
        mode: "@"
    },
    templateUrl: "scripts/components/vocabs/vocabs.html",
    controller: ["$scope", "ngDialog", "$location", "$timeout", "$rootScope", "AuthService", "VocabService", "ThesauriService", "CachingService", function($scope, ngDialog, $location, $timeout, $rootScope, AuthService, VocabService, ThesauriService, CachingService) {

        var ctrl = this;
        ctrl.user = null;

        ctrl.$onInit = function () {

            ctrl.loading = true;
            // get filters from cache
            if (CachingService.filters.vocabs) {
                $scope.vocabFilter = CachingService.filters.vocabs;
            }

        };

        ctrl.$onDestroy = function () {
            if (AuthService.isLoggedIn()) {  //prevents caching after logout
                // cache filter value
                CachingService.filters.vocabs = $scope.vocabFilter;

                // cache vocabs
                CachingService[ctrl.mode].vocabs = $scope.vocabularies;
            }
        };

        $rootScope.$watch("isAuthenticated", function(isAuthenticated) {
            if (ctrl.mode === "editor" && isAuthenticated) {
                ctrl.loadEditorVocabs();
            } else if (ctrl.mode === "viewer") {
                ctrl.loadPublicVocabs();
            }
        });

        ctrl.loadEditorVocabs = function() {
            if (CachingService.editor.vocabs) {
                $scope.vocabularies = CachingService.editor.vocabs;
                ctrl.loading = false;
            } else {
                VocabService.query({
                    creator: AuthService.getUser().id,
                    draft: true,
                    statistics: true
                }, function(vocabs) {
                    $scope.vocabularies = vocabs;
                    ctrl.loading = false;
                });
            }
        };

        ctrl.loadPublicVocabs = function() {
            if (CachingService.viewer.vocabs) {
                $scope.vocabularies = CachingService.viewer.vocabs;
                ctrl.loading = false;
            } else {
                VocabService.query({ creatorInfo: true }, function(vocabs) {
                    $scope.vocabularies = vocabs;
                    ctrl.loading = false;
                }, function error(res) {
                    console.log(res);
                });
            }
        };

        $scope.$on("addedVocab", function(event, data) {
            VocabService.save(data.vocab, function(res) {
                $scope.vocabularies.push(res);

                // update the thesauri for the new vocab and add the default ones
                var vocabThesauri = [];
                ThesauriService.query(function(thesauri) {
                    thesauri.forEach(function(thesaurus) {
                        if (thesaurus.default) {
                            vocabThesauri.push(thesaurus);
                        }
                    });

                    // update
                    ThesauriService.update({id: res.id}, vocabThesauri, function() {
                        // redirect when everything finished
                        ngDialog.closeAll();
                        $location.path("/editor/vocabularies/" + res.id + "/concepts");

                    }, function error(res) {
{'fraction_non_alphanumeric': 0.11357813834329633, 'fraction_numerical': 0.0, 'mean_word_length': 1.4673455056179776, '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': '7543590', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1873, 'n_words': 327}