{"size": 1424, "ext": "js", "max_stars_repo_path": "browser/js/github/github.js", "max_stars_repo_name": "ohhheyyyy/grasshopper", "max_stars_repo_stars_event_min_datetime": "2016-06-24T15:57:56.000Z", "max_stars_repo_stars_event_max_datetime": "2016-06-24T15:57:56.000Z", "max_issues_repo_path": "browser/js/github/github.js", "max_issues_repo_name": "ohhheyyyy/grasshopper", "max_issues_repo_issues_event_min_datetime": "2016-06-24T16:28:29.000Z", "max_issues_repo_issues_event_max_datetime": "2016-07-10T20:55:09.000Z", "max_forks_repo_path": "browser/js/github/github.js", "max_forks_repo_name": "ohhheyyyy/grasshopper", "max_forks_repo_forks_event_min_datetime": "2016-07-15T17:55:45.000Z", "max_forks_repo_forks_event_max_datetime": "2016-07-19T21:15:05.000Z"}
{"max_stars_count": 1, "max_issues_count": 52, "max_forks_count": 2, "avg_line_length": 31.6444444444, "max_line_length": 89, "alphanum_fraction": 0.5498595506}
app.config(function($stateProvider) {
    $stateProvider.state('github', {
        url: '/applications/:appID/github/',
        controller: 'GithubCtrl',
        templateUrl: '/js/github/github.html',
        resolve: {
            allRepos: function(GithubFactory, $stateParams) {
                return GithubFactory.getAllRepos($stateParams.appID);
            },
             appData: function(AppFactory, $stateParams){
                return AppFactory.fetchCurrentApp($stateParams.appID);
            },
        }
    });
});

app.factory('GithubFactory', function($http) {
    return {
        getAllRepos: function(appID) {
            return $http.get('/api/applications/' + appID + '/github')
                .then(function(response) {
                    return response.data;
                });
        },
        addRepoId: function(appID, repoIdObj){
            return $http.put('/api/applications/'  + appID,  repoIdObj)
                .then(function(response) {
                    return response.data;
                });
        }
    };
});

app.controller('GithubCtrl', function($scope, allRepos, GithubFactory, appData, $state) {
   $scope.allRepos = allRepos;
   $scope.addRepo =  function(repoIdObj) {
        var repoObj = {repoId: repoIdObj.name }
        GithubFactory.addRepoId(appData.id, repoObj)
        .then(function(response){
            $scope.repoStatus = true;
        })
   }
});

