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

    var bestSellerController = function ($scope, bestSellerFactory) {

        var model = $scope.model = {};
        model.bestSellers = [];
        model.categories = [];

        model.getCategories = function() {
            bestSellerFactory.getCategories()
                .get(function(results) {
                    model.categories = results.results;
                });
        };

        model.getDetail = function (book, detail) {
            return book.book_details[0][detail];
        };

        model.getDataFor = function (category) {
            if (category === undefined ||
                category === null) return;

            category = category.split(" ").join("-");

            bestSellerFactory.getBestSellers(category)
               .get(function (results) {
                   model.bestSellers = results.results;
               });
        };

        var init = function() {
            model.getCategories();
            // model.getDataFor(model.selectedCategory.list_name); // NOT SURE WHY THIS WONT WORK
        };
        init();

    };

    angular.module("bestSellersApp").controller("bestSellerController", [ "$scope", "bestSellerFactory", bestSellerController ]);
}());<commit_msg>Using promises to populate initial screen<commit_after>/* global angular,console */
(function () {
    "use strict";

    var bestSellerController = function ($scope, bestSellerFactory) {

        var model = $scope.model = {};
        model.bestSellers = [];
        model.categories = [];

        model.getCategories = function() {
            return bestSellerFactory.getCategories()
                        .get(function(results) {
                            model.categories = results.results;
                        });
        };

        model.getDetail = function (book, detail) {
            return book.book_details[0][detail];
        };

        model.getDataFor = function (category) {
            if (category === undefined ||
                category === null) return;

            category = category.split(" ").join("-");

            bestSellerFactory.getBestSellers(category)
               .get(function (results) {
                   model.bestSellers = results.results;
               });

        };

        var init = function() {
            model.getCategories().$promise //this is calling model.getCategories() first, before handing over the $promise
                .then(function() {
                    model.selectedCategory = model.categories[0]; // This will update the drop-down when the page loads.
                    model.getDataFor(model.selectedCategory.list_name);
                // },function (reason) {
                //     console.log("Sorry, failed :" + reason);
                });
        };
        init();

    };

    angular.module("bestSellersApp").controller("bestSellerController", [ "$scope", "bestSellerFactory", bestSellerController ]);
}());
{'fraction_non_alphanumeric': 0.12687312687312688, 'fraction_numerical': 0.000999000999000999, 'mean_word_length': 1.7970204841713222, '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': '2132722', 'n_tokens_mistral': 753, 'n_tokens_neox': 719, 'n_words': 149}