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

    angular.module('Editors').controller('ModulesDetailController', ['$scope', '$state', 'survey', 'surveySections', 'SurveyService', 'SurveyPageService', 'MeasureService', function($scope, $state, survey, surveySections, SurveyService, SurveyPageService, MeasureService){

        $scope.survey = survey;
        $scope.surveyPages = [];
        $scope.surveySections = surveySections;
        $scope.alerts = [];

        if (survey.id) {
            survey.getList('pages').then(function(pages) {
                $scope.surveyPages = pages;
            });
        }

        $scope.sortablePageOptions = {
            'ui-floating': false,
            cancel: '.unsortable',
            items: 'li:not(.unsortable)',
            stop: function(e, ui) {
                for (var index in $scope.surveyPages) {
                    //$scope.surveyPages[index].displayOrder = index;
                }
            }
        };

        $scope.sortableQuestionOptions = {
            'ui-floating': false,
            cancel: '.unsortable',
            items: 'li:not(.unsortable)',
            stop: function(e, ui) {
                // Update the display order
                var questions = ui.item.scope().$parent.page.questions;
                for (var index in questions) {
                    questions[index].displayOrder = index;
                }
            }
        };

        $scope.addAlert = function addAlert() {
            $scope.alerts.push({msg: 'Another alert!'});
        };

        $scope.closeAlert = function closeAlert(index) {
            $scope.alerts.splice(index, 1);
        };

        $scope.addPage = function addPage() {
            var page = SurveyPageService.one();
            page.pageNumber = $scope.surveyPages.length + 1;
            $scope.surveyPages.push(page);
        };

        $scope.deletePage = function deletePage(index) {
            surveyPages.splice(index, 1);
        };

        $scope.addQuestion = function addQuestion(page) {
            $scope.question = MeasureService.one();
            page.questions.push($scope.question);
            $state.go('modules.detail.list');
        };

        $scope.getStateName = function getStateName(selectedStateName){
            var stateName;

            switch (selectedStateName){
                case 'freeText':
                    stateName = "modules.detail.question.text";
                    break;
                case 'selectOne':
                    stateName = "modules.detail.question.simple";
                    break;
                case'selectMulti':
                    stateName = "modules.detail.question.simple";
                    break;
                case 'selectOneMatrix':
                    stateName = "modules.detail.question.matrix";
                    break;
                case 'selectMultiMatrix':
                    stateName = "modules.detail.question.matrix";
                    break;
                case 'tableQuestion':
                    stateName = "modules.detail.question.table";
                    break;
                case 'instruction':
                    stateName = "modules.detail.question.instructions";
                    break;
                default:
                    stateName = "modules.detail.question.text";
            }

            return stateName;
        };

        $scope.editQuestion = function editQuestion(page, question){
            var stateName = $scope.getStateName(question.type);

            // Deselect all questions
            _.each(page.questions, function(question) {
                question.selected = false;
            });

            if(Object.isDefined(stateName)) {
                // Set selected on current question
                question.selected = true;

                $scope.question = question;
                $state.go(stateName, {questionId: question.id});
            }
        };

        $scope.deleteQuestion = function deleteQuestion(page, index){
            page.questions.splice(index, 1);
        };

        $scope.save = function () {

            // Remove any existing alerts
            $scope.alerts = [];

            $scope.survey.save().then(function(survey) {
                $scope.alerts.push({type: 'success', msg: 'Module saved successfully'});
            }, function(response) {
                $scope.alerts.push({type: 'danger', msg: 'There was an error saving the module.'});
            });

            _.each($scope.surveyPages, function(page) {
                // Deselect all questions: Server threw an error saying "selected" is not marked as ignorable
                _.each(page.questions, function(question) {
                    delete question.selected;
                });

                page.save().then(function(page) {

                }, function(response) {
                    $scope.alerts.push({type: 'danger', msg: 'There was an error saving module items.'});
                });
            });

            $scope.resetForm(false, {
                name: "modules.detail",
                params: {surveyId: $scope.survey.id},
                doTransition: true
            });
        };

        $scope.cancel = function cancel() {
            $state.go('modules');
        };

    }]);
})();
<commit_msg>t693 Added survey id to pages after creating new survey<commit_after>(function() {
    'use strict';

    angular.module('Editors').controller('ModulesDetailController', ['$scope', '$state', 'survey', 'surveySections', 'SurveyService', 'SurveyPageService', 'MeasureService', function($scope, $state, survey, surveySections, SurveyService, SurveyPageService, MeasureService){

        $scope.survey = survey;
        $scope.surveyPages = [];
        $scope.surveySections = surveySections;
        $scope.alerts = [];

        if (survey.id) {
            survey.getList('pages').then(function(pages) {
                $scope.surveyPages = pages;
            });
        }

        $scope.sortablePageOptions = {
            'ui-floating': false,
            cancel: '.unsortable',
            items: 'li:not(.unsortable)',
            stop: function(e, ui) {
                for (var index in $scope.surveyPages) {
                    //$scope.surveyPages[index].displayOrder = index;
                }
            }
        };

        $scope.sortableQuestionOptions = {
            'ui-floating': false,
            cancel: '.unsortable',
            items: 'li:not(.unsortable)',
            stop: function(e, ui) {
                // Update the display order
                var questions = ui.item.scope().$parent.page.questions;
                for (var index in questions) {
                    questions[index].displayOrder = index;
                }
            }
        };

        $scope.addAlert = function addAlert() {
            $scope.alerts.push({msg: 'Another alert!'});
        };

        $scope.closeAlert = function closeAlert(index) {
            $scope.alerts.splice(index, 1);
        };

        $scope.addPage = function addPage() {
            var page = SurveyService.one($scope.survey.id).one('pages');
            page.pageNumber = $scope.surveyPages.length + 1;
            $scope.surveyPages.push(page);
        };

        $scope.deletePage = function deletePage(index) {
            surveyPages.splice(index, 1);
        };

        $scope.addQuestion = function addQuestion(page) {
            $scope.question = MeasureService.one();
            page.questions.push($scope.question);
            $state.go('modules.detail.list');
        };

        $scope.getStateName = function getStateName(selectedStateName){
            var stateName;

            switch (selectedStateName){
                case 'freeText':
                    stateName = "modules.detail.question.text";
                    break;
                case 'selectOne':
                    stateName = "modules.detail.question.simple";
                    break;
                case'selectMulti':
                    stateName = "modules.detail.question.simple";
                    break;
                case 'selectOneMatrix':
                    stateName = "modules.detail.question.matrix";
                    break;
                case 'selectMultiMatrix':
                    stateName = "modules.detail.question.matrix";
                    break;
                case 'tableQuestion':
                    stateName = "modules.detail.question.table";
                    break;
                case 'instruction':
                    stateName = "modules.detail.question.instructions";
                    break;
                default:
                    stateName = "modules.detail.question.text";
            }

            return stateName;
        };

        $scope.editQuestion = function editQuestion(page, question){
            var stateName = $scope.getStateName(question.type);

            // Deselect all questions
            _.each(page.questions, function(question) {
                question.selected = false;
            });

            if(Object.isDefined(stateName)) {
                // Set selected on current question
                question.selected = true;

                $scope.question = question;
                $state.go(stateName, {questionId: question.id});
            }
        };

        $scope.deleteQuestion = function deleteQuestion(page, index){
            page.questions.splice(index, 1);
        };

        $scope.save = function () {

            // Remove any existing alerts
            $scope.alerts = [];

            $scope.survey.save().then(function(survey) {
                $scope.alerts.push({type: 'success', msg: 'Module saved successfully'});

                _.each($scope.surveyPages, function(page) {
                    page.parentResource.id = survey.id;
                    // Deselect all questions: Server threw an error saying "selected" is not marked as ignorable
                    _.each(page.questions, function(question) {
                        delete question.selected;
                    });

                    page.save().then(function(page) {}, function(response) {
                        $scope.alerts.push({type: 'danger', msg: 'There was an error saving module items.'});
                    });
                });

            }, function(response) {
                $scope.alerts.push({type: 'danger', msg: 'There was an error saving the module.'});
            });

            $scope.resetForm(false, {
                name: "modules.detail",
                params: {surveyId: $scope.survey.id},
                doTransition: true
            });
        };

        $scope.cancel = function cancel() {
            $state.go('modules');
        };

    }]);
})();

{'fraction_non_alphanumeric': 0.11950092421441774, 'fraction_numerical': 0.0010166358595194084, 'mean_word_length': 1.4956180811808117, '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': '5331284', 'n_tokens_mistral': 2802, 'n_tokens_neox': 2612, 'n_words': 513}