<commit_before>(function (angular) {
    "use strict";

    var app = angular.module('myApp.survey', ['ngRoute', 'firebase.utils', 'firebase']);

    app.controller('SurveyCtrl', ['$scope', '$routeParams', '$location', 'user', 'fbutil', function ($scope, $routeParams, $location, user, fbutil) {
        var surveyHeaderID = $routeParams.surveyHeaderID;

        /* TODO 1: Check if user already has this survey in their profile */
        console.log(user.uid);
   
        
        var ref = fbutil.ref();
        ref.once("value", function (snapshot) {
            //if (snapshot.child("users/2f75583e-4199-4424-83ad-f6486e4b45e9/surveys/-K-t52g5-osgYHQ_xJir").exists()) {
            if (snapshot.child("users/" + user.uid + "/surveys/" + surveyHeaderID).exists()) {
                console.log("OK")
            } else {
                /* TODO 2: If user does not yet have survey in their profile, add it */
                ref.child("/users/" + user.uid + "/surveys/" + surveyHeaderID).set(true);
            }
        });
        
        /* TODO 3: Fetch /SurveyHeaders/<surveyHeaderID> and check its type (template.nameSurvey) */
        ref.child("SurveyHeaders/" + surveyHeaderID + "/template/nameSurvey").once("value", function (data) {
            console.log(data.val());
            var surveyType = data.val().toLowerCase();

            if(['tpp', 'gallop'].indexOf(surveyType) !== -1) {
                /* TODO 4: Redirect to corresponding Survey controller (TPP, etc) */
                $location.path('/survey/' + surveyType + '/' + surveyHeaderID);
                $scope.$apply();
            } else {
                /* TODO: show proper error message; type does not exist */
                alert('Survey type does not exist!');<commit_msg>remove console.log<commit_after>(function (angular) {
    "use strict";

    var app = angular.module('myApp.survey', ['ngRoute', 'firebase.utils', 'firebase']);

    app.controller('SurveyCtrl', ['$scope', '$routeParams', '$location', 'user', 'fbutil', function ($scope, $routeParams, $location, user, fbutil) {
        var surveyHeaderID = $routeParams.surveyHeaderID;

        /* TODO 1: Check if user already has this survey in their profile */
        
   
        
        var ref = fbutil.ref();
        ref.once("value", function (snapshot) {
            //if (snapshot.child("users/2f75583e-4199-4424-83ad-f6486e4b45e9/surveys/-K-t52g5-osgYHQ_xJir").exists()) {
            if (snapshot.child("users/" + user.uid + "/surveys/" + surveyHeaderID).exists()) {
                
            } else {
                /* TODO 2: If user does not yet have survey in their profile, add it */
                ref.child("/users/" + user.uid + "/surveys/" + surveyHeaderID).set(true);
            }
        });
        
        /* TODO 3: Fetch /SurveyHeaders/<surveyHeaderID> and check its type (template.nameSurvey) */
        ref.child("SurveyHeaders/" + surveyHeaderID + "/template/nameSurvey").once("value", function (data) {
            
            var surveyType = data.val().toLowerCase();

            if(['tpp', 'gallop'].indexOf(surveyType) !== -1) {
                /* TODO 4: Redirect to corresponding Survey controller (TPP, etc) */
                $location.path('/survey/' + surveyType + '/' + surveyHeaderID);
                $scope.$apply();
            } else {
                /* TODO: show proper error message; type does not exist */
                alert('Survey type does not exist!');
{'fraction_non_alphanumeric': 0.15495391705069125, 'fraction_numerical': 0.018433179723502304, 'mean_word_length': 2.1572727272727272, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6845837', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1003, 'n_words': 237}