<commit_before>angular.module('myApp').controller('Contribute/GlaasCtrl', function($scope, $routeParams, $location, Restangular, QuestionAssistant) {
    'use strict';

    $scope.questionnaireQueryParams = {permission: 'update', fields: 'permissions', surveyType: 'glaas'};

    // If a questionnaire is specified in URL, load its data
    if ($routeParams.id) {
        $scope.isLoading = true;
        Restangular.one('questionnaire', $routeParams.id).all('question').getList({perPage: 1000, fields: 'type,filter,answers,isCompulsory,choices,parts,isMultiple,isFinal,chapter,description'}).then(function(questions) {
            $scope.questions = questions;
            $scope.isLoading = false;
        });
    }

    $scope.navigation = []; // used in next + previous buttons
    $scope.hierarchicQuestions = []; // used in hierarchic menu
    $scope.currentIndex = 0;
    $scope.currentQuestion = 0;
    $scope.index = {}; // indexed answers
    $scope.score = {};

    $scope.$watch(function() {
        return $location.url();
    }, function() {
        $scope.returnUrl = $location.search().returnUrl;
        $scope.currentUrl = encodeURIComponent($location.url());
    });

    $scope.$watch('questionnaire', function() {
        $scope.initializeQuestionnaire();
    });

    $scope.$watch('questions', function() {
        $scope.initializeQuestionnaire();
    });

    $scope.$watch('currentIndex', function(newIndex, old) {
        if (newIndex !== old) {
            $scope.refreshQuestion();
        }
    });

    var questionnaire2 = null;
    $scope.initializeQuestionnaire = function() {
        if ($scope.questionnaire && $scope.questions && $scope.questions.length > 0) {

            var questionnaire2 = _.cloneDeep($scope.questionnaire);
            questionnaire2.level = -1;
            questionnaire2.index = -1;
            questionnaire2.statusCode = 4;

            $scope.questions[0].active = true;

            angular.forEach($scope.questions, function(question, index) {

                // assign key to each question -> navigation menu bar uses it to avoid loops
                question.index = index;

                // prepare navigation
                question.hasFinalParentChapters = $scope.hasFinalParentChapters(index);
                if (question && question.type && !question.hasFinalParentChapters) {<commit_msg>Load permissions only when needed #2781<commit_after>angular.module('myApp').controller('Contribute/GlaasCtrl', function($scope, $routeParams, $location, Restangular, QuestionAssistant) {
    'use strict';

    $scope.questionnaireQueryParams = {permission: 'update', surveyType: 'glaas'};

    // If a questionnaire is specified in URL, load its data
    if ($routeParams.id) {
        $scope.isLoading = true;
        Restangular.one('questionnaire', $routeParams.id).all('question').getList({perPage: 1000, fields: 'type,filter,answers,isCompulsory,choices,parts,isMultiple,isFinal,chapter,description'}).then(function(questions) {
            $scope.questions = questions;
            $scope.isLoading = false;
        });
    }

    $scope.navigation = []; // used in next + previous buttons
    $scope.hierarchicQuestions = []; // used in hierarchic menu
    $scope.currentIndex = 0;
    $scope.currentQuestion = 0;
    $scope.index = {}; // indexed answers
    $scope.score = {};

    $scope.$watch(function() {
        return $location.url();
    }, function() {
        $scope.returnUrl = $location.search().returnUrl;
        $scope.currentUrl = encodeURIComponent($location.url());
    });

    $scope.$watch('questionnaire', function() {
        $scope.initializeQuestionnaire();
    });

    $scope.$watch('questions', function() {
        $scope.initializeQuestionnaire();
    });

    $scope.$watch('currentIndex', function(newIndex, old) {
        if (newIndex !== old) {
            $scope.refreshQuestion();
        }
    });

    var questionnaire2 = null;
    $scope.initializeQuestionnaire = function() {
        if ($scope.questionnaire && $scope.questions && $scope.questions.length > 0) {

            var questionnaire2 = _.cloneDeep($scope.questionnaire);

            // Load questionnaire permissions
            Restangular.one('questionnaire', $routeParams.id).get({fields: 'permissions'}).then(function(questionnaire) {
                $scope.questionnaire.permissions = questionnaire.permissions;
                questionnaire2.permissions = $scope.questionnaire.permissions;
            });

            questionnaire2.level = -1;
            questionnaire2.index = -1;
            questionnaire2.statusCode = 4;

            $scope.questions[0].active = true;

            angular.forEach($scope.questions, function(question, index) {

                // assign key to each question -> navigation menu bar uses it to avoid loops
                question.index = index;

                // prepare navigation
                question.hasFinalParentChapters = $scope.hasFinalParentChapters(index);
                if (question && question.type && !question.hasFinalParentChapters) {
{'fraction_non_alphanumeric': 0.13597009051554507, 'fraction_numerical': 0.007280598189689099, 'mean_word_length': 2.751291512915129, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '238028', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1323, 'n_words': 263}