<commit_before>angular.module('unibuddyTimetable.timetable', [
        'ui.state',
        'ui.sortable',
        'flap.topics',
        'arrayMath',
        'colorAllocator',
        'unibuddyTimetable.config',
        'unibuddyTimetable.exporter',
        'unibuddyTimetable.generator',
        'gapi',
        'stopwatch'
    ])

    .config(function config($stateProvider) {
        $stateProvider.state('home', {
            url: '/',
            views: {
                "main": {
                    controller: 'TimetableCtrl',
                    templateUrl: 'timetable/timetable.tpl.html'
                }
            },
            data: { pageTitle: 'UniBuddy University Timetable Planner' }
        });
    })

    .controller('TimetableCtrl', function TimetableController($scope, $location, chosenTopicService, urlService, topicFactory) {

        $scope.$on('chosenClassesUpdate', function () {
            urlService.setTopics(chosenTopicService.getTopics());
        });

        // var loadFromUrl = function () {
        //     var newTopicSerials = urlService.getTopics();
        //     var oldTopics = chosenTopicService.getTopics();

        //     var topicsToRemove = [];

        //     angular.forEach(oldTopics, function (oldTopic) {
        //         var index = newTopicSerials.indexOf(oldTopic.getSerial());

        //         if (index === -1) {
        //             // The old topic should be removed.
        //             topicsToRemove.push(oldTopic);
        //         }
        //         else {
        //             // It isn't actually a new topic! Don't add it later.
        //             newTopicSerials.splice(index, 1);
        //         }
        //     });

        //     angular.forEach(topicsToRemove, function (topic) {
        //         chosenTopicService.removeTopic(topic, false);
        //     });


        //     // Don't try to broadcast while we're still asyncronously loading topics.
        //     var topicsToLoad = newTopicSerials.length;
        //     var broadcastUpdateWhenReady = function () {
        //         if (topicsToLoad === 0) {
        //             chosenTopicService.broadcastTopicsUpdate();
        //         }
        //     };

        //     // Load all of the new topics
        //     angular.forEach(newTopicSerials, function (topicSerial) {
        //         topicFactory.loadTopicFromSerialAsync(topicSerial, function (topic) {
        //             topicsToLoad--;

        //             chosenTopicService.addTopic(topic, false);
        //             broadcastUpdateWhenReady();
        //         });
        //     });

        //     broadcastUpdateWhenReady();
        // };

        // $scope.$watch(function () {
        //     return $location.search();
        // }, function () {
        //     loadFromUrl();
        // });


        // loadFromUrl();<commit_msg>fixes url loading; comments out something I'm not sure the purpose of; fixes clowny function decl<commit_after>angular.module('unibuddyTimetable.timetable', [
        'ui.state',
        'ui.sortable',
        'flap.topics',
        'arrayMath',
        'colorAllocator',
        'unibuddyTimetable.config',
        'unibuddyTimetable.exporter',
        'unibuddyTimetable.generator',
        'gapi',
        'stopwatch'
    ])

    .config(function config($stateProvider) {
        $stateProvider.state('home', {
            url: '/',
            views: {
                "main": {
                    controller: 'TimetableCtrl',
                    templateUrl: 'timetable/timetable.tpl.html'
                }
            },
            data: { pageTitle: 'UniBuddy University Timetable Planner' }
        });
    })

    .controller('TimetableCtrl', function TimetableController($scope, $location, chosenTopicService, urlService, topicFactory) {

        $scope.$on('chosenClassesUpdate', function () {
            urlService.setTopics(chosenTopicService.getTopics());
        });

        function loadFromUrl() {
            var newTopicSerials = urlService.getTopics();
            var oldTopics = chosenTopicService.getTopics();

            var topicsToRemove = [];

            angular.forEach(oldTopics, function (oldTopic) {
                var index = newTopicSerials.indexOf(oldTopic.getSerial());

                if (index === -1) {
                    // The old topic should be removed.
                    topicsToRemove.push(oldTopic);
                }
                else {
                    // It isn't actually a new topic! Don't add it later.
                    newTopicSerials.splice(index, 1);
                }
            });

            angular.forEach(topicsToRemove, function (topic) {
                chosenTopicService.removeTopic(topic, false);
            });


            // Don't try to broadcast while we're still asyncronously loading topics.
            var topicsToLoad = newTopicSerials.length;
            var broadcastUpdateWhenReady = function () {
                if (topicsToLoad === 0) {
                    chosenTopicService.broadcastTopicsUpdate();
                }
            };

            // Load all of the new topics
            angular.forEach(newTopicSerials, function (topicSerial) {
                topicFactory.loadTopicFromSerialAsync(topicSerial, function (topic) {
                    topicsToLoad--;

                    chosenTopicService.addTopic(topic, false);
                    broadcastUpdateWhenReady();
                });
            });

            broadcastUpdateWhenReady();
        }

        // $scope.$watch(function () {
        //     return $location.search();
        // }, function () {
        //     loadFromUrl();
        // });


        loadFromUrl();
{'fraction_non_alphanumeric': 0.11829268292682926, 'fraction_numerical': 0.0010452961672473868, 'mean_word_length': 1.4906724511930585, 'pattern_counts': {'":': 2, '<': 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': '1339104', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1443, 'n_words': 263}