<commit_before>'use strict';

angular.module('myApp.node', ['ngRoute', 'drupalService'])

    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider.when('/node', {
            templateUrl: 'node/node.html',
            controller: 'NodeCtrl'
        });
    }])

    .controller('NodeCtrl', function ($scope, ISSUES, MESSAGES, Node, User, TaxonomyTerm, DrupalState, Token) {
        // TODO: DRY this code is used in node_nid.js too.
        var anonymousUser = {
            name: [
                {
                    value: "Anonymous"
                }
            ]
        };

        // How to connect to Drupal
        $scope.auth = DrupalState.get('user').authMethod;

        $scope.issues = {
            'title': 'Front page',
            'items': [
                ISSUES.site.nameSloganLogo,
                ISSUES.views.noPager,
                ISSUES.user.login,
                ISSUES.taxonomy.termList,
                ISSUES.taxonomy.termNotDisplayed
            ]
        };

        // TODO: DRY this code is used in node_nid.js too.
        // Bind tags globally to be usable to print next to each node.
        $scope.tags = TaxonomyTerm.fetch({}, function (data) {
            // nope
        }, function () {
            $scope.messages.push(MESSAGES.termList);

        });

        $scope.breadcrumb = [
            {
                path: '#node',
                title: 'Home'
            }
        ];

        $scope.messages = [];

        $scope.messages.push(MESSAGES.loginMethod);

        $scope.user = DrupalState.get('user');
        if (!$scope.user.token) {
            Token.fetch({}, function (item) {
                $scope.user.token = item.token;
            }, function () {
                $scope.messages.push(MESSAGES.tokenFail);
            });
        }

        $scope.userLogin = function () {
            if ($scope.user.username && $scope.user.password) {
                if ($scope.user.authMethod === 'BASIC_AUTH') {
                    $scope.messages.push(MESSAGES.loginBasicAuth);
                    $scope.user.authenticated = true;
                }
                else if ($scope.user.authMethod === 'COOKIE') {
                    User.login({}, function (result) {
                        $scope.messages.push({text: result.response, type: 'success'});
                        $scope.user.authenticated = true;
                    }, function (result) {
                        $scope.messages.push(MESSAGES.loginFail);
                    });
                }
            }
        };

        $scope.userLogout = function () {
            if ($scope.user.authenticated) {
                $scope.user.password = '';
                if ($scope.user.authMethod === 'BASIC_AUTH') {
                    $scope.user.authenticated = false;
                }
                else if ($scope.user.authMethod === 'COOKIE') {
                    User.logout({}, function (result) {
                        $scope.messages.push({text: result.response, type: 'success'});
                        $scope.user.authenticated = false;
                    }, function (result) {
                        $scope.messages.push(MESSAGES.logoutFail);
                    });
                }
            }
        };

        /**
         * Get the term.name from $scope.tags
         *
         * This requires /taxonomy/list view installed.
         *
         * @param tag
         * @returns {boolean}
         */
        $scope.filterByTag = function (tag) {
            var found = false;
            angular.forEach($scope.tags, function (item, index) {
                if (tag.target_id == item.tid) {
                    found = true;
                }
            });
            return found;
        };

        $scope.nodes = Node.query({}, function (nodes) {
            for (var i = 0; i < $scope.nodes.length; i++) {
                if ($scope.nodes[i]._internals.uid[0].target_id == 0) {
                    $scope.nodes[i].user = anonymousUser;
                } else {
                    $scope.nodes[i].user = User.fetch({uid: $scope.nodes[i]._internals.uid[0].target_id})
                }
            }
        }, function (result) {
            var message = {
                text: MESSAGES.listNodeFail.text + ' (' + result.status + ': ' + result.statusText + ')',
                type: MESSAGES.deleteNodeFail.type
            };
            $scope.messages.push(message);
        });
    });
<commit_msg>Remove the BASIC_AUTH hint as we are defaulting to cookie based sessions.<commit_after>'use strict';

angular.module('myApp.node', ['ngRoute', 'drupalService'])

    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider.when('/node', {
            templateUrl: 'node/node.html',
            controller: 'NodeCtrl'
        });
    }])

    .controller('NodeCtrl', function ($scope, ISSUES, MESSAGES, Node, User, TaxonomyTerm, DrupalState, Token) {
        // TODO: DRY this code is used in node_nid.js too.
        var anonymousUser = {
            name: [
                {
                    value: "Anonymous"
                }
            ]
        };

        // How to connect to Drupal
        $scope.auth = DrupalState.get('user').authMethod;

        $scope.issues = {
            'title': 'Front page',
            'items': [
                ISSUES.site.nameSloganLogo,
                ISSUES.views.noPager,
                ISSUES.user.login,
                ISSUES.taxonomy.termList,
                ISSUES.taxonomy.termNotDisplayed
            ]
        };

        // TODO: DRY this code is used in node_nid.js too.
        // Bind tags globally to be usable to print next to each node.
        $scope.tags = TaxonomyTerm.fetch({}, function (data) {
            // nope
        }, function () {
            $scope.messages.push(MESSAGES.termList);

        });

        $scope.breadcrumb = [
            {
                path: '#node',
                title: 'Home'
            }
        ];

        $scope.messages = [];

        // TODO: no need to push this message when using session based cookie + token
        //$scope.messages.push(MESSAGES.loginMethod);

        $scope.user = DrupalState.get('user');
        if (!$scope.user.token) {
            Token.fetch({}, function (item) {
                $scope.user.token = item.token;
            }, function () {
                $scope.messages.push(MESSAGES.tokenFail);
            });
        }

        $scope.userLogin = function () {
            if ($scope.user.username && $scope.user.password) {
                if ($scope.user.authMethod === 'BASIC_AUTH') {
                    $scope.messages.push(MESSAGES.loginBasicAuth);
                    $scope.user.authenticated = true;
                }
                else if ($scope.user.authMethod === 'COOKIE') {
                    User.login({}, function (result) {
                        $scope.messages.push({text: result.response, type: 'success'});
                        $scope.user.authenticated = true;
                    }, function (result) {
                        $scope.messages.push(MESSAGES.loginFail);
                    });
                }
            }
        };

        $scope.userLogout = function () {
            if ($scope.user.authenticated) {
                $scope.user.password = '';
                if ($scope.user.authMethod === 'BASIC_AUTH') {
                    $scope.user.authenticated = false;
                }
                else if ($scope.user.authMethod === 'COOKIE') {
                    User.logout({}, function (result) {
                        $scope.messages.push({text: result.response, type: 'success'});
                        $scope.user.authenticated = false;
                    }, function (result) {
                        $scope.messages.push(MESSAGES.logoutFail);
                    });
                }
            }
        };

        /**
         * Get the term.name from $scope.tags
         *
         * This requires /taxonomy/list view installed.
         *
         * @param tag
         * @returns {boolean}
         */
        $scope.filterByTag = function (tag) {
            var found = false;
            angular.forEach($scope.tags, function (item, index) {
                if (tag.target_id == item.tid) {
                    found = true;
                }
            });
            return found;
        };

        $scope.nodes = Node.query({}, function (nodes) {
            for (var i = 0; i < $scope.nodes.length; i++) {
                if ($scope.nodes[i]._internals.uid[0].target_id == 0) {
                    $scope.nodes[i].user = anonymousUser;
                } else {
                    $scope.nodes[i].user = User.fetch({uid: $scope.nodes[i]._internals.uid[0].target_id})
                }
            }
        }, function (result) {
            var message = {
                text: MESSAGES.listNodeFail.text + ' (' + result.status + ': ' + result.statusText + ')',
                type: MESSAGES.deleteNodeFail.type
            };
            $scope.messages.push(message);
        });
    });

{'fraction_non_alphanumeric': 0.13157894736842105, 'fraction_numerical': 0.0008735531775496833, 'mean_word_length': 1.281763826606876, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1253096', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2390, 'n_words': 454}