<commit_before>angular.module('history', [])
	.controller('HistoryController', function($scope, $ionicPopup, $ionicActionSheet, localStorage, FooseyService)
	{
        // create a pull-to-refresh function
        $scope.refresh = refresh;

        // initialize the page
        $scope.refresh();
        $scope.loading = true;

        // refresh page function
        function refresh()
        {
            // load from local storage
            $scope.dates = localStorage.getObject('history');

		    // get 30 most recent games and group by the date
            FooseyService.history(0, 30)
            .then(function successCallback(result) 
            { 
                // get games
                $scope.games = result.data.games;

                // get dates from server
                $scope.dates = groupByDate($scope.games);

                // store them to local storage
                localStorage.setObject('history', $scope.dates);
                $scope.error = false;
                
                done();
            }, function errorCallback(response)
            {
                $scope.error = true;
                done();
            });
        }

        function groupByDate(games)
        {
            return _.chain(games)
                    .groupBy('date')
                    .pairs()
                    .map(function (currentItem)
                    {
                      return _.object(_.zip(['date', 'games'], currentItem));
                    })
                    .value();
        }

        // turns off spinner and notifies
        function done()
        {
            $scope.loading = false;
            $scope.$broadcast('scroll.refreshComplete');
        }

        $scope.show = function(game) 
        {
            // Show the action sheet
            $ionicActionSheet.show(
            {
                destructiveText: 'Remove Game',
                cancelText: 'Cancel',
                destructiveButtonClicked: function(index) 
                {
                    confirmRemove(game.id);
                    return true;
                }
            });
        };

        // confirm that they actually want to remove
        function confirmRemove(id)
        {
            var confirmPopup = $ionicPopup.confirm({
              title: 'Remove This Game',
              template: 'Are you sure you want to remove this game? This cannot be undone.'
            });

            // if yes, delete the last game
            confirmPopup.then(function(positive) {
              if(positive) {
                remove(id);
              }
            });
        }

        // Remove game
        function remove(id)
        {
            $scope.loading = true;
            FooseyService.remove(id)
            .then(function()
            {
                refresh();
            });
        }
	});<commit_msg>Comments and passing the game around, not just the id on remove<commit_after>angular.module('history', [])
	.controller('HistoryController', function($scope, $ionicPopup, $ionicActionSheet, localStorage, FooseyService)
	{
        // create a pull-to-refresh function
        $scope.refresh = refresh;

        // initialize the page
        $scope.refresh();
        $scope.loading = true;

        // refresh page function
        function refresh()
        {
            // load from local storage
            $scope.dates = localStorage.getObject('history');

		    // get 30 most recent games and group by the date
            FooseyService.history(0, 30)
            .then(function successCallback(result) 
            { 
                // get games
                $scope.games = result.data.games;

                // get dates from server
                $scope.dates = groupByDate($scope.games);

                // store them to local storage
                localStorage.setObject('history', $scope.dates);
                $scope.error = false;
                
                done();
            }, function errorCallback(response)
            {
                $scope.error = true;
                done();
            });
        }

        // group the games by date
        function groupByDate(games)
        {
            return _.chain(games)
                    .groupBy('date')
                    .pairs()
                    .map(function (currentItem)
                    {
                      return _.object(_.zip(['date', 'games'], currentItem));
                    })
                    .value();
        }

        // turns off spinner and notifies
        function done()
        {
            $scope.loading = false;
            $scope.$broadcast('scroll.refreshComplete');
        }

        // show the action sheet for deleting games
        $scope.show = function(game) 
        {
            // Show the action sheet
            $ionicActionSheet.show(
            {
                destructiveText: 'Remove Game',
                cancelText: 'Cancel',
                destructiveButtonClicked: function(index) 
                {
                    confirmRemove(game);
                    return true;
                }
            });
        };

        // confirm that they actually want to remove
        function confirmRemove(game)
        {
            var confirmPopup = $ionicPopup.confirm({
              title: 'Remove This Game',
              template: 'Are you sure you want to remove this game? This cannot be undone.'
            });

            // if yes, delete the last game
            confirmPopup.then(function(positive) {
              if(positive) {
                remove(game);
              }
            });
        }

        // Remove game
        function remove(game)
        {
            $scope.loading = true;
            FooseyService.remove(game.id)
            .then(function()
            {
                refresh();
            });
        }
	});
{'fraction_non_alphanumeric': 0.0978536420483353, 'fraction_numerical': 0.0016900456312320432, 'mean_word_length': 1.1645940014630578, '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': '3816354', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1338, 'n_words': 339}