<commit_before>'use strict';

angular.module('ngQuestionnaires.questionnaireEditController', [])
    .controller('questionnaireEditController', [
        '$scope',
        '$cacheFactory',
        '$location',
        '$routeParams',
        'questionnaires',
        'questions',
        function ($scope, $cacheFactory, $location, $routeParams, questionnaires, questions) {
            var questionnaire = $cacheFactory.get('data').get('questionnaire'),
                navigate = function () {
                    $cacheFactory.get('data').remove('questionnaire');
                    $location.url('/questionnaires/list');
                };

            $scope.action = 'Edit';

            if (questionnaire !== undefined) {
                $scope.questionnaire = questionnaire;
                $cacheFactory.get('data').remove('questionnaire');
            }

            $scope.questions = questions;

            $scope.addQuestion = function () {
                $cacheFactory.get('data').put('questionnaire', $scope.questionnaire);
                $location.url('/questions/new?returnUrl=' + $location.url());
            };

            $scope.update = function () {
                questionnaires.update(angular.copy($scope.questionnaire));
                navigate();
            };

            $scope.cancel = function () {
                navigate();
            };
        }]);<commit_msg>Implemented edit questionnaire controller<commit_after>'use strict';

angular.module('ngQuestionnaires.questionnaireEditController', [])
    .controller('questionnaireEditController', [
        '$scope',
        '$cacheFactory',
        '$location',
        '$routeParams',
        'fbUrl',
        'Firebase',
        'angularFire',
        'angularFireCollection',
        function ($scope, $cacheFactory, $location, $routeParams, fbUrl, Firebase, angularFire, angularFireCollection) {
            var questionnaire = $cacheFactory.get('data').get('questionnaire'),
                ref = new Firebase(fbUrl + 'questionnaires/' + $routeParams.id);

            function navigate() {
                $cacheFactory.get('data').remove('questionnaire');
                $location.url('/questionnaires/list');
            }

            $scope.action = 'Edit';

            if (questionnaire === undefined) {
                angularFire(ref, $scope, 'questionnaire');
            } else {
                $scope.questionnaire = questionnaire;
                $cacheFactory.get('data').remove('questionnaire');
            }

            $scope.questions = angularFireCollection(new Firebase(fbUrl + 'questions'));

            $scope.addQuestion = function () {
                $cacheFactory.get('data').put('questionnaire', $scope.questionnaire);
                $location.url('/questions/new?returnUrl=' + $location.url());
            };

            $scope.update = function () {
                ref.set($scope.questionnaire);
                navigate();
            };

            $scope.cancel = function () {
                navigate();
            };
        }]);
{'fraction_non_alphanumeric': 0.14146341463414633, 'fraction_numerical': 0.0, 'mean_word_length': 1.9156398104265402, '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': '5519847', 'n_tokens_mistral': 761, 'n_tokens_neox': 716, 'n_words': 112}